import { Reflector } from '@nestjs/core';
import { PERMISSION_METADATA_KEY } from '../../common/auth/permission.decorator';
import { AuditController } from './audit.controller';

describe('AuditController', () => {
  it('requires audit:view for audit queries', () => {
    const metadata = new Reflector().get(PERMISSION_METADATA_KEY, AuditController.prototype.findAll);

    expect(metadata).toEqual({ permission: 'audit:view' });
  });

  it('delegates list query parameters to the audit service', async () => {
    const service = { query: jest.fn().mockResolvedValue([{ id: 'audit-1' }]) };
    const controller = new AuditController(service as any);

    await expect(controller.findAll({ actorId: 'm-8' })).resolves.toEqual([{ id: 'audit-1' }]);

    expect(service.query).toHaveBeenCalledWith({ actorId: 'm-8' });
  });
});
