]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { Component, NgZone } from '@angular/core'; |
2 | import { fakeAsync, TestBed, tick } from '@angular/core/testing'; | |
f67539c2 | 3 | import { Routes } from '@angular/router'; |
9f95a23c TL |
4 | import { RouterTestingModule } from '@angular/router/testing'; |
5 | ||
f67539c2 TL |
6 | import { DashboardUserDeniedError } from '~/app/core/error/error'; |
7 | import { configureTestBed } from '~/testing/unit-test-helper'; | |
9f95a23c TL |
8 | import { AuthStorageService } from './auth-storage.service'; |
9 | import { NoSsoGuardService } from './no-sso-guard.service'; | |
10 | ||
11 | describe('NoSsoGuardService', () => { | |
12 | let service: NoSsoGuardService; | |
13 | let authStorageService: AuthStorageService; | |
14 | let ngZone: NgZone; | |
9f95a23c TL |
15 | |
16 | @Component({ selector: 'cd-404', template: '' }) | |
17 | class NotFoundComponent {} | |
18 | ||
19 | const routes: Routes = [{ path: '404', component: NotFoundComponent }]; | |
20 | ||
21 | configureTestBed({ | |
22 | imports: [RouterTestingModule.withRoutes(routes)], | |
23 | providers: [NoSsoGuardService, AuthStorageService], | |
24 | declarations: [NotFoundComponent] | |
25 | }); | |
26 | ||
27 | beforeEach(() => { | |
f67539c2 TL |
28 | service = TestBed.inject(NoSsoGuardService); |
29 | authStorageService = TestBed.inject(AuthStorageService); | |
30 | ngZone = TestBed.inject(NgZone); | |
9f95a23c TL |
31 | }); |
32 | ||
33 | it('should be created', () => { | |
34 | expect(service).toBeTruthy(); | |
35 | }); | |
36 | ||
37 | it('should allow if not logged in via SSO', () => { | |
38 | spyOn(authStorageService, 'isSSO').and.returnValue(false); | |
39 | expect(service.canActivate()).toBe(true); | |
40 | }); | |
41 | ||
42 | it('should prevent if logged in via SSO', fakeAsync(() => { | |
43 | spyOn(authStorageService, 'isSSO').and.returnValue(true); | |
44 | ngZone.run(() => { | |
f67539c2 | 45 | expect(() => service.canActivate()).toThrowError(DashboardUserDeniedError); |
9f95a23c TL |
46 | }); |
47 | tick(); | |
9f95a23c TL |
48 | })); |
49 | }); |