@@ -68,13 +68,27 @@ describe('TranslationDataSchema — reports', () => {
6868 it ( 'refuses a bare string per report — the value is an object of `label` / `description`' , ( ) => {
6969 const result = TranslationDataSchema . safeParse ( { reports : { opps_by_stage : '各阶段商机' } } ) ;
7070 expect ( result . success ) . toBe ( false ) ;
71+ expect ( result . error ! . issues [ 0 ] ) . toMatchObject ( { code : 'invalid_type' , path : [ 'reports' , 'opps_by_stage' ] } ) ;
7172 } ) ;
7273
7374 it ( 'renames the singular spelling onto the group, and `name` / `title` onto `label`' , ( ) => {
74- expect ( ( ) => TranslationDataSchema . parse ( { report : { r : { label : 'x' } } } ) ) . toThrow ( / r e p o r t s / ) ;
75- expect ( ( ) => TranslationItemSchema . parse ( { locale : 'en' , report : { r : { label : 'x' } } } ) ) . toThrow ( / r e p o r t s / ) ;
76- expect ( ( ) => TranslationDataSchema . parse ( { reports : { r : { title : 'x' } } } ) ) . toThrow ( / l a b e l / ) ;
77- expect ( ( ) => TranslationDataSchema . parse ( { reports : { r : { name : 'x' } } } ) ) . toThrow ( / l a b e l / ) ;
75+ const issueOf = ( result : { success : boolean ; error ?: { issues : any [ ] } } ) => {
76+ expect ( result . success ) . toBe ( false ) ;
77+ return result . error ! . issues [ 0 ] ;
78+ } ;
79+ for ( const result of [
80+ TranslationDataSchema . safeParse ( { report : { r : { label : 'x' } } } ) ,
81+ TranslationItemSchema . safeParse ( { locale : 'en' , report : { r : { label : 'x' } } } ) ,
82+ ] ) {
83+ const issue = issueOf ( result ) ;
84+ expect ( issue ) . toMatchObject ( { code : 'unrecognized_keys' , keys : [ 'report' ] , path : [ ] } ) ;
85+ expect ( issue . message ) . toContain ( '`report` → `reports`' ) ;
86+ }
87+ for ( const key of [ 'title' , 'name' ] ) {
88+ const issue = issueOf ( TranslationDataSchema . safeParse ( { reports : { r : { [ key ] : 'x' } } } ) ) ;
89+ expect ( issue ) . toMatchObject ( { code : 'unrecognized_keys' , keys : [ key ] , path : [ 'reports' , 'r' ] } ) ;
90+ expect ( issue . message ) . toContain ( `\`${ key } \` → \`label\`` ) ;
91+ }
7892 } ) ;
7993} ) ;
8094
0 commit comments