File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { z } from 'zod' ;
2
+ import { JSONStringified } from '../helpers.js' ;
2
3
import { EventBridgeSchema } from './eventbridge.js' ;
3
4
import { SqsRecordSchema } from './sqs.js' ;
4
5
@@ -170,12 +171,15 @@ const S3Schema = z.object({
170
171
} ) ;
171
172
172
173
const S3SqsEventNotificationRecordSchema = SqsRecordSchema . extend ( {
173
- body : z . string ( ) ,
174
+ body : JSONStringified ( S3Schema ) ,
174
175
} ) ;
175
176
176
177
/**
177
178
* Zod schema for S3 -> SQS -> Lambda event notification.
178
179
*
180
+ * Each SQS record’s body field is automatically parsed from a JSON string
181
+ * and then validated as an S3 event.
182
+ *
179
183
* @example
180
184
* ```json
181
185
* {
Original file line number Diff line number Diff line change @@ -196,11 +196,15 @@ describe('Schema: S3', () => {
196
196
filename : 'sqs-event' ,
197
197
} ) ;
198
198
199
+ const expected = structuredClone ( event ) ;
200
+ // @ts -expect-error - Modifying the expected result to account for transform
201
+ expected . Records [ 0 ] . body = JSON . parse ( expected . Records [ 0 ] . body ) ;
202
+
199
203
// Prepare
200
204
const result = S3SqsEventNotificationSchema . parse ( event ) ;
201
205
202
206
// Assess
203
- expect ( result ) . toStrictEqual ( event ) ;
207
+ expect ( result ) . toStrictEqual ( expected ) ;
204
208
} ) ;
205
209
206
210
it ( 'throws if the S3 event notification SQS event is not valid' , ( ) => {
You can’t perform that action at this time.
0 commit comments