-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathsecurity.effect.spec.ts
35 lines (32 loc) · 1.22 KB
/
security.effect.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {TestBed, waitForAsync} from '@angular/core/testing';
import {provideMockActions} from '@ngrx/effects/testing';
import {cold} from 'jasmine-marbles';
import {Router} from '@angular/router';
import {Action} from '@ngrx/store';
import {Observable, of} from 'rxjs';
import * as SecurityAction from './security.action';
import {SecurityEffect} from './security.effect';
describe('Security Effect', () => {
let effects: SecurityEffect;
let actions$: Observable<Action>;
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
providers: [SecurityEffect, provideMockActions(() => actions$), {provide: Router, useValue: routerSpy}]
}).compileComponents();
effects = TestBed.inject(SecurityEffect);
}));
it('Unauthorised should logout', () => {
const props = {
authenticated: false,
enabled: false,
username: '',
roles: [],
clientRegistrations: []
};
actions$ = of(SecurityAction.unauthorised(props));
const expected = cold('(a|)', {a: SecurityAction.logout(props)});
expect(effects.securityReset$).toBeObservable(expected);
expect(routerSpy.navigate).toHaveBeenCalledWith(['/']);
});
});