1
+ import { gzipSync } from 'node:zlib' ;
1
2
import {
2
3
KinesisDataStreamRecord ,
3
4
KinesisDataStreamRecordPayload ,
@@ -285,7 +286,7 @@ describe('Helper: DynamoDBMarshalled', () => {
285
286
} ) ;
286
287
287
288
describe ( 'Helper: Base64Encoded' , ( ) => {
288
- it ( 'returns a valid base64 decoded payload ' , ( ) => {
289
+ it ( 'returns a valid base64 decoded object when passed an encoded object ' , ( ) => {
289
290
// Prepare
290
291
const data = {
291
292
body : Buffer . from ( JSON . stringify ( structuredClone ( basePayload ) ) ) . toString (
@@ -304,7 +305,26 @@ describe('Helper: Base64Encoded', () => {
304
305
} ) ;
305
306
} ) ;
306
307
307
- it ( 'throws an error if the payload is invalid' , ( ) => {
308
+ it ( 'returns a valid base64 decoded object when passed a compressed object' , ( ) => {
309
+ // Prepare
310
+ const data = {
311
+ body : Buffer . from (
312
+ gzipSync ( JSON . stringify ( structuredClone ( basePayload ) ) )
313
+ ) . toString ( 'base64' ) ,
314
+ } ;
315
+
316
+ // Act
317
+ const extendedSchema = envelopeSchema . extend ( {
318
+ body : Base64Encoded ( bodySchema ) ,
319
+ } ) ;
320
+
321
+ // Assess
322
+ expect ( extendedSchema . parse ( data ) ) . toStrictEqual ( {
323
+ body : basePayload ,
324
+ } ) ;
325
+ } ) ;
326
+
327
+ it ( 'throws an error if the payload is does not match the schema' , ( ) => {
308
328
// Prepare
309
329
const data = {
310
330
body : Buffer . from (
@@ -321,6 +341,21 @@ describe('Helper: Base64Encoded', () => {
321
341
expect ( ( ) => extendedSchema . parse ( data ) ) . toThrow ( ) ;
322
342
} ) ;
323
343
344
+ it ( 'throws an error if the payload is malformed' , ( ) => {
345
+ // Prepare
346
+ const data = {
347
+ body : Buffer . from ( '{"foo": 1, }' ) . toString ( 'base64' ) ,
348
+ } ;
349
+
350
+ // Act
351
+ const extendedSchema = envelopeSchema . extend ( {
352
+ body : Base64Encoded ( bodySchema ) ,
353
+ } ) ;
354
+
355
+ // Assess
356
+ expect ( ( ) => extendedSchema . parse ( data ) ) . toThrow ( ) ;
357
+ } ) ;
358
+
324
359
it ( 'throws an error if the base64 payload is malformed' , ( ) => {
325
360
// Prepare
326
361
const data = {
0 commit comments