Skip to content

Commit 057685d

Browse files
committed
use TestSchema
1 parent 58ee5fb commit 057685d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ import { generateMock } from '@anatine/zod-mock';
1111
import { SqsSchema } from '../../src/schemas/sqs.js';
1212
import { z, ZodSchema } from 'zod';
1313
import { sqsEnvelope } from '../../src/envelopes/sqs';
14+
import { TestSchema } from './schema/utils';
1415

1516
describe('Middleware: parser', () => {
16-
const schema = z.object({
17-
name: z.string(),
18-
age: z.number().min(18).max(99),
19-
});
20-
type schema = z.infer<typeof schema>;
17+
type schema = z.infer<typeof TestSchema>;
2118
const handler = async (
2219
event: schema | unknown,
2320
_context: Context
@@ -27,11 +24,11 @@ describe('Middleware: parser', () => {
2724

2825
describe(' when envelope is provided ', () => {
2926
const middyfiedHandler = middy(handler).use(
30-
parser({ schema: schema, envelope: sqsEnvelope })
27+
parser({ schema: TestSchema, envelope: sqsEnvelope })
3128
);
3229

3330
it('should parse request body with schema and envelope', async () => {
34-
const bodyMock = generateMock(schema);
31+
const bodyMock = generateMock(TestSchema);
3532

3633
const event = generateMock(SqsSchema, {
3734
stringMap: {
@@ -97,13 +94,17 @@ describe('Middleware: parser', () => {
9794

9895
it('should parse custom event', async () => {
9996
const event = { name: 'John', age: 18 };
100-
const middyfiedHandler = middy(handler).use(parser({ schema }));
97+
const middyfiedHandler = middy(handler).use(
98+
parser({ schema: TestSchema })
99+
);
101100

102101
expect(await middyfiedHandler(event, {} as Context)).toEqual(event);
103102
});
104103

105104
it('should throw when the schema does not match', async () => {
106-
const middyfiedHandler = middy(handler).use(parser({ schema }));
105+
const middyfiedHandler = middy(handler).use(
106+
parser({ schema: TestSchema })
107+
);
107108

108109
await expect(middyfiedHandler(42, {} as Context)).rejects.toThrow();
109110
});

0 commit comments

Comments
 (0)