1
- /**
2
- * Test BatchProcessor class
3
- *
4
- * @group unit/batch/class/batchprocessor
5
- */
6
1
import context from '@aws-lambda-powertools/testing-utils/context' ;
7
2
import type { Context } from 'aws-lambda' ;
3
+ import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
8
4
import {
9
5
BatchProcessingError ,
10
6
BatchProcessor ,
@@ -31,8 +27,7 @@ describe('Class: AsyncBatchProcessor', () => {
31
27
} ;
32
28
33
29
beforeEach ( ( ) => {
34
- jest . clearAllMocks ( ) ;
35
- jest . resetModules ( ) ;
30
+ vi . clearAllMocks ( ) ;
36
31
process . env = { ...ENVIRONMENT_VARIABLES } ;
37
32
} ) ;
38
33
@@ -41,7 +36,7 @@ describe('Class: AsyncBatchProcessor', () => {
41
36
} ) ;
42
37
43
38
describe ( 'Asynchronously processing SQS Records' , ( ) => {
44
- test ( 'Batch processing SQS records with no failures', async ( ) => {
39
+ it ( 'completes processing with no failures', async ( ) => {
45
40
// Prepare
46
41
const firstRecord = sqsRecordFactory ( 'success' ) ;
47
42
const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -59,7 +54,7 @@ describe('Class: AsyncBatchProcessor', () => {
59
54
] ) ;
60
55
} ) ;
61
56
62
- test ( 'Batch processing SQS records with some failures', async ( ) => {
57
+ it ( 'completes processing with with some failures', async ( ) => {
63
58
// Prepare
64
59
const firstRecord = sqsRecordFactory ( 'failure' ) ;
65
60
const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -86,7 +81,7 @@ describe('Class: AsyncBatchProcessor', () => {
86
81
} ) ;
87
82
} ) ;
88
83
89
- test ( 'Batch processing SQS records with all failures', async ( ) => {
84
+ it ( 'completes processing with all failures', async ( ) => {
90
85
// Prepare
91
86
const firstRecord = sqsRecordFactory ( 'failure' ) ;
92
87
const secondRecord = sqsRecordFactory ( 'failure' ) ;
@@ -106,7 +101,7 @@ describe('Class: AsyncBatchProcessor', () => {
106
101
} ) ;
107
102
108
103
describe ( 'Asynchronously processing Kinesis Records' , ( ) => {
109
- test ( 'Batch processing Kinesis records with no failures', async ( ) => {
104
+ it ( 'completes processing with no failures', async ( ) => {
110
105
// Prepare
111
106
const firstRecord = kinesisRecordFactory ( 'success' ) ;
112
107
const secondRecord = kinesisRecordFactory ( 'success' ) ;
@@ -124,7 +119,7 @@ describe('Class: AsyncBatchProcessor', () => {
124
119
] ) ;
125
120
} ) ;
126
121
127
- test ( 'Batch processing Kinesis records with some failures', async ( ) => {
122
+ it ( 'completes processing with some failures', async ( ) => {
128
123
// Prepare
129
124
const firstRecord = kinesisRecordFactory ( 'failure' ) ;
130
125
const secondRecord = kinesisRecordFactory ( 'success' ) ;
@@ -151,7 +146,7 @@ describe('Class: AsyncBatchProcessor', () => {
151
146
} ) ;
152
147
} ) ;
153
148
154
- test ( 'Batch processing Kinesis records with all failures', async ( ) => {
149
+ it ( 'completes processing with all failures', async ( ) => {
155
150
// Prepare
156
151
const firstRecord = kinesisRecordFactory ( 'failure' ) ;
157
152
const secondRecord = kinesisRecordFactory ( 'failure' ) ;
@@ -171,7 +166,7 @@ describe('Class: AsyncBatchProcessor', () => {
171
166
} ) ;
172
167
173
168
describe ( 'Asynchronously processing DynamoDB Records' , ( ) => {
174
- test ( 'Batch processing DynamoDB records with no failures', async ( ) => {
169
+ it ( 'completes processing with no failures', async ( ) => {
175
170
// Prepare
176
171
const firstRecord = dynamodbRecordFactory ( 'success' ) ;
177
172
const secondRecord = dynamodbRecordFactory ( 'success' ) ;
@@ -189,7 +184,7 @@ describe('Class: AsyncBatchProcessor', () => {
189
184
] ) ;
190
185
} ) ;
191
186
192
- test ( 'Batch processing DynamoDB records with some failures', async ( ) => {
187
+ it ( 'completes processing with some failures', async ( ) => {
193
188
// Prepare
194
189
const firstRecord = dynamodbRecordFactory ( 'failure' ) ;
195
190
const secondRecord = dynamodbRecordFactory ( 'success' ) ;
@@ -216,7 +211,7 @@ describe('Class: AsyncBatchProcessor', () => {
216
211
} ) ;
217
212
} ) ;
218
213
219
- test ( 'Batch processing DynamoDB records with all failures', async ( ) => {
214
+ it ( 'completes processing with all failures', async ( ) => {
220
215
// Prepare
221
216
const firstRecord = dynamodbRecordFactory ( 'failure' ) ;
222
217
const secondRecord = dynamodbRecordFactory ( 'failure' ) ;
@@ -236,7 +231,7 @@ describe('Class: AsyncBatchProcessor', () => {
236
231
} ) ;
237
232
238
233
describe ( 'Batch processing with Lambda context' , ( ) => {
239
- test ( 'Batch processing when context is provided and handler accepts ', async ( ) => {
234
+ it ( 'passes the context to the record handler', async ( ) => {
240
235
// Prepare
241
236
const firstRecord = sqsRecordFactory ( 'success' ) ;
242
237
const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -254,25 +249,7 @@ describe('Class: AsyncBatchProcessor', () => {
254
249
] ) ;
255
250
} ) ;
256
251
257
- test ( 'Batch processing when context is provided and handler does not accept' , async ( ) => {
258
- // Prepare
259
- const firstRecord = sqsRecordFactory ( 'success' ) ;
260
- const secondRecord = sqsRecordFactory ( 'success' ) ;
261
- const records = [ firstRecord , secondRecord ] ;
262
- const processor = new BatchProcessor ( EventType . SQS ) ;
263
-
264
- // Act
265
- processor . register ( records , asyncSqsRecordHandler , options ) ;
266
- const processedMessages = await processor . process ( ) ;
267
-
268
- // Assess
269
- expect ( processedMessages ) . toStrictEqual ( [
270
- [ 'success' , firstRecord . body , firstRecord ] ,
271
- [ 'success' , secondRecord . body , secondRecord ] ,
272
- ] ) ;
273
- } ) ;
274
-
275
- test ( 'Batch processing when malformed context is provided and handler attempts to use' , async ( ) => {
252
+ it ( 'throws an error when passing an invalid context object' , async ( ) => {
276
253
// Prepare
277
254
const firstRecord = sqsRecordFactory ( 'success' ) ;
278
255
const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -289,7 +266,7 @@ describe('Class: AsyncBatchProcessor', () => {
289
266
} ) ;
290
267
} ) ;
291
268
292
- test ( 'When calling the sync process method, it should throw an error ', ( ) => {
269
+ it ( 'throws an error when the sync process method is called ', ( ) => {
293
270
// Prepare
294
271
const processor = new BatchProcessor ( EventType . SQS ) ;
295
272
0 commit comments