Files
gridpilot.gg/apps/api/src/domain/admin/RequireSystemAdmin.test.ts
Marc Mintel 6c07abe5e7
Some checks failed
Contract Testing / contract-snapshot (pull_request) Has been cancelled
Contract Testing / contract-tests (pull_request) Has been cancelled
view data fixes
2026-01-25 00:12:30 +01:00

41 lines
1.3 KiB
TypeScript

import { SetMetadata } from '@nestjs/common';
import { RequireSystemAdmin, REQUIRE_SYSTEM_ADMIN_METADATA_KEY } from './RequireSystemAdmin';
// Mock SetMetadata
vi.mock('@nestjs/common', () => ({
SetMetadata: vi.fn(() => (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => descriptor),
}));
describe('RequireSystemAdmin', () => {
it('should return a method decorator', () => {
const decorator = RequireSystemAdmin();
expect(typeof decorator).toBe('function');
});
it('should call SetMetadata with correct key and value', () => {
RequireSystemAdmin();
expect(SetMetadata).toHaveBeenCalledWith(REQUIRE_SYSTEM_ADMIN_METADATA_KEY, {
required: true,
});
});
it('should return a decorator that can be used as both method and class decorator', () => {
const decorator = RequireSystemAdmin();
// Test as method decorator
const mockTarget = {};
const mockPropertyKey = 'testMethod';
const mockDescriptor = { value: () => {} };
const result = decorator(mockTarget, mockPropertyKey, mockDescriptor);
// The decorator should return the descriptor (SetMetadata returns the descriptor)
expect(result).toBe(mockDescriptor);
});
it('should have correct metadata key', () => {
expect(REQUIRE_SYSTEM_ADMIN_METADATA_KEY).toBe('gridpilot:requireSystemAdmin');
});
});