Skip to content

Commit

Permalink
Revert to original files
Browse files Browse the repository at this point in the history
  • Loading branch information
ssylver93 committed Jan 22, 2025
1 parent 83449c8 commit ba3c02a
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 344 deletions.
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;
}
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 client/wfprev-war/src/main/angular/src/assets/data/appConfig.json
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}#"
}
}
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"
}
}
Loading

0 comments on commit ba3c02a

Please sign in to comment.