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';
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();
});
}));
});
});
......
......@@ -30,7 +30,7 @@ export class AuthService {
});
}
private buildConfiguration(): AuthConfig {
buildConfiguration(): AuthConfig {
return {
issuer: this.envConfig.authServer + '/realms/' + this.envConfig.realm,
tokenEndpoint:
......
import { AuthConfig } from 'angular-oauth2-oidc';
export function createAuthConfig(): AuthConfig {
return {};
}
......@@ -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));
......
......@@ -33,7 +33,6 @@ export class PostfachFormService extends AbstractFormService {
}
protected doSubmit(): Observable<StateResource<Resource>> {
console.info('FormValue: ', this.getFormValue());
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