-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
346 additions
and
344 deletions.
There are no files selected for viewing
58 changes: 29 additions & 29 deletions
58
client/wfprev-war/src/main/angular/src/app/interfaces/application-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
export interface Application { | ||
acronym: string; | ||
version: string; | ||
baseUrl: string; | ||
environment: string; | ||
lazyAuthenticate?: boolean; | ||
enableLocalStorageToken?: boolean; | ||
allowLocalExpiredToken?: boolean; | ||
localStorageTokenKey?: string; | ||
|
||
} | ||
|
||
export interface RestConfig { | ||
[prop: string]: string; | ||
} | ||
|
||
export interface WebADE { | ||
oauth2Url: string; | ||
clientId: string; | ||
authScopes: string; | ||
enableCheckToken?: boolean; | ||
checkTokenUrl?: string; | ||
} | ||
|
||
export interface ApplicationConfig { | ||
application: Application | ||
rest: RestConfig; | ||
webade: WebADE; | ||
} | ||
export interface Application { | ||
acronym: string; | ||
version: string; | ||
baseUrl: string; | ||
environment: string; | ||
lazyAuthenticate?: boolean; | ||
enableLocalStorageToken?: boolean; | ||
allowLocalExpiredToken?: boolean; | ||
localStorageTokenKey?: string; | ||
|
||
} | ||
|
||
export interface RestConfig { | ||
[prop: string]: string; | ||
} | ||
|
||
export interface WebADE { | ||
oauth2Url: string; | ||
clientId: string; | ||
authScopes: string; | ||
enableCheckToken?: boolean; | ||
checkTokenUrl?: string; | ||
} | ||
|
||
export interface ApplicationConfig { | ||
application: Application | ||
rest: RestConfig; | ||
webade: WebADE; | ||
} |
236 changes: 118 additions & 118 deletions
236
client/wfprev-war/src/main/angular/src/app/services/app-config.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,119 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { AppConfigService } from './app-config.service'; | ||
import { LibraryConfig } from '../config/library-config'; | ||
import { ApplicationConfig } from '../interfaces/application-config'; | ||
|
||
describe('AppConfigService', () => { | ||
let service: AppConfigService; | ||
let httpMock: HttpTestingController; | ||
|
||
const mockLibraryConfig: LibraryConfig = { | ||
configurationPath: '/assets/data/appConfig.json', | ||
}; | ||
|
||
const mockConfig: ApplicationConfig = { | ||
application: { | ||
baseUrl: 'http://test.com', | ||
lazyAuthenticate: false, | ||
enableLocalStorageToken: true, | ||
acronym: 'TEST', | ||
environment: 'DEV', | ||
version: '1.0.0', | ||
}, | ||
webade: { | ||
oauth2Url: 'http://oauth.test', | ||
clientId: 'test-client', | ||
authScopes: 'TEST.*', | ||
}, | ||
rest: {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
AppConfigService, | ||
{ provide: LibraryConfig, useValue: mockLibraryConfig }, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(AppConfigService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
it('should load configuration successfully', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockConfig); | ||
|
||
await loadConfigPromise; | ||
|
||
expect(service.getConfig()).toEqual(mockConfig); | ||
}); | ||
|
||
it('should throw an error if configuration is not loaded', () => { | ||
expect(() => service.getConfig()).toThrowError( | ||
'Configuration not loaded. Please call loadAppConfig() first.' | ||
); | ||
}); | ||
|
||
it('should handle HTTP error when loading configuration', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.error(new ErrorEvent('Network error'), { status: 500, statusText: 'Internal Server Error' }); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejectedWithError( | ||
'Failed to load application configuration: Http failure response for /assets/data/appConfig.json: 500 Internal Server Error' | ||
); | ||
}); | ||
|
||
it('should notify configEmitter on successful configuration load', async () => { | ||
const configSpy = jasmine.createSpy('configEmitter'); | ||
service.configEmitter.subscribe(configSpy); | ||
|
||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.flush(mockConfig); | ||
|
||
await loadConfigPromise; | ||
|
||
expect(configSpy).toHaveBeenCalledWith(mockConfig); | ||
}); | ||
|
||
it('should notify configEmitter of errors when loading fails', async () => { | ||
const configSpy = jasmine.createSpy('configEmitter'); | ||
const errorSpy = jasmine.createSpy('error'); | ||
service.configEmitter.subscribe(configSpy, errorSpy); | ||
|
||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.error(new ErrorEvent('Network error'), { status: 500, statusText: 'Internal Server Error' }); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejected(); | ||
|
||
expect(configSpy).not.toHaveBeenCalled(); | ||
expect(errorSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw an error when no data is returned from configuration', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
|
||
// Flush with null to simulate no data | ||
req.flush(null); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejectedWithError( | ||
'Failed to load application configuration: No data returned from application config' | ||
); | ||
}); | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { AppConfigService } from './app-config.service'; | ||
import { LibraryConfig } from '../config/library-config'; | ||
import { ApplicationConfig } from '../interfaces/application-config'; | ||
|
||
describe('AppConfigService', () => { | ||
let service: AppConfigService; | ||
let httpMock: HttpTestingController; | ||
|
||
const mockLibraryConfig: LibraryConfig = { | ||
configurationPath: '/assets/data/appConfig.json', | ||
}; | ||
|
||
const mockConfig: ApplicationConfig = { | ||
application: { | ||
baseUrl: 'http://test.com', | ||
lazyAuthenticate: false, | ||
enableLocalStorageToken: true, | ||
acronym: 'TEST', | ||
environment: 'DEV', | ||
version: '1.0.0', | ||
}, | ||
webade: { | ||
oauth2Url: 'http://oauth.test', | ||
clientId: 'test-client', | ||
authScopes: 'TEST.*', | ||
}, | ||
rest: {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
AppConfigService, | ||
{ provide: LibraryConfig, useValue: mockLibraryConfig }, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(AppConfigService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
it('should load configuration successfully', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
expect(req.request.method).toBe('GET'); | ||
req.flush(mockConfig); | ||
|
||
await loadConfigPromise; | ||
|
||
expect(service.getConfig()).toEqual(mockConfig); | ||
}); | ||
|
||
it('should throw an error if configuration is not loaded', () => { | ||
expect(() => service.getConfig()).toThrowError( | ||
'Configuration not loaded. Please call loadAppConfig() first.' | ||
); | ||
}); | ||
|
||
it('should handle HTTP error when loading configuration', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.error(new ErrorEvent('Network error'), { status: 500, statusText: 'Internal Server Error' }); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejectedWithError( | ||
'Failed to load application configuration: Http failure response for /assets/data/appConfig.json: 500 Internal Server Error' | ||
); | ||
}); | ||
|
||
it('should notify configEmitter on successful configuration load', async () => { | ||
const configSpy = jasmine.createSpy('configEmitter'); | ||
service.configEmitter.subscribe(configSpy); | ||
|
||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.flush(mockConfig); | ||
|
||
await loadConfigPromise; | ||
|
||
expect(configSpy).toHaveBeenCalledWith(mockConfig); | ||
}); | ||
|
||
it('should notify configEmitter of errors when loading fails', async () => { | ||
const configSpy = jasmine.createSpy('configEmitter'); | ||
const errorSpy = jasmine.createSpy('error'); | ||
service.configEmitter.subscribe(configSpy, errorSpy); | ||
|
||
const loadConfigPromise = service.loadAppConfig(); | ||
|
||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
req.error(new ErrorEvent('Network error'), { status: 500, statusText: 'Internal Server Error' }); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejected(); | ||
|
||
expect(configSpy).not.toHaveBeenCalled(); | ||
expect(errorSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw an error when no data is returned from configuration', async () => { | ||
const loadConfigPromise = service.loadAppConfig(); | ||
const req = httpMock.expectOne(mockLibraryConfig.configurationPath); | ||
|
||
// Flush with null to simulate no data | ||
req.flush(null); | ||
|
||
await expectAsync(loadConfigPromise).toBeRejectedWithError( | ||
'Failed to load application configuration: No data returned from application config' | ||
); | ||
}); | ||
}); |
32 changes: 17 additions & 15 deletions
32
client/wfprev-war/src/main/angular/src/assets/data/appConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
{ | ||
"application": { | ||
"baseUrl": "#{WFPREV_BASE_URL}#" | ||
}, | ||
"webade": { | ||
"oauth2Url": "#{WEBADE_OAUTH2_CHECK_AUTHORIZE_URL}#", | ||
"clientId": "WFNEWS-UI", | ||
"authScopes": "WFNEWS.*", | ||
"enableCheckToken": true, | ||
"checkTokenUrl": "#{WFPREV_CHECK_TOKEN_URL}#" | ||
}, | ||
"rest": { | ||
"wfprev": "#{WFPREV_BASE_URL}#" | ||
} | ||
} | ||
{ | ||
"application": { | ||
"baseUrl": "#{WFPREV_BASE_URL}#" | ||
}, | ||
|
||
"webade": { | ||
"oauth2Url": "#{WEBADE_OAUTH2_CHECK_AUTHORIZE_URL}#", | ||
"clientId": "WFNEWS-UI", | ||
"authScopes": "WFNEWS.*", | ||
"enableCheckToken": true, | ||
"checkTokenUrl": "#{WFPREV_CHECK_TOKEN_URL}#" | ||
}, | ||
|
||
"rest": { | ||
"wfprev":"#{WFPREV_BASE_URL}#" | ||
} | ||
} |
32 changes: 16 additions & 16 deletions
32
client/wfprev-war/src/main/angular/src/assets/data/appConfig.local.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"application": { | ||
"baseUrl": "http://localhost:4200/" | ||
}, | ||
|
||
"webade": { | ||
"oauth2Url": "https://wfappsi.nrs.gov.bc.ca/ext/oauth2/v1/oauth/authorize", | ||
"clientId": "WFNEWS-UI", | ||
"authScopes": "WFNEWS.*", | ||
"enableCheckToken": true, | ||
"checkTokenUrl": "./assets/data/checktoken-user.json" | ||
}, | ||
|
||
"rest": { | ||
"wfprev":"http://localhost:8080" | ||
} | ||
{ | ||
"application": { | ||
"baseUrl": "http://localhost:4200/" | ||
}, | ||
|
||
"webade": { | ||
"oauth2Url": "https://wfappsi.nrs.gov.bc.ca/ext/oauth2/v1/oauth/authorize", | ||
"clientId": "WFNEWS-UI", | ||
"authScopes": "WFNEWS.*", | ||
"enableCheckToken": true, | ||
"checkTokenUrl": "./assets/data/checktoken-user.json" | ||
}, | ||
|
||
"rest": { | ||
"wfprev":"http://localhost:8080" | ||
} | ||
} |
Oops, something went wrong.