Skip to content

Commit

Permalink
[AAE-18459] Replace all placeholders if the configuration key is an o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
alep85 committed Dec 11, 2023
1 parent f528283 commit 6b7dcb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/core/src/lib/app-config/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,20 @@ describe('AppConfigService', () => {
expect(fakeCallBack).toHaveBeenCalled();
});

it('should replace all the configuration placeholders if the provided key is an object', () => {
appConfigService.config.objectKey = {
firstUrl: '{protocol}//{hostname}{:port}',
secondUrl: '{protocol}//{hostname}{:port}',
thirdUrl: '{protocol}//{hostname}{:port}'
};
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue(':8080');
spyOn(appConfigService, 'getLocationProtocol').and.returnValue('http:');

expect(appConfigService.get<any>('objectKey').firstUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').secondUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').thirdUrl).toEqual('http://localhost:8080');
});


});
6 changes: 3 additions & 3 deletions lib/core/src/lib/app-config/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export class AppConfigService {
}

if (typeof result === 'object') {
result = JSON.parse(JSON.stringify(result).replace('{hostname}', this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace('{:port}', this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace('{protocol}', this.getLocationProtocol()));
result = JSON.parse(JSON.stringify(result).replace(/{hostname}/g, this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace(/{:port}/g, this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace(/{protocol}/g, this.getLocationProtocol()));
}

if (result === undefined) {
Expand Down

0 comments on commit 6b7dcb7

Please sign in to comment.