import 'reflect-metadata';
import { PERMISSION_KEY } from '../auth/decorators/permission.decorator';
import { BillsController } from './bills.controller';

describe('BillsController purge routes', () => {
  it('requires bill:purge on permanent delete routes', () => {
    expect(Reflect.getMetadata(PERMISSION_KEY, BillsController.prototype.purge)).toEqual([
      'bill:purge',
    ]);
    expect(Reflect.getMetadata(PERMISSION_KEY, BillsController.prototype.batchPurge)).toEqual([
      'bill:purge',
    ]);
  });

  it('writes permanent delete audit logs', async () => {
    const service = { purge: jest.fn().mockResolvedValue({ message: '已永久删除账单（不可恢复）' }) };
    const log = jest.fn().mockResolvedValue(undefined);
    const controller = new BillsController(
      service as never,
      {} as never,
      { log } as never,
      {} as never,
      {} as never,
      {} as never,
    );
    const req = { user: { id: 1, username: 'admin' }, ip: '127.0.0.1', headers: {} };
    await controller.purge(1, req);
    expect(service.purge).toHaveBeenCalledWith(1);
    expect(log).toHaveBeenCalledWith(
      expect.objectContaining({ module: '账单管理', action: '永久删除账单', targetId: 1 }),
    );
  });
});
