@@ -359,4 +359,121 @@ describe('MultiWiggleAdapter.getSources', () => {
359359 expect ( sources1 ) . toEqual ( sources2 )
360360 } )
361361 } )
362+
363+ describe ( 'source uniqueness' , ( ) => {
364+ it ( 'should keep sources unique when all are different' , async ( ) => {
365+ adapter = new MultiWiggleAdapter ( configSchema . create ( { } ) )
366+
367+ adapter . getAdapters = jest . fn ( ) . mockResolvedValue ( [
368+ {
369+ source : 'source-1' ,
370+ type : 'BigWigAdapter' ,
371+ bigWigLocation : { uri : 'http://example.com/data/file1.bw' } ,
372+ dataAdapter : { } as any ,
373+ } ,
374+ {
375+ source : 'source-2' ,
376+ type : 'BigWigAdapter' ,
377+ bigWigLocation : { uri : 'http://example.com/data/file2.bw' } ,
378+ dataAdapter : { } as any ,
379+ } ,
380+ {
381+ source : 'source-3' ,
382+ type : 'BigWigAdapter' ,
383+ bigWigLocation : { uri : 'http://example.com/data/file3.bw' } ,
384+ dataAdapter : { } as any ,
385+ } ,
386+ ] )
387+
388+ const sources = await adapter . getSources ( [ ] )
389+
390+ expect ( sources ) . toHaveLength ( 3 )
391+ expect ( sources [ 0 ] ! . source ) . toBe ( 'source-1' )
392+ expect ( sources [ 1 ] ! . source ) . toBe ( 'source-2' )
393+ expect ( sources [ 2 ] ! . source ) . toBe ( 'source-3' )
394+
395+ // Verify all sources are unique
396+ const uniqueSourcesSet = new Set ( sources . map ( s => s . source ) )
397+ expect ( uniqueSourcesSet . size ) . toBe ( 3 )
398+ } )
399+
400+ it ( 'should make duplicate sources unique by appending counter' , async ( ) => {
401+ adapter = new MultiWiggleAdapter ( configSchema . create ( { } ) )
402+
403+ adapter . getAdapters = jest . fn ( ) . mockResolvedValue ( [
404+ {
405+ source : 'duplicate' ,
406+ type : 'BigWigAdapter' ,
407+ bigWigLocation : { uri : 'http://example.com/data/file1.bw' } ,
408+ dataAdapter : { } as any ,
409+ } ,
410+ {
411+ source : 'duplicate' ,
412+ type : 'BigWigAdapter' ,
413+ bigWigLocation : { uri : 'http://example.com/data/file2.bw' } ,
414+ dataAdapter : { } as any ,
415+ } ,
416+ {
417+ source : 'duplicate' ,
418+ type : 'BigWigAdapter' ,
419+ bigWigLocation : { uri : 'http://example.com/data/file3.bw' } ,
420+ dataAdapter : { } as any ,
421+ } ,
422+ ] )
423+
424+ const sources = await adapter . getSources ( [ ] )
425+
426+ expect ( sources ) . toHaveLength ( 3 )
427+ expect ( sources [ 0 ] ! . source ) . toBe ( 'duplicate' )
428+ expect ( sources [ 1 ] ! . source ) . toBe ( 'duplicate-1' )
429+ expect ( sources [ 2 ] ! . source ) . toBe ( 'duplicate-2' )
430+
431+ // Verify all sources are unique
432+ const uniqueSourcesSet = new Set ( sources . map ( s => s . source ) )
433+ expect ( uniqueSourcesSet . size ) . toBe ( 3 )
434+ } )
435+
436+ it ( 'should handle mixed duplicate and unique sources' , async ( ) => {
437+ adapter = new MultiWiggleAdapter ( configSchema . create ( { } ) )
438+
439+ adapter . getAdapters = jest . fn ( ) . mockResolvedValue ( [
440+ {
441+ source : 'unique1' ,
442+ type : 'BigWigAdapter' ,
443+ bigWigLocation : { uri : 'http://example.com/data/file1.bw' } ,
444+ dataAdapter : { } as any ,
445+ } ,
446+ {
447+ source : 'duplicate' ,
448+ type : 'BigWigAdapter' ,
449+ bigWigLocation : { uri : 'http://example.com/data/file2.bw' } ,
450+ dataAdapter : { } as any ,
451+ } ,
452+ {
453+ source : 'duplicate' ,
454+ type : 'BigWigAdapter' ,
455+ bigWigLocation : { uri : 'http://example.com/data/file3.bw' } ,
456+ dataAdapter : { } as any ,
457+ } ,
458+ {
459+ source : 'unique2' ,
460+ type : 'BigWigAdapter' ,
461+ bigWigLocation : { uri : 'http://example.com/data/file4.bw' } ,
462+ dataAdapter : { } as any ,
463+ } ,
464+ ] )
465+
466+ const sources = await adapter . getSources ( [ ] )
467+
468+ expect ( sources ) . toHaveLength ( 4 )
469+ expect ( sources [ 0 ] ! . source ) . toBe ( 'unique1' )
470+ expect ( sources [ 1 ] ! . source ) . toBe ( 'duplicate' )
471+ expect ( sources [ 2 ] ! . source ) . toBe ( 'duplicate-1' )
472+ expect ( sources [ 3 ] ! . source ) . toBe ( 'unique2' )
473+
474+ // Verify all sources are unique
475+ const uniqueSourcesSet = new Set ( sources . map ( s => s . source ) )
476+ expect ( uniqueSourcesSet . size ) . toBe ( 4 )
477+ } )
478+ } )
362479} )
0 commit comments