Skip to content

Commit b32e1ea

Browse files
author
Martin Pirkl
committed
test(APIGatewayProxyHandler): add tests for HTTP 20x responses
1 parent 222ae64 commit b32e1ea

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

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)