@@ -14,6 +14,7 @@ import {
1414import { TranslateModule } from '@ngx-translate/core' ;
1515import { of } from 'rxjs' ;
1616
17+ import { APP_CONFIG } from '../../../config/app-config.interface' ;
1718import { getBitstreamDownloadRoute } from '../../app-routing-paths' ;
1819import {
1920 SortDirection ,
@@ -131,6 +132,7 @@ describe('LuckySearchComponent', () => {
131132 { provide : HardRedirectService , useValue : hardRedirectService } ,
132133 { provide : PLATFORM_ID , useValue : 'browser' } ,
133134 { provide : NotificationsService , useValue : new NotificationsServiceStub ( ) } ,
135+ { provide : APP_CONFIG , useValue : { } } ,
134136 ] ,
135137 } ) . overrideComponent ( LuckySearchComponent , {
136138 remove : {
@@ -355,4 +357,57 @@ describe('LuckySearchComponent', () => {
355357 } ) ;
356358
357359 } ) ;
360+
361+ describe ( '' , ( ) => {
362+ beforeEach ( ( ) => {
363+ fixture = TestBed . createComponent ( LuckySearchComponent ) ;
364+ component = fixture . componentInstance ;
365+ } ) ;
366+
367+ it ( 'should return default code when no specific identifier is found' , ( ) => {
368+ // @ts -ignore: Accessing private method for testing
369+ component . appConfig = {
370+ luckySearchRedirects : {
371+ default : 301 ,
372+ } ,
373+ } as any ;
374+ // @ts -ignore: Accessing private method for testing
375+ component . currentFilter = { identifier : 'unknown' } ;
376+
377+ // @ts -ignore: Accessing private method for testing
378+ const result = component . getRedirectCode ( ) ;
379+
380+ expect ( result ) . toBe ( 301 ) ;
381+ } ) ;
382+
383+ it ( 'should return 302 when default is not set and identifier is not found' , ( ) => {
384+ // @ts -ignore: Accessing private method for testing
385+ component . appConfig = {
386+ luckySearchRedirects : { } ,
387+ } as any ;
388+ // @ts -ignore: Accessing private method for testing
389+ component . currentFilter = { identifier : 'unknown' } ;
390+
391+ // @ts -ignore: Accessing private method for testing
392+ const result = component . getRedirectCode ( ) ;
393+ expect ( result ) . toBe ( 302 ) ;
394+ } ) ;
395+
396+ it ( 'should return specific code for known identifier' , ( ) => {
397+ // @ts -ignore: Accessing private method for testing
398+ component . appConfig = {
399+ luckySearchRedirects : {
400+ default : 302 ,
401+ 'legacy-id' : 301 ,
402+ } ,
403+ } ;
404+ // @ts -ignore: Accessing private method for testing
405+ component . currentFilter = { identifier : 'legacy-id' } ;
406+
407+ // @ts -ignore: Accessing private method for testing
408+ const result = component . getRedirectCode ( ) ;
409+ expect ( result ) . toBe ( 301 ) ;
410+ } ) ;
411+
412+ } ) ;
358413} ) ;
0 commit comments