Files
gridpilot.gg/apps/api/src/domain/auth/Public.test.ts
Marc Mintel fb1221701d
Some checks failed
Contract Testing / contract-tests (push) Failing after 6m7s
Contract Testing / contract-snapshot (push) Failing after 4m46s
add tests
2026-01-22 11:52:42 +01:00

41 lines
1.1 KiB
TypeScript

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