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

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

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