Files
gridpilot.gg/apps/api/src/domain/auth/RequireAuthenticatedUser.test.ts
Marc Mintel 9ac74f5046
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
code quality
2026-01-26 17:22:01 +01:00

41 lines
1.4 KiB
TypeScript

import { SetMetadata } from '@nestjs/common';
import { RequireAuthenticatedUser, REQUIRE_AUTHENTICATED_USER_METADATA_KEY } from './RequireAuthenticatedUser';
// Mock SetMetadata
vi.mock('@nestjs/common', () => ({
SetMetadata: vi.fn(() => (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => descriptor),
}));
describe('RequireAuthenticatedUser', () => {
it('should return a method decorator', () => {
const decorator = RequireAuthenticatedUser();
expect(typeof decorator).toBe('function');
});
it('should call SetMetadata with correct key and value', () => {
RequireAuthenticatedUser();
expect(SetMetadata).toHaveBeenCalledWith(REQUIRE_AUTHENTICATED_USER_METADATA_KEY, {
required: true,
});
});
it('should return a decorator that can be used as both method and class decorator', () => {
const decorator = RequireAuthenticatedUser();
// 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(REQUIRE_AUTHENTICATED_USER_METADATA_KEY).toBe('gridpilot:requireAuthenticatedUser');
});
});