刘光辉
6 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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');
  });
});