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

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

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