Skip to content

Commit 0568d3a

Browse files
committed
update tests
1 parent fc017f9 commit 0568d3a

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

packages/orm/src/client/contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type { ExtClientMembersBase, ExtQueryArgsBase, RuntimePlugin } from './pl
4444
import type { ZenStackPromise } from './promise';
4545
import type { ToKysely } from './query-builder';
4646
import type { GetSlicedModels, GetSlicedOperations, GetSlicedProcedures } from './type-utils';
47-
import type { ZodSchemaFactory } from './zod/zod-schema-factory';
47+
import type { ZodSchemaFactory } from './zod/factory';
4848

4949
type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[number];
5050

packages/orm/src/client/crud/validator/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../../crud-types';
2323
import { createInvalidInputError } from '../../errors';
2424
import type { ClientOptions } from '../../options';
25-
import { ZodSchemaFactory } from '../../zod/zod-schema-factory';
25+
import { ZodSchemaFactory } from '../../zod/factory';
2626

2727
type GetSchemaFunc<Schema extends SchemaDef> = (model: GetModels<Schema>) => ZodType;
2828

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { createQuerySchemaFactory } from './zod-schema-factory';
1+
export { createQuerySchemaFactory } from './factory';

tests/e2e/orm/client-api/zod.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,4 +1411,41 @@ describe('Zod schema factory test', () => {
14111411
});
14121412

14131413
// #endregion
1414+
1415+
// #region makeProcedureParamSchema
1416+
1417+
describe('makeProcedureParamSchema', () => {
1418+
it('works with scalar types', () => {
1419+
const s = client.$zod.makeProcedureParamSchema({ type: 'String' });
1420+
expect(s.safeParse('hello').success).toBe(true);
1421+
expect(s.safeParse(42).success).toBe(false);
1422+
});
1423+
1424+
it('works with array types', () => {
1425+
const s = client.$zod.makeProcedureParamSchema({ type: 'String', array: true });
1426+
expect(s.safeParse(['a', 'b', 'c']).success).toBe(true);
1427+
expect(s.safeParse('a').success).toBe(false);
1428+
expect(s.safeParse([1, 2, 3]).success).toBe(false);
1429+
});
1430+
1431+
it('works with optional types', () => {
1432+
const s = client.$zod.makeProcedureParamSchema({ type: 'String', optional: true });
1433+
expect(s.safeParse('hello').success).toBe(true);
1434+
expect(s.safeParse(undefined).success).toBe(true);
1435+
expect(s.safeParse(42).success).toBe(false);
1436+
});
1437+
1438+
it('works with array and optional types combined', () => {
1439+
const s = client.$zod.makeProcedureParamSchema({ type: 'Int', array: true, optional: true });
1440+
expect(s.safeParse([1, 2, 3]).success).toBe(true);
1441+
expect(s.safeParse(undefined).success).toBe(true);
1442+
expect(s.safeParse(1).success).toBe(false);
1443+
});
1444+
1445+
it('throws for unsupported type', () => {
1446+
expect(() => client.$zod.makeProcedureParamSchema({ type: 'NotAType' })).toThrow();
1447+
});
1448+
});
1449+
1450+
// #endregion
14141451
});

0 commit comments

Comments
 (0)