Skip to content

Commit dcb20dc

Browse files
committed
fixed tests for refactoring
1 parent eee96cf commit dcb20dc

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
@@ -1,4 +1,5 @@
11
import { buildSchema } from 'graphql';
2+
import dedent from 'ts-dedent';
23

34
import { plugin } from '../src/index';
45

@@ -297,6 +298,37 @@ describe('myzod', () => {
297298
}
298299
});
299300

301+
it('with notAllowEmptyString issue #386', async () => {
302+
const schema = buildSchema(/* GraphQL */ `
303+
input InputOne {
304+
field: InputNested!
305+
}
306+
307+
input InputNested {
308+
field: String!
309+
}
310+
`);
311+
const result = await plugin(
312+
schema,
313+
[],
314+
{
315+
schema: 'myzod',
316+
notAllowEmptyString: true,
317+
scalars: {
318+
ID: 'string',
319+
},
320+
},
321+
{}
322+
);
323+
const wantContain = dedent`
324+
export function InputNestedSchema(): myzod.Type<InputNested> {
325+
return myzod.object({
326+
field: myzod.string().min(1)
327+
})
328+
}`;
329+
expect(result.content).toContain(wantContain);
330+
});
331+
300332
it('with scalarSchemas', async () => {
301333
const schema = buildSchema(/* GraphQL */ `
302334
input ScalarsInput {

tests/yup.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { buildSchema } from 'graphql';
2+
import dedent from 'ts-dedent';
23

34
import { plugin } from '../src/index';
45

@@ -294,6 +295,37 @@ describe('yup', () => {
294295
}
295296
});
296297

298+
it('with notAllowEmptyString issue #386', async () => {
299+
const schema = buildSchema(/* GraphQL */ `
300+
input InputOne {
301+
field: InputNested!
302+
}
303+
304+
input InputNested {
305+
field: String!
306+
}
307+
`);
308+
const result = await plugin(
309+
schema,
310+
[],
311+
{
312+
schema: 'yup',
313+
notAllowEmptyString: true,
314+
scalars: {
315+
ID: 'string',
316+
},
317+
},
318+
{}
319+
);
320+
const wantContain = dedent`
321+
export function InputNestedSchema(): yup.ObjectSchema<InputNested> {
322+
return yup.object({
323+
field: yup.string().defined().required()
324+
})
325+
}`;
326+
expect(result.content).toContain(wantContain);
327+
});
328+
297329
it('with scalarSchemas', async () => {
298330
const schema = buildSchema(/* GraphQL */ `
299331
input ScalarsInput {

tests/zod.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { buildSchema } from 'graphql';
2+
import { dedent } from 'ts-dedent';
23

34
import { plugin } from '../src/index';
45

@@ -297,6 +298,37 @@ describe('zod', () => {
297298
}
298299
});
299300

301+
it('with notAllowEmptyString issue #386', async () => {
302+
const schema = buildSchema(/* GraphQL */ `
303+
input InputOne {
304+
field: InputNested!
305+
}
306+
307+
input InputNested {
308+
field: String!
309+
}
310+
`);
311+
const result = await plugin(
312+
schema,
313+
[],
314+
{
315+
schema: 'zod',
316+
notAllowEmptyString: true,
317+
scalars: {
318+
ID: 'string',
319+
},
320+
},
321+
{}
322+
);
323+
const wantContain = dedent`
324+
export function InputNestedSchema(): z.ZodObject<Properties<InputNested>> {
325+
return z.object({
326+
field: z.string().min(1)
327+
})
328+
}`;
329+
expect(result.content).toContain(wantContain);
330+
});
331+
300332
it('with scalarSchemas', async () => {
301333
const schema = buildSchema(/* GraphQL */ `
302334
input ScalarsInput {

0 commit comments

Comments
 (0)