Skip to content

Commit 7646572

Browse files
committed
added tests for variables
1 parent 6ae565e commit 7646572

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

tests/myzod.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,38 @@ describe('myzod', () => {
803803
expect(result.content).toContain(wantContain);
804804
}
805805
});
806+
807+
it('with object arguments', async () => {
808+
const schema = buildSchema(/* GraphQL */ `
809+
type MyType {
810+
foo(a: String, b: Int!, c: Boolean, d: Float!, e: Text): String
811+
}
812+
scalar Text
813+
`);
814+
const result = await plugin(
815+
schema,
816+
[],
817+
{
818+
schema: 'myzod',
819+
withObjectType: true,
820+
scalars: {
821+
Text: 'string',
822+
},
823+
},
824+
{}
825+
);
826+
const wantContain = dedent`
827+
export function MyTypeFooArgsSchema(): myzod.Type<MyTypeFooArgs> {
828+
return myzod.object({
829+
a: myzod.string().optional().nullable(),
830+
b: myzod.number(),
831+
c: myzod.boolean().optional().nullable(),
832+
d: myzod.number(),
833+
e: myzod.string().optional().nullable()
834+
})
835+
}`;
836+
expect(result.content).toContain(wantContain);
837+
});
806838
});
807839

808840
it('properly generates custom directive values', async () => {

tests/yup.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,38 @@ describe('yup', () => {
717717
expect(result.content).toContain(wantContain);
718718
}
719719
});
720+
721+
it('with object arguments', async () => {
722+
const schema = buildSchema(/* GraphQL */ `
723+
type MyType {
724+
foo(a: String, b: Int!, c: Boolean, d: Float!, e: Text): String
725+
}
726+
scalar Text
727+
`);
728+
const result = await plugin(
729+
schema,
730+
[],
731+
{
732+
schema: 'yup',
733+
withObjectType: true,
734+
scalars: {
735+
Text: 'string',
736+
},
737+
},
738+
{}
739+
);
740+
const wantContain = dedent`
741+
export function MyTypeFooArgsSchema(): yup.ObjectSchema<MyTypeFooArgs> {
742+
return yup.object({
743+
a: yup.string().defined().nullable(),
744+
b: yup.number().defined().nonNullable(),
745+
c: yup.boolean().defined().nullable(),
746+
d: yup.number().defined().nonNullable(),
747+
e: yup.string().defined().nullable()
748+
})
749+
}`;
750+
expect(result.content).toContain(wantContain);
751+
});
720752
});
721753

722754
it('properly generates custom directive values', async () => {

tests/zod.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,38 @@ describe('zod', () => {
871871
expect(result.content).toContain(wantContain);
872872
}
873873
});
874+
875+
it('with object arguments', async () => {
876+
const schema = buildSchema(/* GraphQL */ `
877+
type MyType {
878+
foo(a: String, b: Int!, c: Boolean, d: Float!, e: Text): String
879+
}
880+
scalar Text
881+
`);
882+
const result = await plugin(
883+
schema,
884+
[],
885+
{
886+
schema: 'zod',
887+
withObjectType: true,
888+
scalars: {
889+
Text: 'string',
890+
},
891+
},
892+
{}
893+
);
894+
const wantContain = dedent`
895+
export function MyTypeFooArgsSchema(): z.ZodObject<Properties<MyTypeFooArgs>> {
896+
return z.object({
897+
a: z.string().nullish(),
898+
b: z.number(),
899+
c: z.boolean().nullish(),
900+
d: z.number(),
901+
e: z.string().nullish()
902+
})
903+
}`;
904+
expect(result.content).toContain(wantContain);
905+
});
874906
});
875907

876908
it('properly generates custom directive values', async () => {

0 commit comments

Comments
 (0)