Skip to content

Commit 8964c66

Browse files
author
Sebastian Sauerer
committed
adapt tests
1 parent 9e25b19 commit 8964c66

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/lambda-invoker.test.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,55 @@ import { mockClient } from 'aws-sdk-client-mock'
55
const mockLambdaClient = mockClient(Lambda)
66

77
describe('Lambda invoker', () => {
8-
98
it('process 200 response with http error returned', async () => {
109
// given
10+
const payload = {
11+
statusCode: 404,
12+
body: {
13+
message: 'User not found',
14+
},
15+
}
16+
1117
mockLambdaClient.on(InvokeCommand).resolves({
1218
StatusCode: 200,
13-
Payload: JSON.stringify({
14-
statusCode: 404,
15-
body: JSON.stringify({
16-
message: 'User not found',
17-
}),
18-
}) as any
19+
Payload: Buffer.from(JSON.stringify(payload)) as any
1920
})
2021

2122
// then
2223
const resp = await invokeLambda({ payload: '', functionName: 'test' })
2324
expect(resp.statusCode).toEqual(404)
24-
expect(resp.body).toEqual(JSON.stringify({
25+
expect(resp.body).toEqual({
2526
message: 'User not found',
26-
}))
27+
})
2728
})
2829

2930
it('process 200 response with timeout error returned', async () => {
3031
// given
32+
const payload = {
33+
errorMessage: "2023-01-09T10:48:53.262Z 873b04e4-991b-4d5f-b7ca-b99df84bfd66 Task timed out after 1.00 seconds"
34+
}
3135
mockLambdaClient.on(InvokeCommand).resolves({
3236
StatusCode: 200,
3337
FunctionError: 'Unhandled',
34-
Payload: JSON.stringify({
35-
errorMessage: "2023-01-09T10:48:53.262Z 873b04e4-991b-4d5f-b7ca-b99df84bfd66 Task timed out after 1.00 seconds"
36-
}) as any
38+
Payload: Buffer.from(JSON.stringify(payload)) as any
3739
})
40+
3841

3942
// then
4043
await expect(invokeLambda({ payload: '', functionName: 'test' })).rejects.toThrow()
4144
})
4245

4346
it('process 200 response with non APIGatewayProxyStructuredResultV2 payload', async () => {
4447
// given
48+
const payload = {
49+
username: 'this should fail'
50+
}
4551
mockLambdaClient.on(InvokeCommand).resolves({
4652
StatusCode: 200,
47-
Payload: JSON.stringify({
48-
username: 'this should fail'
49-
}) as any
53+
Payload: Buffer.from(JSON.stringify(payload)) as any
5054
})
5155

5256
// then
5357
await expect(invokeLambda({ payload: '', functionName: 'test' })).rejects.toThrow()
5458
})
55-
5659
})

0 commit comments

Comments
 (0)