diff --git a/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts b/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts index 14b3984a1833f29c5900aa7053df98198d0a311f..486415f425de82475e9733ec3f5800cb47128c92 100644 --- a/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts +++ b/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts @@ -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(); }); diff --git a/alfa-client/libs/authentication/src/lib/authentication.service.ts b/alfa-client/libs/authentication/src/lib/authentication.service.ts index b22baa5b455b97006551d8645680b370c70f50d3..e350dcafe7cb9312799db97db5eb50c0d25c8319 100644 --- a/alfa-client/libs/authentication/src/lib/authentication.service.ts +++ b/alfa-client/libs/authentication/src/lib/authentication.service.ts @@ -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); }