Skip to content

Commit bddcb82

Browse files
committed
Added test cases to cover all lines
1 parent 46d5b14 commit bddcb82

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

packages/parser/tests/unit/helpers.test.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { gzipSync } from 'node:zlib';
12
import {
23
KinesisDataStreamRecord,
34
KinesisDataStreamRecordPayload,
@@ -285,7 +286,7 @@ describe('Helper: DynamoDBMarshalled', () => {
285286
});
286287

287288
describe('Helper: Base64Encoded', () => {
288-
it('returns a valid base64 decoded payload', () => {
289+
it('returns a valid base64 decoded object when passed an encoded object', () => {
289290
// Prepare
290291
const data = {
291292
body: Buffer.from(JSON.stringify(structuredClone(basePayload))).toString(
@@ -304,7 +305,26 @@ describe('Helper: Base64Encoded', () => {
304305
});
305306
});
306307

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', () => {
308328
// Prepare
309329
const data = {
310330
body: Buffer.from(
@@ -321,6 +341,21 @@ describe('Helper: Base64Encoded', () => {
321341
expect(() => extendedSchema.parse(data)).toThrow();
322342
});
323343

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+
324359
it('throws an error if the base64 payload is malformed', () => {
325360
// Prepare
326361
const data = {

0 commit comments

Comments
 (0)