File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 11import { z } from 'zod' ;
2+ import { JSONStringified } from '../helpers.js' ;
23import { EventBridgeSchema } from './eventbridge.js' ;
34import { SqsRecordSchema } from './sqs.js' ;
45
@@ -170,12 +171,15 @@ const S3Schema = z.object({
170171} ) ;
171172
172173const S3SqsEventNotificationRecordSchema = SqsRecordSchema . extend ( {
173- body : z . string ( ) ,
174+ body : JSONStringified ( S3Schema ) ,
174175} ) ;
175176
176177/**
177178 * Zod schema for S3 -> SQS -> Lambda event notification.
178179 *
180+ * Each SQS record’s body field is automatically parsed from a JSON string
181+ * and then validated as an S3 event.
182+ *
179183 * @example
180184 * ```json
181185 * {
Original file line number Diff line number Diff line change @@ -196,11 +196,15 @@ describe('Schema: S3', () => {
196196 filename : 'sqs-event' ,
197197 } ) ;
198198
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+
199203 // Prepare
200204 const result = S3SqsEventNotificationSchema . parse ( event ) ;
201205
202206 // Assess
203- expect ( result ) . toStrictEqual ( event ) ;
207+ expect ( result ) . toStrictEqual ( expected ) ;
204208 } ) ;
205209
206210 it ( 'throws if the S3 event notification SQS event is not valid' , ( ) => {
You can’t perform that action at this time.
0 commit comments