import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { folderAuditOperationQuery } from '../folderAuditOperationQuery';
|
|
const apiMocks = vi.hoisted(() => ({
|
detail: vi.fn(),
|
page: vi.fn(),
|
timeline: vi.fn(),
|
}));
|
|
vi.mock('#/api/x/audit/events', () => ({
|
getDmsFolderAuditDetail: apiMocks.detail,
|
getDmsFolderAuditPage: apiMocks.page,
|
getDmsFolderAuditTimeline: apiMocks.timeline,
|
}));
|
|
describe('dms folder audit query boundary', () => {
|
beforeEach(() => {
|
vi.clearAllMocks();
|
});
|
|
it('normalizes the dedicated folder audit page', async () => {
|
apiMocks.page.mockResolvedValue({
|
data: {
|
list: [
|
{
|
id: 11,
|
operationId: 'folder-op-1',
|
bizType: 'DMS_FOLDER',
|
folderName: '检验报告',
|
parentFolderName: '质量管理',
|
diffCount: 2,
|
subEvents: [{ id: 12, eventType: 'E_SIGNATURE', signatureRole: 'PRIMARY', sourceLayer: 3 }],
|
},
|
],
|
pagination: { currentPage: 1, pageSize: 20, total: 1 },
|
},
|
});
|
|
const page = await folderAuditOperationQuery.page({ currentPage: 1, pageSize: 20, signed: true });
|
|
expect(apiMocks.page).toHaveBeenCalledWith({ currentPage: 1, pageSize: 20, signed: true });
|
expect(page.list[0]?.correlationKey).toBe('folder-op-1');
|
expect(page.list[0]?.folderName).toBe('检验报告');
|
expect(page.list[0]?.parentFolderName).toBe('质量管理');
|
expect(page.list[0]?.signed).toBeUndefined();
|
expect(page.list[0]?.eventIds).toEqual([11, 12]);
|
});
|
|
it('keeps an unsigned folder timeline free of electronic-signature content', async () => {
|
apiMocks.timeline.mockResolvedValue({
|
data: [{ id: 32, operationId: 'folder-op-unsigned', bizType: 'DMS_FOLDER', eventType: 'DATA_CHANGE', sourceLayer: 3, signed: false }],
|
});
|
|
const timeline = await folderAuditOperationQuery.timeline('folder-32');
|
|
expect(timeline[0]?.sourceSummary).toBe('业务埋点');
|
expect(timeline[0]?.sourceSummary).not.toContain('电子签名');
|
});
|
|
it('uses one scoped detail response for the business event and signature switches', async () => {
|
apiMocks.detail.mockResolvedValue({
|
data: {
|
business: {
|
id: 21,
|
bizType: 'DMS_FOLDER',
|
fieldDiffs: '[{"field":"name","oldData":"旧目录","newData":"新目录"}]',
|
},
|
signatures: [
|
{ id: 22, eventType: 'E_SIGNATURE', fieldDiffs: null, signatureRole: 'PRIMARY' },
|
{ id: 23, eventType: 'E_SIGNATURE', fieldDiffs: null, signatureRole: 'REVIEW' },
|
],
|
},
|
});
|
|
const business = await folderAuditOperationQuery.detail(21);
|
const primary = await folderAuditOperationQuery.detail(22);
|
const review = await folderAuditOperationQuery.detail(23);
|
|
expect(apiMocks.detail).toHaveBeenCalledTimes(1);
|
expect(business.fieldDiffList).toHaveLength(1);
|
expect(primary.signatureRole).toBe('PRIMARY');
|
expect(review.signatureRole).toBe('REVIEW');
|
});
|
|
it('loads the folder timeline through the dedicated endpoint', async () => {
|
apiMocks.timeline.mockResolvedValue({ data: [{ id: 31, operationId: 'folder-op-3', bizType: 'DMS_FOLDER' }] });
|
|
const timeline = await folderAuditOperationQuery.timeline('folder-31');
|
|
expect(apiMocks.timeline).toHaveBeenCalledWith('folder-31');
|
expect(timeline[0]?.correlationKey).toBe('folder-op-3');
|
});
|
});
|