Skip to content
Snippets Groups Projects
Commit 20a69358 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4321 fix test; cleanup

parent 5a9873f7
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,9 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; ...@@ -2,7 +2,9 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { UserProfileResource } from '@alfa-client/user-profile-shared'; import { UserProfileResource } from '@alfa-client/user-profile-shared';
import { createUserProfileResource } from '../../../../../libs/user-profile-shared/test/user-profile'; 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', () => { describe('AuthService', () => {
let service: AuthService; let service: AuthService;
...@@ -10,7 +12,10 @@ describe('AuthService', () => { ...@@ -10,7 +12,10 @@ describe('AuthService', () => {
let environmentConfig; let environmentConfig;
beforeEach(() => { beforeEach(() => {
oAuthService = mock(OAuthService); oAuthService = <any>{
...mock(OAuthService),
loadDiscoveryDocumentAndLogin: jest.fn().mockResolvedValue(() => Promise.resolve()),
};
environmentConfig = {}; environmentConfig = {};
service = new AuthService(useFromMock(oAuthService), environmentConfig); service = new AuthService(useFromMock(oAuthService), environmentConfig);
...@@ -25,15 +30,14 @@ describe('AuthService', () => { ...@@ -25,15 +30,14 @@ describe('AuthService', () => {
expect(service.proceedWithLogin).toHaveBeenCalled(); expect(service.proceedWithLogin).toHaveBeenCalled();
}); });
describe.skip('FIXME(proper mock of then)proceed with login', () => { describe('proceed with login', () => {
beforeEach(() => { it('should configure service with authConfig', () => {
oAuthService.loadDiscoveryDocumentAndTryLogin.mockImplementation(() => Promise.resolve()); const authConfig: AuthConfig = createAuthConfig();
}); service.buildConfiguration = jest.fn().mockReturnValue(authConfig);
it('should configure service', () => {
service.proceedWithLogin(Promise.resolve); service.proceedWithLogin(Promise.resolve);
expect(oAuthService.configure).toHaveBeenCalled(); expect(oAuthService.configure).toHaveBeenCalledWith(authConfig);
}); });
it('should setup automatic silent refresh', () => { it('should setup automatic silent refresh', () => {
...@@ -47,7 +51,7 @@ describe('AuthService', () => { ...@@ -47,7 +51,7 @@ describe('AuthService', () => {
service.proceedWithLogin(Promise.resolve); service.proceedWithLogin(Promise.resolve);
expect(oAuthService.tokenValidationHandler).toEqual(new JwksValidationHandler()); expect(oAuthService.tokenValidationHandler).not.toBeNull();
}); });
it('should load discovery document and login', () => { it('should load discovery document and login', () => {
...@@ -56,21 +60,14 @@ describe('AuthService', () => { ...@@ -56,21 +60,14 @@ describe('AuthService', () => {
expect(oAuthService.loadDiscoveryDocumentAndLogin).toHaveBeenCalled(); expect(oAuthService.loadDiscoveryDocumentAndLogin).toHaveBeenCalled();
}); });
it('should set current user', () => { it('should set current user', fakeAsync(() => {
service.setCurrentUser = jest.fn(); service.setCurrentUser = jest.fn();
service.proceedWithLogin(Promise.resolve); service.proceedWithLogin(() => Promise.resolve);
tick();
expect(service.setCurrentUser).toHaveBeenCalled(); expect(service.setCurrentUser).toHaveBeenCalled();
}); }));
it('should resolve', () => {
const resolve = Promise.resolve;
service.proceedWithLogin(resolve);
expect(resolve).toHaveBeenCalled();
});
}); });
}); });
......
...@@ -30,7 +30,7 @@ export class AuthService { ...@@ -30,7 +30,7 @@ export class AuthService {
}); });
} }
private buildConfiguration(): AuthConfig { buildConfiguration(): AuthConfig {
return { return {
issuer: this.envConfig.authServer + '/realms/' + this.envConfig.realm, issuer: this.envConfig.authServer + '/realms/' + this.envConfig.realm,
tokenEndpoint: tokenEndpoint:
......
import { AuthConfig } from 'angular-oauth2-oidc';
export function createAuthConfig(): AuthConfig {
return {};
}
...@@ -14,9 +14,6 @@ loadEnvironment(environment.environmentUrl).then((env) => { ...@@ -14,9 +14,6 @@ loadEnvironment(environment.environmentUrl).then((env) => {
if (env.production) { if (env.production) {
enableProdMode(); enableProdMode();
} }
console.info('init bootstrap application...');
//Für Standalone AppComponent
//bootstrapApplication(AppComponent, appConfig).catch(err => console.error(err));
platformBrowserDynamic() platformBrowserDynamic()
.bootstrapModule(AppModule) .bootstrapModule(AppModule)
.catch((err) => console.log(err)); .catch((err) => console.log(err));
......
...@@ -33,7 +33,6 @@ export class PostfachFormService extends AbstractFormService { ...@@ -33,7 +33,6 @@ export class PostfachFormService extends AbstractFormService {
} }
protected doSubmit(): Observable<StateResource<Resource>> { protected doSubmit(): Observable<StateResource<Resource>> {
console.info('FormValue: ', this.getFormValue());
return of(createEmptyStateResource<Resource>()); return of(createEmptyStateResource<Resource>());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment