feat: 重构各业务模块管理页面与服务
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import 'reflect-metadata';
|
||||
import { PERMISSION_KEY } from '../auth/decorators/permission.decorator';
|
||||
import { StudentsController } from './students.controller';
|
||||
|
||||
describe('StudentsController purge routes', () => {
|
||||
it('requires student:purge on permanent delete routes', () => {
|
||||
expect(Reflect.getMetadata(PERMISSION_KEY, StudentsController.prototype.purge)).toEqual([
|
||||
'student:purge',
|
||||
]);
|
||||
expect(
|
||||
Reflect.getMetadata(PERMISSION_KEY, StudentsController.prototype.batchPurge),
|
||||
).toEqual(['student:purge']);
|
||||
});
|
||||
|
||||
it('writes permanent delete audit logs', async () => {
|
||||
const service = { purge: jest.fn().mockResolvedValue({ message: '已永久删除学生(不可恢复)' }) };
|
||||
const log = jest.fn().mockResolvedValue(undefined);
|
||||
const controller = new StudentsController(
|
||||
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 }),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user