55 AppConfigService ,
66 HelpMessages ,
77} from "app-config.service" ;
8- import { of } from "rxjs" ;
8+ import { Observable , of } from "rxjs" ;
99import { MockHttp } from "shared/MockStubs" ;
1010
1111const appConfig : AppConfigInterface = {
@@ -280,6 +280,47 @@ describe("AppConfigService", () => {
280280 } ) ;
281281
282282 describe ( "#getConfig()" , ( ) => {
283+ const mockConfigResponses : Record < string , object > = {
284+ "/assets/config.json" : {
285+ accessTokenPrefix : "" ,
286+ lbBaseURL : "http://127.0.0.1:3000" ,
287+ gettingStarted : null ,
288+ mainMenu : { nonAuthenticatedUser : { datasets : true } } ,
289+ } ,
290+ "/assets/config.0.json" : { accessTokenPrefix : "Bearer " } ,
291+ "/assets/config.override.json" : {
292+ gettingStarted : "aGettingStarted" ,
293+ addDatasetEnabled : true ,
294+ mainMenu : { nonAuthenticatedUser : { files : true } } ,
295+ } ,
296+ "/assets/config.override.0.json" : { siteTitle : "Test title" } ,
297+ } ;
298+
299+ const mergedConfig = {
300+ accessTokenPrefix : "Bearer " ,
301+ lbBaseURL : "http://127.0.0.1:3000" ,
302+ gettingStarted : "aGettingStarted" ,
303+ addDatasetEnabled : true ,
304+ siteTitle : "Test title" ,
305+ mainMenu : { nonAuthenticatedUser : { datasets : true , files : true } } ,
306+ } ;
307+
308+ const mockHttpGet = ( backendError = false ) => {
309+ spyOn ( service [ "http" ] , "get" ) . and . callFake (
310+ ( url : string ) : Observable < any > => {
311+ if ( url === "/api/v3/admin/config" ) {
312+ if ( backendError ) {
313+ return new Observable ( ( sub ) =>
314+ sub . error ( new Error ( "No config in backend" ) ) ,
315+ ) ;
316+ }
317+ return of ( mergedConfig ) ;
318+ }
319+ return of ( mockConfigResponses [ url ] || { } ) ;
320+ } ,
321+ ) ;
322+ } ;
323+
283324 it ( "should return the AppConfig object" , async ( ) => {
284325 spyOn ( service [ "http" ] , "get" ) . and . returnValue ( of ( appConfig ) ) ;
285326 await service . loadAppConfig ( ) ;
@@ -288,5 +329,29 @@ describe("AppConfigService", () => {
288329
289330 expect ( config ) . toEqual ( appConfig ) ;
290331 } ) ;
332+
333+ it ( "should merge multiple config JSONs" , async ( ) => {
334+ mockHttpGet ( ) ;
335+ const config = await service [ "mergeConfig" ] ( ) ;
336+ expect ( config ) . toEqual ( mergedConfig ) ;
337+ } ) ;
338+
339+ it ( "should return the merged appConfig" , async ( ) => {
340+ mockHttpGet ( true ) ;
341+ await service . loadAppConfig ( ) ;
342+
343+ expect ( service [ "appConfig" ] ) . toEqual (
344+ jasmine . objectContaining ( mergedConfig ) ,
345+ ) ;
346+ expect ( service [ "http" ] . get ) . toHaveBeenCalledWith ( "/api/v3/admin/config" ) ;
347+ expect ( service [ "http" ] . get ) . toHaveBeenCalledWith ( "/assets/config.json" ) ;
348+ expect ( service [ "http" ] . get ) . toHaveBeenCalledWith ( "/assets/config.0.json" ) ;
349+ expect ( service [ "http" ] . get ) . toHaveBeenCalledWith (
350+ "/assets/config.override.json" ,
351+ ) ;
352+ expect ( service [ "http" ] . get ) . toHaveBeenCalledWith (
353+ "/assets/config.override.0.json" ,
354+ ) ;
355+ } ) ;
291356 } ) ;
292357} ) ;
0 commit comments