Added tests

This commit is contained in:
Giuseppe Digilio
2018-05-17 11:05:26 +02:00
parent 240e1ee0af
commit f66dd32658
4 changed files with 161 additions and 43 deletions

View File

@@ -1,7 +1,12 @@
import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs/Observable';
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Store } from '@ngrx/store';
import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of'
import { AuthEffects } from './auth.effects';
import {
AuthActionTypes,
@@ -20,25 +25,27 @@ import { AuthTokenInfo } from './models/auth-token-info.model';
import { AuthServiceStub } from '../../shared/testing/auth-service-stub';
import { AuthService } from './auth.service';
import { TruncatablesState } from '../../shared/truncatable/truncatable.reducer';
import { Store } from '@ngrx/store';
import { EpersonMock } from '../../shared/testing/eperson-mock';
describe('AuthEffects', () => {
let authEffects: AuthEffects;
let actions: Observable<any>;
const authServiceStub = new AuthServiceStub();
const store: Store<TruncatablesState> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: Observable.of(true)
});
const token = new AuthTokenInfo('token_test');
const token = authServiceStub.getToken();
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AuthEffects,
{provide: AuthService, useClass: AuthServiceStub},
{provide: AuthService, useValue: authServiceStub},
{provide: Store, useValue: store},
provideMockActions(() => actions),
// other providers
@@ -58,7 +65,8 @@ describe('AuthEffects', () => {
}
});
const expected = cold('--b-', {b: new AuthenticationSuccessAction(new AuthTokenInfo('token_test'))});
const expected = cold('--b-', {b: new AuthenticationSuccessAction(token)});
expect(authEffects.authenticate$).toBeObservable(expected);
});
@@ -87,7 +95,7 @@ describe('AuthEffects', () => {
it('should return a AUTHENTICATED action in response to a AUTHENTICATE_SUCCESS action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATE_SUCCESS, payload: token}});
const expected = cold('--b-', {b: new AuthenticatedAction(new AuthTokenInfo('token_test'))});
const expected = cold('--b-', {b: new AuthenticatedAction(token)});
expect(authEffects.authenticateSuccess$).toBeObservable(expected);
});
@@ -125,7 +133,7 @@ describe('AuthEffects', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN}});
const expected = cold('--b-', {b: new AuthenticatedAction(new AuthTokenInfo('token_test'))});
const expected = cold('--b-', {b: new AuthenticatedAction(token)});
expect(authEffects.checkToken$).toBeObservable(expected);
});
@@ -151,7 +159,7 @@ describe('AuthEffects', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.REFRESH_TOKEN}});
const expected = cold('--b-', {b: new RefreshTokenSuccessAction(new AuthTokenInfo('token_test'))});
const expected = cold('--b-', {b: new RefreshTokenSuccessAction(token)});
expect(authEffects.refreshToken$).toBeObservable(expected);
});