fix(admin-panel): resolve feature flag key mismatch (#9530)

Update feature flag handling by mapping input keys to enum values. This
ensures compatibility and prevents potential runtime errors when
updating workspace feature flags.
This commit is contained in:
Antoine Moreaux
2025-01-10 12:30:42 +01:00
committed by GitHub
parent c716a30d92
commit 75bf9e3c69
7 changed files with 324 additions and 10 deletions

View File

@ -0,0 +1,54 @@
import { ExecutionContext } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { expect, jest } from '@jest/globals';
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);
});
});