@@ -16,21 +16,21 @@ describe('Lambda invoker', () => {
16
16
StatusCode : 200 ,
17
17
Payload : Uint8ArrayBlobAdapter . fromString ( JSON . stringify ( {
18
18
statusCode : 404 ,
19
- body : {
19
+ body : JSON . stringify ( {
20
20
message : 'User not found' ,
21
- } ,
21
+ } ) ,
22
22
} ) )
23
23
} )
24
24
25
25
// then
26
26
const resp = await invokeLambda ( { payload : '' , functionName : 'test' } )
27
27
expect ( resp . statusCode ) . toEqual ( 404 )
28
- expect ( resp . body ) . toEqual ( {
28
+ expect ( resp . body ) . toEqual ( JSON . stringify ( {
29
29
message : 'User not found' ,
30
- } )
30
+ } ) )
31
31
} )
32
32
33
- it ( 'process 200 response with timeout error returned ' , async ( ) => {
33
+ it ( 'converts 200 responses with timeout to 504 Gateway Timeout error ' , async ( ) => {
34
34
// given
35
35
mockLambda . on ( InvokeCommand ) . resolves ( {
36
36
StatusCode : 200 ,
@@ -41,10 +41,18 @@ describe('Lambda invoker', () => {
41
41
} )
42
42
43
43
// then
44
- await expect ( invokeLambda ( { payload : '' , functionName : 'test' } ) ) . rejects . toThrow ( )
44
+ const resp = await invokeLambda ( { payload : '' , functionName : 'test' } )
45
+ expect ( resp . statusCode ) . toEqual ( 504 )
46
+ expect ( resp . body ) . toEqual (
47
+ JSON . stringify ( {
48
+ "message" : "Service timed out." ,
49
+ "functionName" : "test" , "error" : "Unhandled" ,
50
+ "payload" : JSON . stringify ( { "errorMessage" : "2023-01-09T10:48:53.262Z 873b04e4-991b-4d5f-b7ca-b99df84bfd66 Task timed out after 1.00 seconds" } )
51
+ } )
52
+ )
45
53
} )
46
54
47
- it ( 'process 200 response with non APIGatewayProxyStructuredResultV2 payload' , async ( ) => {
55
+ it ( 'converts 200 response with non APIGatewayProxyStructuredResultV2 payload to 502 Bad Gateway error ' , async ( ) => {
48
56
// given
49
57
mockLambda . on ( InvokeCommand ) . resolves ( {
50
58
StatusCode : 200 ,
@@ -54,6 +62,19 @@ describe('Lambda invoker', () => {
54
62
} )
55
63
56
64
// then
57
- await expect ( invokeLambda ( { payload : '' , functionName : 'test' } ) ) . rejects . toThrow ( )
65
+ const resp = await invokeLambda ( { payload : '' , functionName : 'test' } )
66
+ expect ( resp . statusCode ) . toEqual ( 502 )
67
+ expect ( resp . body ) . toEqual (
68
+ JSON . stringify ( {
69
+ "message" : "Service returned a wrongly formatted response." ,
70
+ "functionName" : "test" ,
71
+ "payload" : JSON . stringify ( {
72
+ username : 'this should fail'
73
+ } ) ,
74
+ "payloadJson" : {
75
+ username : 'this should fail'
76
+ }
77
+ } )
78
+ )
58
79
} )
59
80
} )
0 commit comments