Skip to content

Commit 0ba6e90

Browse files
committed
CCM-11343: add unit tests to cover the Zod validator for inputSchema
1 parent c32ad32 commit 0ba6e90

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {
2+
$DynamoDBStreamRecord,
3+
$DynamoDBTemplate,
4+
$PublishableEventRecord,
5+
} from '../../domain/input-schemas';
6+
7+
describe('Input Schemas', () => {
8+
describe('$DynamoDBStreamRecord', () => {
9+
it('should validate minimal valid record', () => {
10+
const minimalRecord = {
11+
eventID: 'test-event-id',
12+
dynamodb: {},
13+
tableName: 'test-table',
14+
};
15+
16+
expect(() => $DynamoDBStreamRecord.parse(minimalRecord)).not.toThrow();
17+
});
18+
19+
it('should validate record with all AttributeValue types', () => {
20+
const recordWithAllTypes = {
21+
eventID: 'test-event-id',
22+
dynamodb: {
23+
NewImage: {
24+
stringField: { S: 'test-string' },
25+
numberField: { N: '123' },
26+
booleanField: { BOOL: true },
27+
nullField: { NULL: true },
28+
binaryField: { B: new Uint8Array([1, 2, 3]) },
29+
stringSetField: { SS: ['string1', 'string2'] },
30+
numberSetField: { NS: ['123', '456'] },
31+
binarySetField: {
32+
BS: [new Uint8Array([1, 2]), new Uint8Array([3, 4])],
33+
},
34+
listField: { L: [{ S: 'nested-string' }, { N: '789' }] },
35+
mapField: {
36+
M: {
37+
nestedString: { S: 'nested-value' },
38+
nestedNumber: { N: '999' },
39+
},
40+
},
41+
},
42+
SequenceNumber: '12345678901234567890',
43+
},
44+
tableName: 'test-table',
45+
};
46+
47+
expect(() =>
48+
$DynamoDBStreamRecord.parse(recordWithAllTypes)
49+
).not.toThrow();
50+
});
51+
});
52+
53+
describe('$DynamoDBTemplate', () => {
54+
it('should validate minimal template', () => {
55+
const minimalTemplate = {
56+
id: 'template-123',
57+
templateType: 'EMAIL',
58+
templateStatus: 'SUBMITTED',
59+
};
60+
61+
expect(() => $DynamoDBTemplate.parse(minimalTemplate)).not.toThrow();
62+
});
63+
64+
it('should validate template with optional fields', () => {
65+
const templateWithProofing = {
66+
id: 'template-456',
67+
templateType: 'EMAIL',
68+
templateStatus: 'SUBMITTED',
69+
proofingEnabled: true,
70+
};
71+
72+
expect(() => $DynamoDBTemplate.parse(templateWithProofing)).not.toThrow();
73+
});
74+
});
75+
76+
describe('$PublishableEventRecord', () => {
77+
it('should validate publishable event record', () => {
78+
const record = {
79+
eventID: 'publishable-event-id',
80+
dynamodb: {
81+
NewImage: {
82+
id: { S: 'template-id-123' },
83+
name: { S: 'Test Template' },
84+
},
85+
SequenceNumber: '1234567890',
86+
},
87+
tableName: 'templates-table',
88+
};
89+
90+
expect(() => $PublishableEventRecord.parse(record)).not.toThrow();
91+
});
92+
});
93+
});

0 commit comments

Comments
 (0)