Skip to content

Commit bc3bd7b

Browse files
author
Martin Pirkl
authored
Merge pull request #215 from enter-at/feat/tests-for-successful-responses
Tests for successful HTTP responses
2 parents da4c03c + b32e1ea commit bc3bd7b

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,13 @@ See [LICENSE](LICENSE) for full details.
257257

258258
[![Steffen Leistner][sleistner_avatar]][sleistner_homepage]
259259

260+
[![Martin Pirkl][pirklmar_avatar]][pirklmar_homepage]
261+
260262

261263
[sleistner_homepage]: https://github.com/sleistner
262264
[sleistner_avatar]: https://res.cloudinary.com/enter-at/image/fetch/f_png,r_max,w_100,h_100,c_thumb/https://github.com/sleistner.png
265+
[pirklmar_homepage]: https://github.com/pirklmar
266+
[pirklmar_avatar]: https://res.cloudinary.com/enter-at/image/fetch/f_png,r_max,w_100,h_100,c_thumb/https://github.com/pirklmar.png
263267

264268

265269

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ include:
6565
contributors:
6666
- name: "Steffen Leistner"
6767
github: "sleistner"
68+
- name: "Martin Pirkl"
69+
github: "pirklmar"

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"Typescript"
3131
],
3232
"author": "Steffen Leistner",
33+
"contributors": [
34+
"Martin Pirkl <[email protected]>"
35+
],
3336
"license": "Apache-2.0",
3437
"bugs": {
3538
"url": "https://github.com/enter-at/node-aws-lambda-handlers/issues"

src/handler/APIGatewayProxyHandler.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ForbiddenError,
1010
BadRequestError,
1111
} from "../error";
12+
import { ok, created, noContent } from '../response'
1213
import * as ContextFactory from "../../test/fixtures/ContextFactory";
1314
import * as APIGatewayProxyEventFactory from "../../test/fixtures/APIGatewayProxyEventFactory";
1415

@@ -23,6 +24,33 @@ describe(APIGatewayProxyHandler.name, () => {
2324
event = APIGatewayProxyEventFactory.factory();
2425
});
2526

27+
it("handles HTTP 200 response correctly", async () => {
28+
const fn = handler.wrapper(() => {
29+
return ok({ result: "HTTP 200" })
30+
}) as Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
31+
32+
const result = await fn(event, context, () => {});
33+
expect(result).toMatchSnapshot();
34+
});
35+
36+
it("handles HTTP 201 response correctly", async () => {
37+
const fn = handler.wrapper(() => {
38+
return created({ result: "HTTP 201" })
39+
}) as Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
40+
41+
const result = await fn(event, context, () => {});
42+
expect(result).toMatchSnapshot();
43+
});
44+
45+
it("handles HTTP 204 response correctly", async () => {
46+
const fn = handler.wrapper(() => {
47+
return noContent()
48+
}) as Handler<APIGatewayProxyEvent, APIGatewayProxyResult>;
49+
50+
const result = await fn(event, context, () => {});
51+
expect(result).toMatchSnapshot();
52+
});
53+
2654
it("handles BadRequestError response correctly", async () => {
2755
const fn = handler.wrapper(() => {
2856
throw new BadRequestError("BadRequestError message");

src/handler/__snapshots__/APIGatewayProxyHandler.spec.ts.snap

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ Object {
3636
}
3737
`;
3838

39+
exports[`APIGatewayProxyHandler handles HTTP 200 response correctly 1`] = `
40+
Object {
41+
"body": "{\\"result\\":\\"HTTP 200\\"}",
42+
"headers": Object {
43+
"Access-Control-Allow-Credentials": true,
44+
"Access-Control-Allow-Origin": "*",
45+
"Content-Type": "application/json",
46+
},
47+
"statusCode": 200,
48+
}
49+
`;
50+
51+
exports[`APIGatewayProxyHandler handles HTTP 201 response correctly 1`] = `
52+
Object {
53+
"body": "{\\"result\\":\\"HTTP 201\\"}",
54+
"headers": Object {
55+
"Access-Control-Allow-Credentials": true,
56+
"Access-Control-Allow-Origin": "*",
57+
"Content-Type": "application/json",
58+
},
59+
"statusCode": 201,
60+
}
61+
`;
62+
63+
exports[`APIGatewayProxyHandler handles HTTP 204 response correctly 1`] = `
64+
Object {
65+
"headers": Object {
66+
"Access-Control-Allow-Credentials": true,
67+
"Access-Control-Allow-Origin": "*",
68+
"Content-Type": "application/json",
69+
},
70+
"statusCode": 204,
71+
}
72+
`;
73+
3974
exports[`APIGatewayProxyHandler handles InternalServerError response correctly 1`] = `
4075
Object {
4176
"body": "{\\"errors\\":[{\\"name\\":\\"InternalServerError\\",\\"details\\":\\"InternalServerError\\"}]}",

0 commit comments

Comments
 (0)