41 lines
1.1 KiB
TypeScript
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');
|
|
});
|
|
});
|