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

describe('DepositsController purge route', () => {
  it('requires deposit:purge on permanent delete route', () => {
    expect(Reflect.getMetadata(PERMISSION_KEY, DepositsController.prototype.purge)).toEqual([
      'deposit:purge',
    ]);
  });

  it('writes permanent delete audit logs', async () => {
    const service = { purge: jest.fn().mockResolvedValue({ message: '已永久删除押金（不可恢复）' }) };
    const log = jest.fn().mockResolvedValue(undefined);
    const controller = new DepositsController(
      service as never,
      { log } 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 }),
    );
  });
});
