@@ -314,52 +314,106 @@ describe('yup', () => {
314314 expect ( result . content ) . toContain ( 'export function SayISchema(): yup.SchemaOf<SayI> {' ) ;
315315 } ) ;
316316 describe ( 'with withObjectType' , ( ) => {
317- const schema = buildSchema ( /* GraphQL */ `
318- input ScalarsInput {
319- date: Date!
320- email: Email
321- }
322- scalar Date
323- scalar Email
324- input UserCreateInput {
325- name: String!
326- email: Email!
327- }
328- type User {
329- id: ID!
330- name: String
331- age: Int
332- email: Email
333- isMember: Boolean
334- createdAt: Date!
335- }
336-
337- type Mutation {
338- _empty: String
339- }
317+ it ( 'not generate if withObjectType false' , async ( ) => {
318+ const schema = buildSchema ( /* GraphQL */ `
319+ type User {
320+ id: ID!
321+ name: String
322+ }
323+ ` ) ;
324+ const result = await plugin (
325+ schema ,
326+ [ ] ,
327+ {
328+ schema : 'yup' ,
329+ } ,
330+ { }
331+ ) ;
332+ expect ( result . content ) . not . toContain ( 'export function UserSchema(): yup.SchemaOf<User> {' ) ;
333+ } ) ;
340334
341- type Query {
342- _empty: String
343- }
335+ it ( 'generate object type contains object type' , async ( ) => {
336+ const schema = buildSchema ( /* GraphQL */ `
337+ type Book {
338+ author: Author
339+ title: String
340+ }
344341
345- type Subscription {
346- _empty: String
347- }
348- ` ) ;
342+ type Book2 {
343+ author: Author!
344+ title: String!
345+ }
349346
350- it ( 'not generate if withObjectType false' , async ( ) => {
347+ type Author {
348+ books: [Book]
349+ name: String
350+ }
351+ ` ) ;
351352 const result = await plugin (
352353 schema ,
353354 [ ] ,
354355 {
355356 schema : 'yup' ,
357+ withObjectType : true ,
356358 } ,
357359 { }
358360 ) ;
359- expect ( result . content ) . not . toContain ( 'export function UserSchema(): yup.SchemaOf<User> {' ) ;
361+ const wantContains = [
362+ 'export function AuthorSchema(): yup.SchemaOf<Author> {' ,
363+ "__typename: yup.mixed().oneOf(['Author', undefined])," ,
364+ 'books: yup.array().of(BookSchema().optional()).optional(),' ,
365+ 'name: yup.string()' ,
366+
367+ 'export function BookSchema(): yup.SchemaOf<Book> {' ,
368+ "__typename: yup.mixed().oneOf(['Book', undefined])," ,
369+ 'author: AuthorSchema().optional(),' ,
370+ 'title: yup.string()' ,
371+
372+ 'export function Book2Schema(): yup.SchemaOf<Book2> {' ,
373+ "__typename: yup.mixed().oneOf(['Book2', undefined])," ,
374+ 'author: AuthorSchema().optional().defined(),' ,
375+ 'title: yup.string().defined()' ,
376+ ] ;
377+ for ( const wantContain of wantContains ) {
378+ expect ( result . content ) . toContain ( wantContain ) ;
379+ }
380+
381+ for ( const wantNotContain of [ 'Query' , 'Mutation' , 'Subscription' ] ) {
382+ expect ( result . content ) . not . toContain ( wantNotContain ) ;
383+ }
360384 } ) ;
361385
362386 it ( 'generate both input & type if withObjectType true' , async ( ) => {
387+ const schema = buildSchema ( /* GraphQL */ `
388+ scalar Date
389+ scalar Email
390+ input UserCreateInput {
391+ name: String!
392+ date: Date!
393+ email: Email!
394+ }
395+ type User {
396+ id: ID!
397+ name: String
398+ age: Int
399+ email: Email
400+ isMember: Boolean
401+ createdAt: Date!
402+ }
403+
404+ type Mutation {
405+ _empty: String
406+ }
407+
408+ type Query {
409+ _empty: String
410+ }
411+
412+ type Subscription {
413+ _empty: String
414+ }
415+ ` ) ;
416+
363417 const result = await plugin (
364418 schema ,
365419 [ ] ,
@@ -374,14 +428,10 @@ describe('yup', () => {
374428 { }
375429 ) ;
376430 const wantContains = [
377- // ScalarsInput
378- 'export function ScalarsInputSchema(): yup.SchemaOf<ScalarsInput> {' ,
379- 'return yup.object({' ,
380- 'date: yup.date().defined(),' ,
381- 'email: yup.string().email()' ,
382431 // User Create Input
383432 'export function UserCreateInputSchema(): yup.SchemaOf<UserCreateInput> {' ,
384433 'name: yup.string().defined(),' ,
434+ 'date: yup.date().defined(),' ,
385435 'email: yup.string().email().defined()' ,
386436 // User
387437 'export function UserSchema(): yup.SchemaOf<User> {' ,
0 commit comments