@@ -65,11 +65,39 @@ describe('getVariantAliases', () => {
6565 expect ( sortAliases ( result . variants ) ) . toEqual ( sortAliases ( [ 'keep_me' , 'also_keep' ] ) ) ;
6666 } ) ;
6767
68+ it ( 'skips variant entries that are null, non-objects, or arrays' , ( ) => {
69+ const variants : Record < string , unknown > = {
70+ skip_null : null ,
71+ skip_string : 'not-an-object' ,
72+ skip_array : [ 1 , 2 ] ,
73+ keep : { alias : 'only_valid' } ,
74+ } ;
75+ const entry = {
76+ uid : 'u1' ,
77+ publish_details : {
78+ variants,
79+ } ,
80+ } ;
81+ const result = getVariantAliases ( entry ) ;
82+ expect ( result . variants ) . toEqual ( [ 'only_valid' ] ) ;
83+ } ) ;
84+
6885 it ( 'throws when entry is null or undefined' , ( ) => {
6986 expect ( ( ) => getVariantAliases ( null as unknown as Record < string , unknown > ) ) . toThrow ( ) ;
7087 expect ( ( ) => getVariantAliases ( undefined as unknown as Record < string , unknown > ) ) . toThrow ( ) ;
7188 } ) ;
7289
90+ it ( 'throws TypeError when single entry is a non-object (e.g. primitive)' , ( ) => {
91+ expect ( ( ) => getVariantAliases ( 42 as unknown as Record < string , unknown > ) ) . toThrow ( TypeError ) ;
92+ expect ( ( ) => getVariantAliases ( 'entry' as unknown as Record < string , unknown > ) ) . toThrow ( TypeError ) ;
93+ } ) ;
94+
95+ it ( 'throws TypeError when an array item is not a plain object' , ( ) => {
96+ expect ( ( ) =>
97+ getVariantAliases ( [ variantEntrySingle , [ ] as unknown as Record < string , unknown > ] )
98+ ) . toThrow ( TypeError ) ;
99+ } ) ;
100+
73101 it ( 'throws when entry uid is missing or empty' , ( ) => {
74102 expect ( ( ) => getVariantAliases ( { } ) ) . toThrow ( / u i d / i) ;
75103 expect ( ( ) => getVariantAliases ( { uid : '' } ) ) . toThrow ( / u i d / i) ;
0 commit comments