import { describe, it, expect } from 'vitest';
import { Roles, ROLES_KEY } from '../decorators/roles.decorator';

describe('Roles Decorator', () => {
  it('exports ROLES_KEY constant', () => {
    expect(ROLES_KEY).toBe('roles');
  });

  it('returns a decorator function', () => {
    const decorator = Roles('ADMIN' as any);
    expect(typeof decorator).toBe('function');
  });

  it('applies metadata with single role', () => {
    const decorator = Roles('ADMIN' as any);
    // SetMetadata returns a decorator that sets Reflect metadata
    // We test by applying it to a test class
    @decorator
    class TestClass {}

    const metadata = Reflect.getMetadata(ROLES_KEY, TestClass);
    expect(metadata).toEqual(['ADMIN']);
  });

  it('applies metadata with multiple roles', () => {
    const decorator = Roles('ADMIN' as any, 'MODERATOR' as any);

    @decorator
    class TestClass {}

    const metadata = Reflect.getMetadata(ROLES_KEY, TestClass);
    expect(metadata).toEqual(['ADMIN', 'MODERATOR']);
  });

  it('applies metadata with no roles', () => {
    const decorator = Roles();

    @decorator
    class TestClass {}

    const metadata = Reflect.getMetadata(ROLES_KEY, TestClass);
    expect(metadata).toEqual([]);
  });
});
