@@ -145,5 +145,113 @@ public void GetDataCsvariantsAttribute_WhenEntryNull_ReturnsEmptyArrayString()
145145 Assert . True ( result [ "data-csvariants" ] != null ) ;
146146 Assert . Equal ( "[]" , result [ "data-csvariants" ] . ToString ( ) ) ;
147147 }
148+
149+ [ Fact ]
150+ public void GetVariantAliases_ThrowsWhenUidMissing ( )
151+ {
152+ var entry = new JObject { [ "title" ] = "no-uid" } ;
153+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetVariantAliases ( entry , "movie" ) ) ;
154+ }
155+
156+ [ Fact ]
157+ public void GetVariantAliases_ThrowsWhenUidNull ( )
158+ {
159+ var entry = new JObject { [ "uid" ] = JValue . CreateNull ( ) } ;
160+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetVariantAliases ( entry , "movie" ) ) ;
161+ }
162+
163+ [ Fact ]
164+ public void GetVariantAliases_Batch_ThrowsWhenContentTypeUidNull ( )
165+ {
166+ var entries = new JArray { new JObject { [ "uid" ] = "a" } } ;
167+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetVariantAliases ( entries , null ) ) ;
168+ }
169+
170+ [ Fact ]
171+ public void GetVariantAliases_Batch_ThrowsWhenContentTypeUidEmpty ( )
172+ {
173+ var entries = new JArray { new JObject { [ "uid" ] = "a" } } ;
174+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetVariantAliases ( entries , "" ) ) ;
175+ }
176+
177+ [ Fact ]
178+ public void GetDataCsvariantsAttribute_WhenEntriesArrayNull_ReturnsEmptyArrayString ( )
179+ {
180+ JObject result = Utils . GetDataCsvariantsAttribute ( ( JArray ) null , "movie" ) ;
181+ Assert . Equal ( "[]" , result [ "data-csvariants" ] . ToString ( ) ) ;
182+ }
183+
184+ [ Fact ]
185+ public void GetDataCsvariantsAttribute_Batch_ThrowsWhenContentTypeUidNull ( )
186+ {
187+ var entries = new JArray { new JObject { [ "uid" ] = "a" } } ;
188+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetDataCsvariantsAttribute ( entries , null ) ) ;
189+ }
190+
191+ [ Fact ]
192+ public void GetDataCsvariantsAttribute_Batch_ThrowsWhenContentTypeUidEmpty ( )
193+ {
194+ var entries = new JArray { new JObject { [ "uid" ] = "a" } } ;
195+ Assert . Throws < ArgumentException > ( ( ) => Utils . GetDataCsvariantsAttribute ( entries , "" ) ) ;
196+ }
197+
198+ [ Fact ]
199+ public void GetVariantAliases_ReturnsEmptyVariantsWhenPublishDetailsMissing ( )
200+ {
201+ var entry = new JObject { [ "uid" ] = "blt_no_pd" } ;
202+ JObject result = Utils . GetVariantAliases ( entry , "movie" ) ;
203+ Assert . Equal ( "blt_no_pd" , result [ "entry_uid" ] . ToString ( ) ) ;
204+ Assert . Equal ( "movie" , result [ "contenttype_uid" ] . ToString ( ) ) ;
205+ Assert . Empty ( ( JArray ) result [ "variants" ] ) ;
206+ }
207+
208+ [ Fact ]
209+ public void GetVariantAliases_ReturnsEmptyVariantsWhenVariantsObjectEmpty ( )
210+ {
211+ var entry = new JObject
212+ {
213+ [ "uid" ] = "blt_empty_v" ,
214+ [ "publish_details" ] = new JObject
215+ {
216+ [ "variants" ] = new JObject ( )
217+ }
218+ } ;
219+ JObject result = Utils . GetVariantAliases ( entry , "movie" ) ;
220+ Assert . Empty ( ( JArray ) result [ "variants" ] ) ;
221+ }
222+
223+ [ Fact ]
224+ public void GetVariantAliases_ReturnsEmptyVariantsWhenVariantsKeyMissing ( )
225+ {
226+ var entry = new JObject
227+ {
228+ [ "uid" ] = "blt_no_variants_key" ,
229+ [ "publish_details" ] = new JObject { [ "time" ] = "2025-01-01T00:00:00.000Z" }
230+ } ;
231+ JObject result = Utils . GetVariantAliases ( entry , "movie" ) ;
232+ Assert . Empty ( ( JArray ) result [ "variants" ] ) ;
233+ }
234+
235+ [ Fact ]
236+ public void GetVariantAliases_SkipsVariantWhenAliasMissingOrEmpty ( )
237+ {
238+ var entry = new JObject
239+ {
240+ [ "uid" ] = "blt_skip" ,
241+ [ "publish_details" ] = new JObject
242+ {
243+ [ "variants" ] = new JObject
244+ {
245+ [ "v1" ] = new JObject { [ "alias" ] = "keep_me" } ,
246+ [ "v2" ] = new JObject ( ) ,
247+ [ "v3" ] = new JObject { [ "alias" ] = "" }
248+ }
249+ }
250+ } ;
251+ JObject result = Utils . GetVariantAliases ( entry , "page" ) ;
252+ var variants = ( JArray ) result [ "variants" ] ;
253+ Assert . Single ( variants ) ;
254+ Assert . Equal ( "keep_me" , variants [ 0 ] . ToString ( ) ) ;
255+ }
148256 }
149257}
0 commit comments