1- /**
2- * Test BatchProcessor class
3- *
4- * @group unit/batch/class/batchprocessor
5- */
61import context from '@aws-lambda-powertools/testing-utils/context' ;
72import type { Context } from 'aws-lambda' ;
3+ import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
84import {
95 BatchProcessingError ,
106 BatchProcessor ,
@@ -31,8 +27,7 @@ describe('Class: AsyncBatchProcessor', () => {
3127 } ;
3228
3329 beforeEach ( ( ) => {
34- jest . clearAllMocks ( ) ;
35- jest . resetModules ( ) ;
30+ vi . clearAllMocks ( ) ;
3631 process . env = { ...ENVIRONMENT_VARIABLES } ;
3732 } ) ;
3833
@@ -41,7 +36,7 @@ describe('Class: AsyncBatchProcessor', () => {
4136 } ) ;
4237
4338 describe ( 'Asynchronously processing SQS Records' , ( ) => {
44- test ( 'Batch processing SQS records with no failures', async ( ) => {
39+ it ( 'completes processing with no failures', async ( ) => {
4540 // Prepare
4641 const firstRecord = sqsRecordFactory ( 'success' ) ;
4742 const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -59,7 +54,7 @@ describe('Class: AsyncBatchProcessor', () => {
5954 ] ) ;
6055 } ) ;
6156
62- test ( 'Batch processing SQS records with some failures', async ( ) => {
57+ it ( 'completes processing with with some failures', async ( ) => {
6358 // Prepare
6459 const firstRecord = sqsRecordFactory ( 'failure' ) ;
6560 const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -86,7 +81,7 @@ describe('Class: AsyncBatchProcessor', () => {
8681 } ) ;
8782 } ) ;
8883
89- test ( 'Batch processing SQS records with all failures', async ( ) => {
84+ it ( 'completes processing with all failures', async ( ) => {
9085 // Prepare
9186 const firstRecord = sqsRecordFactory ( 'failure' ) ;
9287 const secondRecord = sqsRecordFactory ( 'failure' ) ;
@@ -106,7 +101,7 @@ describe('Class: AsyncBatchProcessor', () => {
106101 } ) ;
107102
108103 describe ( 'Asynchronously processing Kinesis Records' , ( ) => {
109- test ( 'Batch processing Kinesis records with no failures', async ( ) => {
104+ it ( 'completes processing with no failures', async ( ) => {
110105 // Prepare
111106 const firstRecord = kinesisRecordFactory ( 'success' ) ;
112107 const secondRecord = kinesisRecordFactory ( 'success' ) ;
@@ -124,7 +119,7 @@ describe('Class: AsyncBatchProcessor', () => {
124119 ] ) ;
125120 } ) ;
126121
127- test ( 'Batch processing Kinesis records with some failures', async ( ) => {
122+ it ( 'completes processing with some failures', async ( ) => {
128123 // Prepare
129124 const firstRecord = kinesisRecordFactory ( 'failure' ) ;
130125 const secondRecord = kinesisRecordFactory ( 'success' ) ;
@@ -151,7 +146,7 @@ describe('Class: AsyncBatchProcessor', () => {
151146 } ) ;
152147 } ) ;
153148
154- test ( 'Batch processing Kinesis records with all failures', async ( ) => {
149+ it ( 'completes processing with all failures', async ( ) => {
155150 // Prepare
156151 const firstRecord = kinesisRecordFactory ( 'failure' ) ;
157152 const secondRecord = kinesisRecordFactory ( 'failure' ) ;
@@ -171,7 +166,7 @@ describe('Class: AsyncBatchProcessor', () => {
171166 } ) ;
172167
173168 describe ( 'Asynchronously processing DynamoDB Records' , ( ) => {
174- test ( 'Batch processing DynamoDB records with no failures', async ( ) => {
169+ it ( 'completes processing with no failures', async ( ) => {
175170 // Prepare
176171 const firstRecord = dynamodbRecordFactory ( 'success' ) ;
177172 const secondRecord = dynamodbRecordFactory ( 'success' ) ;
@@ -189,7 +184,7 @@ describe('Class: AsyncBatchProcessor', () => {
189184 ] ) ;
190185 } ) ;
191186
192- test ( 'Batch processing DynamoDB records with some failures', async ( ) => {
187+ it ( 'completes processing with some failures', async ( ) => {
193188 // Prepare
194189 const firstRecord = dynamodbRecordFactory ( 'failure' ) ;
195190 const secondRecord = dynamodbRecordFactory ( 'success' ) ;
@@ -216,7 +211,7 @@ describe('Class: AsyncBatchProcessor', () => {
216211 } ) ;
217212 } ) ;
218213
219- test ( 'Batch processing DynamoDB records with all failures', async ( ) => {
214+ it ( 'completes processing with all failures', async ( ) => {
220215 // Prepare
221216 const firstRecord = dynamodbRecordFactory ( 'failure' ) ;
222217 const secondRecord = dynamodbRecordFactory ( 'failure' ) ;
@@ -236,7 +231,7 @@ describe('Class: AsyncBatchProcessor', () => {
236231 } ) ;
237232
238233 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 ( ) => {
240235 // Prepare
241236 const firstRecord = sqsRecordFactory ( 'success' ) ;
242237 const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -254,25 +249,7 @@ describe('Class: AsyncBatchProcessor', () => {
254249 ] ) ;
255250 } ) ;
256251
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 ( ) => {
276253 // Prepare
277254 const firstRecord = sqsRecordFactory ( 'success' ) ;
278255 const secondRecord = sqsRecordFactory ( 'success' ) ;
@@ -289,7 +266,7 @@ describe('Class: AsyncBatchProcessor', () => {
289266 } ) ;
290267 } ) ;
291268
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 ', ( ) => {
293270 // Prepare
294271 const processor = new BatchProcessor ( EventType . SQS ) ;
295272
0 commit comments