import 'reflect-metadata';
import { PERMISSION_KEY } from '../auth/decorators/permission.decorator';
import { ClassroomRentalsController } from './classroom-rentals.controller';

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

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