Skip to content

Commit

Permalink
Update test name and use new RouterStateSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ssylver93 committed Dec 9, 2024
1 parent fd63deb commit cec8d42
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,31 @@ describe('PrevAuthGuard', () => {

it('should redirect user to error page when token validation fails', fakeAsync(() => {
// Setup route with scopes
const route = new ActivatedRouteSnapshot();
route.data = { scopes: [['test-scope']] };


const state = jasmine.createSpyObj<RouterStateSnapshot>('RouterStateSnapshot', [], { url: '/test' });

// Mock token exists
tokenService.getOauthToken.and.returnValue('test-token');

// Mock token validation fails
tokenService.validateToken.and.returnValue(of(false));

// Spy on redirectToErrorPage
spyOn(guard, 'redirectToErrorPage');

// Trigger canActivate
let result: boolean | undefined;
guard.canActivate(route, state).subscribe(res => {
result = res;
});

tick(); // Simulate passage of time for the observable
expect(guard.redirectToErrorPage).toHaveBeenCalled();
expect(result).toBeUndefined(); // Ensure the result matches the expectation
}));
});
})

describe('getTokenInfo', () => {
let mockRoute: any;
Expand Down Expand Up @@ -288,31 +291,31 @@ describe('PrevAuthGuard', () => {
tokenService.getOauthToken.and.returnValue(null);

const result = await guard.canAccessRoute([['test-scope']], tokenService);

expect(result).toBeFalse();
});

it('should return true when token is validated successfully', async () => {
// Mock token exists
tokenService.getOauthToken.and.returnValue('test-token');

// Mock token validation
tokenService.validateToken.and.returnValue(of(true));

const result = await guard.canAccessRoute([['test-scope']], tokenService);

expect(result).toBeTrue();
});

it('should return false when token validation fails', async () => {
// Mock token exists
tokenService.getOauthToken.and.returnValue('test-token');

// Mock token validation fails
tokenService.validateToken.and.returnValue(of(false));

const result = await guard.canAccessRoute([['test-scope']], tokenService);

expect(result).toBeFalse();
});
});
Expand Down

0 comments on commit cec8d42

Please sign in to comment.