diff --git a/alfa-client/apps/admin/src/common/user-profile-button-container/user-profile-button-container.component.spec.ts b/alfa-client/apps/admin/src/common/user-profile-button-container/user-profile-button-container.component.spec.ts index ca63742722fc7a9e3987f8621296df2eae6aa37f..f96d0b911d20d6e9c4da08c2c7cce135b3d4f863 100644 --- a/alfa-client/apps/admin/src/common/user-profile-button-container/user-profile-button-container.component.spec.ts +++ b/alfa-client/apps/admin/src/common/user-profile-button-container/user-profile-button-container.component.spec.ts @@ -66,7 +66,7 @@ describe('UserProfileButtonContainerComponent', () => { fixture.detectChanges(); const buttonElement: HTMLElement = getElementFromFixture(fixture, dropDownButton); - expect(buttonElement.textContent).toEqual('AV'); + expect(buttonElement.textContent.trim()).toEqual('AV'); }); }); 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 466e7d4567ec9c922289fa86ad578faac231a6e0..16b30c377fd4926c36a7d15d8cb4c635f08f7b00 100644 --- a/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts +++ b/alfa-client/libs/authentication/src/lib/authentication.service.spec.ts @@ -23,53 +23,43 @@ describe('AuthenticationService', () => { }); describe('login', () => { - it('should call proceedWithLogin', () => { - service.proceedWithLogin = jest.fn().mockImplementation(() => Promise.resolve()); + it('should configure service with authConfig', () => { + const authConfig: AuthConfig = createAuthConfig(); + service.buildConfiguration = jest.fn().mockReturnValue(authConfig); service.login(); - expect(service.proceedWithLogin).toHaveBeenCalled(); + expect(oAuthService.configure).toHaveBeenCalledWith(authConfig); }); - describe('proceed with login', () => { - it('should configure service with authConfig', () => { - const authConfig: AuthConfig = createAuthConfig(); - service.buildConfiguration = jest.fn().mockReturnValue(authConfig); - - service.proceedWithLogin(Promise.resolve); - - expect(oAuthService.configure).toHaveBeenCalledWith(authConfig); - }); - - it('should setup automatic silent refresh', () => { - service.proceedWithLogin(Promise.resolve); + it('should setup automatic silent refresh', () => { + service.login(); - expect(oAuthService.setupAutomaticSilentRefresh).toHaveBeenCalled(); - }); + expect(oAuthService.setupAutomaticSilentRefresh).toHaveBeenCalled(); + }); - // it('should set tokenValidator', () => { - // oAuthService.tokenValidationHandler = null; + it('should set tokenValidator', () => { + oAuthService.tokenValidationHandler = null; - // service.proceedWithLogin(Promise.resolve); + service.login(); - // expect(oAuthService.tokenValidationHandler).not.toBeNull(); - // }); + expect(oAuthService.tokenValidationHandler).not.toBeNull(); + }); - it('should load discovery document and login', () => { - service.proceedWithLogin(Promise.resolve); + it('should load discovery document and login', () => { + service.login(); - expect(oAuthService.loadDiscoveryDocumentAndLogin).toHaveBeenCalled(); - }); + expect(oAuthService.loadDiscoveryDocumentAndLogin).toHaveBeenCalled(); + }); - it('should set current user', fakeAsync(() => { - service.setCurrentUser = jest.fn(); + it('should set current user', fakeAsync(() => { + service.setCurrentUser = jest.fn(); - service.proceedWithLogin(() => Promise.resolve); - tick(); + service.login(); + tick(); - expect(service.setCurrentUser).toHaveBeenCalled(); - })); - }); + expect(service.setCurrentUser).toHaveBeenCalled(); + })); }); describe('set current user', () => { diff --git a/alfa-client/libs/authentication/src/lib/authentication.service.ts b/alfa-client/libs/authentication/src/lib/authentication.service.ts index 542131f68589a18722812b761b64f548e08fcc4c..0e45de7eec32e9788212415f86e98db6b5012fce 100644 --- a/alfa-client/libs/authentication/src/lib/authentication.service.ts +++ b/alfa-client/libs/authentication/src/lib/authentication.service.ts @@ -15,19 +15,11 @@ export class AuthenticationService { ) {} public async login(): Promise<void> { - return new Promise<void>((resolve: (value: void | PromiseLike<void>) => void) => - this.proceedWithLogin(resolve), - ); - } - - proceedWithLogin(resolve: (value: void | PromiseLike<void>) => void): void { this.oAuthService.configure(this.buildConfiguration()); this.oAuthService.setupAutomaticSilentRefresh(); this.oAuthService.tokenValidationHandler = new JwksValidationHandler(); - this.oAuthService.loadDiscoveryDocumentAndLogin().then(() => { - this.setCurrentUser(); - resolve(); - }); + await this.oAuthService.loadDiscoveryDocumentAndLogin(); + this.setCurrentUser(); } buildConfiguration(): AuthConfig {