remove companion tests
This commit is contained in:
@@ -28,7 +28,7 @@ function createExecutionContext(options: { handler: Function; userId?: string })
|
||||
}
|
||||
|
||||
describe('AuthorizationGuard', () => {
|
||||
it('allows public routes without a user session', () => {
|
||||
it('allows public routes without a user session', async () => {
|
||||
const authorizationService = { getRolesForUser: vi.fn() };
|
||||
const guard = new AuthorizationGuard(new Reflector(), authorizationService as any);
|
||||
|
||||
@@ -36,11 +36,11 @@ describe('AuthorizationGuard', () => {
|
||||
handler: DummyController.prototype.publicHandler,
|
||||
});
|
||||
|
||||
expect(guard.canActivate(ctx as any)).toBe(true);
|
||||
await expect(guard.canActivate(ctx as any)).resolves.toBe(true);
|
||||
expect(authorizationService.getRolesForUser).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('denies non-public routes by default when not authenticated', () => {
|
||||
it('denies non-public routes by default when not authenticated', async () => {
|
||||
const authorizationService = { getRolesForUser: vi.fn() };
|
||||
const guard = new AuthorizationGuard(new Reflector(), authorizationService as any);
|
||||
|
||||
@@ -48,10 +48,10 @@ describe('AuthorizationGuard', () => {
|
||||
handler: DummyController.prototype.protectedHandler,
|
||||
});
|
||||
|
||||
expect(() => guard.canActivate(ctx as any)).toThrow(UnauthorizedException);
|
||||
await expect(guard.canActivate(ctx as any)).rejects.toThrow(UnauthorizedException);
|
||||
});
|
||||
|
||||
it('allows non-public routes when authenticated', () => {
|
||||
it('allows non-public routes when authenticated', async () => {
|
||||
const authorizationService = { getRolesForUser: vi.fn().mockReturnValue([]) };
|
||||
const guard = new AuthorizationGuard(new Reflector(), authorizationService as any);
|
||||
|
||||
@@ -60,10 +60,10 @@ describe('AuthorizationGuard', () => {
|
||||
userId: 'user-1',
|
||||
});
|
||||
|
||||
expect(guard.canActivate(ctx as any)).toBe(true);
|
||||
await expect(guard.canActivate(ctx as any)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('denies routes requiring roles when user does not have any required role', () => {
|
||||
it('denies routes requiring roles when user does not have any required role', async () => {
|
||||
const authorizationService = { getRolesForUser: vi.fn().mockReturnValue(['user']) };
|
||||
const guard = new AuthorizationGuard(new Reflector(), authorizationService as any);
|
||||
|
||||
@@ -72,10 +72,10 @@ describe('AuthorizationGuard', () => {
|
||||
userId: 'user-1',
|
||||
});
|
||||
|
||||
expect(() => guard.canActivate(ctx as any)).toThrow(ForbiddenException);
|
||||
await expect(guard.canActivate(ctx as any)).rejects.toThrow(ForbiddenException);
|
||||
});
|
||||
|
||||
it('allows routes requiring roles when user has a required role', () => {
|
||||
it('allows routes requiring roles when user has a required role', async () => {
|
||||
const authorizationService = { getRolesForUser: vi.fn().mockReturnValue(['admin']) };
|
||||
const guard = new AuthorizationGuard(new Reflector(), authorizationService as any);
|
||||
|
||||
@@ -84,6 +84,6 @@ describe('AuthorizationGuard', () => {
|
||||
userId: 'user-1',
|
||||
});
|
||||
|
||||
expect(guard.canActivate(ctx as any)).toBe(true);
|
||||
await expect(guard.canActivate(ctx as any)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user