diff --git a/alfa-client/apps/admin/src/common/auth/auth.service.spec.ts b/alfa-client/apps/admin/src/common/auth/auth.service.spec.ts index 4cfb03ac88b573a851db79bfc90552306436d009..26e9d1e857d679a45775328b57ca951987208eb2 100644 --- a/alfa-client/apps/admin/src/common/auth/auth.service.spec.ts +++ b/alfa-client/apps/admin/src/common/auth/auth.service.spec.ts @@ -2,7 +2,9 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { AuthService } from './auth.service'; import { UserProfileResource } from '@alfa-client/user-profile-shared'; import { createUserProfileResource } from '../../../../../libs/user-profile-shared/test/user-profile'; -import { JwksValidationHandler, OAuthService } from 'angular-oauth2-oidc'; +import { AuthConfig, OAuthService } from 'angular-oauth2-oidc'; +import { fakeAsync, tick } from '@angular/core/testing'; +import { createAuthConfig } from './auth.test'; describe('AuthService', () => { let service: AuthService; @@ -10,7 +12,10 @@ describe('AuthService', () => { let environmentConfig; beforeEach(() => { - oAuthService = mock(OAuthService); + oAuthService = <any>{ + ...mock(OAuthService), + loadDiscoveryDocumentAndLogin: jest.fn().mockResolvedValue(() => Promise.resolve()), + }; environmentConfig = {}; service = new AuthService(useFromMock(oAuthService), environmentConfig); @@ -25,15 +30,14 @@ describe('AuthService', () => { expect(service.proceedWithLogin).toHaveBeenCalled(); }); - describe.skip('FIXME(proper mock of then)proceed with login', () => { - beforeEach(() => { - oAuthService.loadDiscoveryDocumentAndTryLogin.mockImplementation(() => Promise.resolve()); - }); + describe('proceed with login', () => { + it('should configure service with authConfig', () => { + const authConfig: AuthConfig = createAuthConfig(); + service.buildConfiguration = jest.fn().mockReturnValue(authConfig); - it('should configure service', () => { service.proceedWithLogin(Promise.resolve); - expect(oAuthService.configure).toHaveBeenCalled(); + expect(oAuthService.configure).toHaveBeenCalledWith(authConfig); }); it('should setup automatic silent refresh', () => { @@ -47,7 +51,7 @@ describe('AuthService', () => { service.proceedWithLogin(Promise.resolve); - expect(oAuthService.tokenValidationHandler).toEqual(new JwksValidationHandler()); + expect(oAuthService.tokenValidationHandler).not.toBeNull(); }); it('should load discovery document and login', () => { @@ -56,21 +60,14 @@ describe('AuthService', () => { expect(oAuthService.loadDiscoveryDocumentAndLogin).toHaveBeenCalled(); }); - it('should set current user', () => { + it('should set current user', fakeAsync(() => { service.setCurrentUser = jest.fn(); - service.proceedWithLogin(Promise.resolve); + service.proceedWithLogin(() => Promise.resolve); + tick(); expect(service.setCurrentUser).toHaveBeenCalled(); - }); - - it('should resolve', () => { - const resolve = Promise.resolve; - - service.proceedWithLogin(resolve); - - expect(resolve).toHaveBeenCalled(); - }); + })); }); }); diff --git a/alfa-client/apps/admin/src/common/auth/auth.service.ts b/alfa-client/apps/admin/src/common/auth/auth.service.ts index 0f6a345310573367899352c09fef9ca97cd7ab25..98a63e28edeab016888dfa4bcdbf063b8ba0b4c5 100644 --- a/alfa-client/apps/admin/src/common/auth/auth.service.ts +++ b/alfa-client/apps/admin/src/common/auth/auth.service.ts @@ -30,7 +30,7 @@ export class AuthService { }); } - private buildConfiguration(): AuthConfig { + buildConfiguration(): AuthConfig { return { issuer: this.envConfig.authServer + '/realms/' + this.envConfig.realm, tokenEndpoint: diff --git a/alfa-client/apps/admin/src/common/auth/auth.test.ts b/alfa-client/apps/admin/src/common/auth/auth.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..a33cb3c48a772b5327e9251eaa4a892743c7d2c2 --- /dev/null +++ b/alfa-client/apps/admin/src/common/auth/auth.test.ts @@ -0,0 +1,5 @@ +import { AuthConfig } from 'angular-oauth2-oidc'; + +export function createAuthConfig(): AuthConfig { + return {}; +} diff --git a/alfa-client/apps/admin/src/main.ts b/alfa-client/apps/admin/src/main.ts index 5e03b925b784465a49e2f49ead63c0801124b6b0..3199db2879e8a93ad807dd20615329948b7e0373 100644 --- a/alfa-client/apps/admin/src/main.ts +++ b/alfa-client/apps/admin/src/main.ts @@ -14,9 +14,6 @@ loadEnvironment(environment.environmentUrl).then((env) => { if (env.production) { enableProdMode(); } - console.info('init bootstrap application...'); - //Für Standalone AppComponent - //bootstrapApplication(AppComponent, appConfig).catch(err => console.error(err)); platformBrowserDynamic() .bootstrapModule(AppModule) .catch((err) => console.log(err)); diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts index 53829e1fce73f0d3dbb83fcb30d91fafc1a576d0..3e795f982fbc6d9f97d5d2e44e2b73f20a535261 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts +++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts @@ -33,7 +33,6 @@ export class PostfachFormService extends AbstractFormService { } protected doSubmit(): Observable<StateResource<Resource>> { - console.info('FormValue: ', this.getFormValue()); return of(createEmptyStateResource<Resource>()); }