admin panel fast follows (#10723)
fast follows: - https://discord.com/channels/1130383047699738754/1346433965451382845 - https://discord.com/channels/1130383047699738754/1346434512757981264 - https://discord.com/channels/1130383047699738754/1346453484911853610 --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
import { ExecutionContext } from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { AdminPanelGuard } from 'src/engine/guards/admin-panel-guard';
|
||||
|
||||
describe('AdminPanelGuard', () => {
|
||||
const guard = new AdminPanelGuard();
|
||||
|
||||
it('should return true if user can access full admin panel', async () => {
|
||||
const mockContext = {
|
||||
getContext: jest.fn(() => ({
|
||||
req: {
|
||||
user: {
|
||||
canAccessFullAdminPanel: true,
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
jest
|
||||
.spyOn(GqlExecutionContext, 'create')
|
||||
.mockReturnValue(mockContext as any);
|
||||
|
||||
const mockExecutionContext = {} as ExecutionContext;
|
||||
|
||||
const result = await guard.canActivate(mockExecutionContext);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if user cannot access full admin panel', async () => {
|
||||
const mockContext = {
|
||||
getContext: jest.fn(() => ({
|
||||
req: {
|
||||
user: {
|
||||
canAccessFullAdminPanel: false,
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
jest
|
||||
.spyOn(GqlExecutionContext, 'create')
|
||||
.mockReturnValue(mockContext as any);
|
||||
|
||||
const mockExecutionContext = {} as ExecutionContext;
|
||||
|
||||
const result = await guard.canActivate(mockExecutionContext);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,52 @@
|
||||
import { ExecutionContext } from '@nestjs/common';
|
||||
import { GqlExecutionContext } from '@nestjs/graphql';
|
||||
|
||||
import { ImpersonateGuard } from 'src/engine/guards/impersonate-guard';
|
||||
|
||||
describe('ImpersonateGuard', () => {
|
||||
const guard = new ImpersonateGuard();
|
||||
|
||||
it('should return true if user can impersonate', async () => {
|
||||
const mockContext = {
|
||||
getContext: jest.fn(() => ({
|
||||
req: {
|
||||
user: {
|
||||
canImpersonate: true,
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
jest
|
||||
.spyOn(GqlExecutionContext, 'create')
|
||||
.mockReturnValue(mockContext as any);
|
||||
|
||||
const mockExecutionContext = {} as ExecutionContext;
|
||||
|
||||
const result = await guard.canActivate(mockExecutionContext);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if user cannot impersonate', async () => {
|
||||
const mockContext = {
|
||||
getContext: jest.fn(() => ({
|
||||
req: {
|
||||
user: {
|
||||
canImpersonate: false,
|
||||
},
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
jest
|
||||
.spyOn(GqlExecutionContext, 'create')
|
||||
.mockReturnValue(mockContext as any);
|
||||
|
||||
const mockExecutionContext = {} as ExecutionContext;
|
||||
|
||||
const result = await guard.canActivate(mockExecutionContext);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user