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

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

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