From cd131d4eeb1057f73f0d1e13f1634cb2b180d5b2 Mon Sep 17 00:00:00 2001 From: lotte Date: Tue, 9 Apr 2019 11:10:47 +0200 Subject: [PATCH] Fixed test issues --- src/app/core/auth/auth.service.spec.ts | 35 +++++++++++++++----------- src/app/core/auth/auth.service.ts | 1 - 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/app/core/auth/auth.service.spec.ts b/src/app/core/auth/auth.service.spec.ts index c461148eea..ebb4026265 100644 --- a/src/app/core/auth/auth.service.spec.ts +++ b/src/app/core/auth/auth.service.spec.ts @@ -26,21 +26,24 @@ import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-da describe('AuthService test', () => { - const mockStore: Store = jasmine.createSpyObj('store', { - dispatch: {}, - pipe: observableOf(true) - }); + let mockStore: Store; let authService: AuthService; let authRequest; - const window = new NativeWindowRef(); - const routerStub = new RouterStub(); + let window; + let routerStub; let routeStub; let storage: CookieService; let token: AuthTokenInfo; let authenticatedState; - const rdbService = getMockRemoteDataBuildService(); + let rdbService; function init() { + mockStore = jasmine.createSpyObj('store', { + dispatch: {}, + pipe: observableOf(true) + }); + window = new NativeWindowRef(); + routerStub = new RouterStub() token = new AuthTokenInfo('test_token'); token.expires = Date.now() + (1000 * 60 * 60); authenticatedState = { @@ -52,15 +55,14 @@ describe('AuthService test', () => { }; authRequest = new AuthRequestServiceStub(); routeStub = new ActivatedRouteStub(); - } + rdbService = getMockRemoteDataBuildService(); + spyOn(rdbService, 'build').and.returnValue({authenticated: true, eperson: observableOf({payload: {}})}); - beforeEach(() => { - init(); - }); + } describe('', () => { beforeEach(() => { - + init(); TestBed.configureTestingModule({ imports: [ CommonModule, @@ -137,7 +139,8 @@ describe('AuthService test', () => { { provide: REQUEST, useValue: {} }, { provide: Router, useValue: routerStub }, { provide: RemoteDataBuildService, useValue: rdbService }, - CookieService + CookieService, + AuthService ] }).compileComponents(); })); @@ -176,8 +179,8 @@ describe('AuthService test', () => { }); describe('', () => { - beforeEach(async(() => { + init(); TestBed.configureTestingModule({ imports: [ StoreModule.forRoot({ authReducer }) @@ -186,8 +189,10 @@ describe('AuthService test', () => { { provide: AuthRequestService, useValue: authRequest }, { provide: REQUEST, useValue: {} }, { provide: Router, useValue: routerStub }, + { provide: RemoteDataBuildService, useValue: rdbService }, ClientCookieService, - CookieService + CookieService, + AuthService ] }).compileComponents(); })); diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index d0547a1b9c..7874eebea8 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -238,7 +238,6 @@ export class AuthService { throw(new Error('auth.errors.invalid-user')); } })) - } /**