@@ -7,8 +7,8 @@ const captureCorrelationIds = require('../index')
7
7
8
8
global . console . log = jest . fn ( )
9
9
10
- const invokeDynamoHandler = ( event , awsRequestId , sampleDebugLogRate , handlerF , recordF , done ) => {
11
- const handler = middy ( ( event , context , cb ) => {
10
+ const invokeDynamoHandler = async ( event , awsRequestId , sampleDebugLogRate , handlerF , recordF ) => {
11
+ const handler = middy ( async ( event , context ) => {
12
12
// check the correlation IDs outside the context of a record are correct
13
13
handlerF ( CorrelationIds . get ( ) )
14
14
@@ -18,18 +18,10 @@ const invokeDynamoHandler = (event, awsRequestId, sampleDebugLogRate, handlerF,
18
18
19
19
// check the correlation IDs outside the context of a record are correct
20
20
handlerF ( CorrelationIds . get ( ) )
21
-
22
- cb ( null )
23
21
} )
24
22
handler . use ( captureCorrelationIds ( { sampleDebugLogRate } ) )
25
23
26
- handler ( event , { awsRequestId } , ( err , result ) => {
27
- if ( err ) {
28
- throw err
29
- }
30
-
31
- if ( done ) done ( )
32
- } )
24
+ await handler ( event , { awsRequestId } )
33
25
}
34
26
35
27
const dynamo = require ( './event-templates/dynamo-new-old.json' )
@@ -59,9 +51,9 @@ const genDynamoEventWithoutNewImage = () => {
59
51
60
52
const dynamoTests = ( ) => {
61
53
describe ( 'when sampleDebugLogRate = 0' , ( ) => {
62
- it ( 'always sets debug-log-enabled to false' , ( ) => {
54
+ it ( 'always sets debug-log-enabled to false' , async ( ) => {
63
55
const requestId = uuid ( )
64
- invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
56
+ await invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
65
57
x => {
66
58
expect ( x [ 'awsRequestId' ] ) . toBe ( requestId )
67
59
expect ( x [ 'debug-log-enabled' ] ) . toBe ( 'false' )
@@ -75,9 +67,9 @@ const dynamoTests = () => {
75
67
} )
76
68
77
69
describe ( 'when event lacks NewImage' , ( ) => {
78
- it ( 'should set default correlation id' , ( ) => {
70
+ it ( 'should set default correlation id' , async ( ) => {
79
71
const requestId = uuid ( )
80
- invokeDynamoHandler ( genDynamoEventWithoutNewImage ( ) , requestId , 0 ,
72
+ await invokeDynamoHandler ( genDynamoEventWithoutNewImage ( ) , requestId , 0 ,
81
73
x => {
82
74
expect ( x [ 'awsRequestId' ] ) . toBe ( requestId )
83
75
expect ( x [ 'debug-log-enabled' ] ) . toBe ( 'false' )
@@ -92,9 +84,9 @@ const dynamoTests = () => {
92
84
} )
93
85
94
86
describe ( 'when sampleDebugLogRate = 1' , ( ) => {
95
- it ( 'always sets debug-log-enabled to true' , ( ) => {
87
+ it ( 'always sets debug-log-enabled to true' , async ( ) => {
96
88
const requestId = uuid ( )
97
- invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 1 ,
89
+ await invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 1 ,
98
90
x => {
99
91
expect ( x [ 'awsRequestId' ] ) . toBe ( requestId )
100
92
expect ( x [ 'debug-log-enabled' ] ) . toBe ( 'true' )
@@ -108,9 +100,9 @@ const dynamoTests = () => {
108
100
} )
109
101
110
102
describe ( 'when correlation ID is not provided in the event' , ( ) => {
111
- it ( 'sets it to the AWS Request ID' , ( ) => {
103
+ it ( 'sets it to the AWS Request ID' , async ( ) => {
112
104
const requestId = uuid ( )
113
- invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
105
+ await invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
114
106
x => {
115
107
// correlation IDs at the handler level
116
108
expect ( x [ 'x-correlation-id' ] ) . toBe ( requestId )
@@ -126,9 +118,9 @@ const dynamoTests = () => {
126
118
} )
127
119
128
120
describe ( 'when call-chain-length is not provided in the event' , ( ) => {
129
- it ( 'sets it to 1' , ( ) => {
121
+ it ( 'sets it to 1' , async ( ) => {
130
122
const requestId = uuid ( )
131
- invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
123
+ await invokeDynamoHandler ( genDynamoEvent ( ) , requestId , 0 ,
132
124
x => { } , // n/a
133
125
record => {
134
126
const x = record . correlationIds . get ( )
@@ -144,7 +136,7 @@ const dynamoTests = () => {
144
136
let userId
145
137
let requestId
146
138
147
- beforeEach ( ( done ) => {
139
+ beforeEach ( async ( ) => {
148
140
id = uuid ( )
149
141
userId = uuid ( )
150
142
@@ -157,11 +149,11 @@ const dynamoTests = () => {
157
149
158
150
const event = genDynamoEvent ( correlationIds )
159
151
requestId = uuid ( )
160
- invokeDynamoHandler ( event , requestId , 0 , x => {
152
+ await invokeDynamoHandler ( event , requestId , 0 , x => {
161
153
handlerCorrelationIds = x
162
154
} , aRecord => {
163
155
record = aRecord
164
- } , done )
156
+ } )
165
157
} )
166
158
167
159
it ( 'still has the correct handler correlation IDs' , ( ) => {
@@ -195,7 +187,7 @@ const dynamoTests = () => {
195
187
let record
196
188
let id
197
189
198
- beforeEach ( ( done ) => {
190
+ beforeEach ( async ( ) => {
199
191
id = uuid ( )
200
192
201
193
const correlationIds = {
@@ -204,10 +196,9 @@ const dynamoTests = () => {
204
196
}
205
197
206
198
const event = genDynamoEvent ( correlationIds )
207
- invokeDynamoHandler ( event , uuid ( ) , 0 ,
199
+ await invokeDynamoHandler ( event , uuid ( ) , 0 ,
208
200
( ) => { } ,
209
- aRecord => { record = aRecord } ,
210
- done )
201
+ aRecord => { record = aRecord } )
211
202
} )
212
203
213
204
it ( 'increments it by 1' , ( ) => {
0 commit comments