File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import { TestBed } from '@angular/core/testing' ;
2+ import { CanMatchFn } from '@angular/router' ;
3+
4+ import { authGuard } from './auth.guard' ;
5+
6+ describe ( 'authGuard' , ( ) => {
7+ const executeGuard : CanMatchFn = ( ...guardParameters ) =>
8+ TestBed . runInInjectionContext ( ( ) => authGuard ( ...guardParameters ) ) ;
9+
10+ beforeEach ( ( ) => {
11+ TestBed . configureTestingModule ( { } ) ;
12+ } ) ;
13+
14+ it ( 'should be created' , ( ) => {
15+ expect ( executeGuard ) . toBeTruthy ( ) ;
16+ } ) ;
17+ } ) ;
Original file line number Diff line number Diff line change 11import { inject } from '@angular/core' ;
22import { CanMatchFn , Router } from '@angular/router' ;
3+ < < < << << HEAD
34import { AuthService } from '../auth.service' ;
45import { Roles } from '../../shared/_enums/roles' ;
6+ === === =
7+ import { Observable } from 'rxjs' ;
8+ import { map , take } from 'rxjs/operators' ;
9+ import { AuthService } from '../auth.service' ;
10+ >>> >>> > 2 ca65a2 ( auth guard moved to auth folder )
511
612export const authGuard : CanMatchFn = ( ) : boolean => {
713 const authService = inject ( AuthService ) ;
814 const router = inject ( Router ) ;
15+ < < < << << HEAD
916
1017 if ( authService . user$ ( ) ?. roles ?. includes ( Roles . ADMIN ) ) {
18+ === = ===
19+ console . log ( 'GUARD' , authService . isAdmin$ ( ) ) ;
20+ if ( authService . isAdmin$ ( ) ) {
21+ >>> > >>> 2 ca65a2 ( auth guard moved to auth folder )
1122 return true ;
1223 } else {
1324 router . navigate ( [ '/posts' ] ) ;
1425 return false ;
1526 }
27+ << < < < << HEAD
28+ === = ===
29+
30+ >>> > >>> 2 ca65a2 ( auth guard moved to auth folder )
1631} ;
You can’t perform that action at this time.
0 commit comments