@@ -1470,4 +1470,81 @@ describe('yup', () => {
14701470 expect ( result . content ) . toContain ( 'ratio: yup.number().defined().nullable().default(0.5).optional()' ) ;
14711471 expect ( result . content ) . toContain ( 'isMember: yup.boolean().defined().nullable().default(true).optional()' ) ;
14721472 } ) ;
1473+
1474+ it ( 'with default input values as enum types with underscores' , async ( ) => {
1475+ const schema = buildSchema ( /* GraphQL */ `
1476+ enum PageType {
1477+ PUBLIC
1478+ BASIC_AUTH
1479+ }
1480+ input PageInput {
1481+ pageType: PageType! = BASIC_AUTH
1482+ greeting: String = "Hello"
1483+ score: Int = 100
1484+ ratio: Float = 0.5
1485+ isMember: Boolean = true
1486+ }
1487+ ` ) ;
1488+ const result = await plugin (
1489+ schema ,
1490+ [ ] ,
1491+ {
1492+ schema : 'yup' ,
1493+ importFrom : './types' ,
1494+ useEnumTypeAsDefaultValue : true ,
1495+ } ,
1496+ { } ,
1497+ ) ;
1498+
1499+ expect ( result . content ) . toContain (
1500+ 'export const PageTypeSchema = yup.string<PageType>().oneOf(Object.values(PageType)).defined()' ,
1501+ ) ;
1502+ expect ( result . content ) . toContain ( 'export function PageInputSchema(): yup.ObjectSchema<PageInput>' ) ;
1503+
1504+ expect ( result . content ) . toContain ( 'pageType: PageTypeSchema.nonNullable().default(PageType.Basic_Auth)' ) ;
1505+ expect ( result . content ) . toContain ( 'greeting: yup.string().defined().nullable().default("Hello").optional()' ) ;
1506+ expect ( result . content ) . toContain ( 'score: yup.number().defined().nullable().default(100).optional()' ) ;
1507+ expect ( result . content ) . toContain ( 'ratio: yup.number().defined().nullable().default(0.5).optional()' ) ;
1508+ expect ( result . content ) . toContain ( 'isMember: yup.boolean().defined().nullable().default(true).optional()' ) ;
1509+ } ) ;
1510+
1511+ it ( 'with default input values as enum types with no underscores' , async ( ) => {
1512+ const schema = buildSchema ( /* GraphQL */ `
1513+ enum PageType {
1514+ PUBLIC
1515+ BASIC_AUTH
1516+ }
1517+ input PageInput {
1518+ pageType: PageType! = BASIC_AUTH
1519+ greeting: String = "Hello"
1520+ score: Int = 100
1521+ ratio: Float = 0.5
1522+ isMember: Boolean = true
1523+ }
1524+ ` ) ;
1525+ const result = await plugin (
1526+ schema ,
1527+ [ ] ,
1528+ {
1529+ schema : 'yup' ,
1530+ importFrom : './types' ,
1531+ useEnumTypeAsDefaultValue : true ,
1532+ namingConvention : {
1533+ transformUnderscore : true ,
1534+ }
1535+ } ,
1536+ { } ,
1537+ ) ;
1538+
1539+ expect ( result . content ) . toContain (
1540+ 'export const PageTypeSchema = yup.string<PageType>().oneOf(Object.values(PageType)).defined()' ,
1541+ ) ;
1542+ expect ( result . content ) . toContain ( 'export function PageInputSchema(): yup.ObjectSchema<PageInput>' ) ;
1543+
1544+ expect ( result . content ) . toContain ( 'pageType: PageTypeSchema.nonNullable().default(PageType.BasicAuth)' ) ;
1545+ expect ( result . content ) . toContain ( 'greeting: yup.string().defined().nullable().default("Hello").optional()' ) ;
1546+ expect ( result . content ) . toContain ( 'score: yup.number().defined().nullable().default(100).optional()' ) ;
1547+ expect ( result . content ) . toContain ( 'ratio: yup.number().defined().nullable().default(0.5).optional()' ) ;
1548+ expect ( result . content ) . toContain ( 'isMember: yup.boolean().defined().nullable().default(true).optional()' ) ;
1549+ } ) ;
14731550} ) ;
0 commit comments