Skip to content
Snippets Groups Projects
Commit 96410d88 authored by Martin's avatar Martin
Browse files

OZG-6986 rename Functions

parent 055eaa6f
No related branches found
No related tags found
1 merge request!25Ozg 6986 adjust routing
......@@ -55,7 +55,7 @@ describe('AuthenticationService', () => {
describe('login', () => {
beforeEach(() => {
service.buildEventPromise = jest.fn();
service.buildAuthEventPromise = jest.fn();
});
it('should configure service with authConfig', async () => {
......@@ -81,12 +81,12 @@ describe('AuthenticationService', () => {
expect(oAuthService.tokenValidationHandler).not.toBeNull();
});
it('should build event promise', async () => {
service.buildEventPromise = jest.fn().mockResolvedValue(() => Promise.resolve());
it('should build auth event promise', async () => {
service.buildAuthEventPromise = jest.fn().mockResolvedValue(() => Promise.resolve());
await service.login();
expect(service.buildEventPromise).toHaveBeenCalled();
expect(service.buildAuthEventPromise).toHaveBeenCalled();
});
it('should load discovery document and login', () => {
......@@ -97,7 +97,7 @@ describe('AuthenticationService', () => {
it('should return eventPromise', async () => {
const promise: Promise<void> = Promise.resolve();
service.buildEventPromise = jest.fn().mockResolvedValue(promise);
service.buildAuthEventPromise = jest.fn().mockResolvedValue(promise);
const returnPromise: Promise<void> = service.login();
......@@ -105,39 +105,39 @@ describe('AuthenticationService', () => {
});
});
describe('build event promise', () => {
describe('build auth event promise', () => {
const event: OAuthEvent = createOAuthEvent();
beforeEach(() => {
service.shouldProceedByType = jest.fn().mockReturnValue(true);
service.shouldProceedByAuthEvent = jest.fn().mockReturnValue(true);
service.setCurrentUser = jest.fn();
service.unsubscribeEvents = jest.fn();
});
it('should call shouldProceedByType on event trigger', () => {
service.buildEventPromise();
it('should call shouldProceedByAuthEvent on event trigger', () => {
service.buildAuthEventPromise();
eventsSubject.next(event);
expect(service.shouldProceedByType).toHaveBeenCalledWith(event);
expect(service.shouldProceedByAuthEvent).toHaveBeenCalledWith(event);
});
describe('on next', () => {
it('should set current user', () => {
service.buildEventPromise();
service.buildAuthEventPromise();
eventsSubject.next(event);
expect(service.setCurrentUser).toHaveBeenCalled();
});
it('should unsubscribe event', () => {
service.buildEventPromise();
service.buildAuthEventPromise();
eventsSubject.next(event);
expect(service.unsubscribeEvents).toHaveBeenCalled();
});
it('should resolved promise with a valid event', async () => {
const promise: Promise<void> = service.buildEventPromise();
const promise: Promise<void> = service.buildAuthEventPromise();
eventsSubject.next(event);
await expect(promise).resolves.toBeUndefined();
......@@ -149,14 +149,14 @@ describe('AuthenticationService', () => {
const error: Error = new Error(errorMessage);
it('should unsubscribe event', () => {
service.buildEventPromise();
service.buildAuthEventPromise();
eventsSubject.error(error);
expect(service.unsubscribeEvents).toHaveBeenCalled();
});
it('should reject the promise with an error', async () => {
const promise: Promise<void> = service.buildEventPromise();
const promise: Promise<void> = service.buildAuthEventPromise();
eventsSubject.error(error);
......@@ -165,13 +165,13 @@ describe('AuthenticationService', () => {
});
});
describe('should proceed by type', () => {
describe('should proceed by auth event', () => {
const event: OAuthEvent = createOAuthEvent();
it('should call considered as login event', () => {
service.consideredAsLoginEvent = jest.fn();
service.shouldProceedByType(event);
service.shouldProceedByAuthEvent(event);
expect(service.consideredAsLoginEvent).toHaveBeenCalledWith(event.type);
});
......@@ -179,7 +179,7 @@ describe('AuthenticationService', () => {
it('should return true on login event', () => {
service.consideredAsLoginEvent = jest.fn().mockReturnValue(true);
const proceed: boolean = service.shouldProceedByType(event);
const proceed: boolean = service.shouldProceedByAuthEvent(event);
expect(proceed).toBeTruthy();
});
......@@ -188,7 +188,7 @@ describe('AuthenticationService', () => {
service.consideredAsLoginEvent = jest.fn().mockReturnValue(false);
service.consideredAsPageReloadEvent = jest.fn();
service.shouldProceedByType(event);
service.shouldProceedByAuthEvent(event);
expect(service.consideredAsPageReloadEvent).toHaveBeenCalledWith(event.type);
});
......@@ -197,7 +197,7 @@ describe('AuthenticationService', () => {
service.consideredAsLoginEvent = jest.fn().mockReturnValue(false);
service.consideredAsPageReloadEvent = jest.fn().mockReturnValue(true);
const proceed: boolean = service.shouldProceedByType(event);
const proceed: boolean = service.shouldProceedByAuthEvent(event);
expect(proceed).toBeTruthy();
});
......@@ -206,7 +206,7 @@ describe('AuthenticationService', () => {
service.consideredAsLoginEvent = jest.fn().mockReturnValue(false);
service.consideredAsPageReloadEvent = jest.fn().mockReturnValue(false);
const proceed: boolean = service.shouldProceedByType(event);
const proceed: boolean = service.shouldProceedByAuthEvent(event);
expect(proceed).toBeFalsy();
});
......
......@@ -45,18 +45,18 @@ export class AuthenticationService {
this.oAuthService.setupAutomaticSilentRefresh();
this.oAuthService.tokenValidationHandler = new JwksValidationHandler();
const eventPromise: Promise<void> = this.buildEventPromise();
const eventPromise: Promise<void> = this.buildAuthEventPromise();
await this.oAuthService.loadDiscoveryDocumentAndLogin();
return eventPromise;
}
buildEventPromise(): Promise<void> {
return new Promise<void>((resolve, reject) => this.handleOAuthEventsForPromise(resolve, reject));
buildAuthEventPromise(): Promise<void> {
return new Promise<void>((resolve, reject) => this.handleAuthEventsForPromise(resolve, reject));
}
private handleOAuthEventsForPromise(resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void): void {
private handleAuthEventsForPromise(resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void): void {
this.eventSubscription = this.oAuthService.events
.pipe(filter((event: OAuthEvent) => this.shouldProceedByType(event)))
.pipe(filter((event: OAuthEvent) => this.shouldProceedByAuthEvent(event)))
.subscribe({
next: () => {
this.setCurrentUser();
......@@ -70,7 +70,7 @@ export class AuthenticationService {
});
}
shouldProceedByType(event: OAuthEvent): boolean {
shouldProceedByAuthEvent(event: OAuthEvent): boolean {
return this.consideredAsLoginEvent(event.type) || this.consideredAsPageReloadEvent(event.type);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment