刘光辉
3 小时以前 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
import { beforeEach, describe, expect, it, vi } from 'vitest';
 
const requestMocks = vi.hoisted(() => ({
  get: vi.fn(),
  post: vi.fn(),
}));
 
vi.mock('#/api/request', () => ({
  defHttp: {
    delete: vi.fn(),
    get: requestMocks.get,
    post: requestMocks.post,
    put: vi.fn(),
  },
}));
 
// eslint-disable-next-line import/first -- request module must be mocked before loading the API wrapper.
import { confirmRemoveMissing, getTemplateCategoryTree, getTemplateDirectory, switchCurrentTemplate } from './templates';
 
describe('eln template API', () => {
  beforeEach(() => vi.clearAllMocks());
 
  it('通过数据接口以空 currentId 加载分类树', () => {
    getTemplateCategoryTree();
 
    expect(requestMocks.post).toHaveBeenCalledWith({
      data: { paramList: [{ field: 'currentId', sourceType: 3 }] },
      url: '/api/system/DataInterface/855428577502430981/Actions/Preview',
    });
  });
 
  it('按模板编号加载目录和可空生效版本摘要', () => {
    const query = { currentPage: 2, keyword: '无菌', pageSize: 50 };
 
    getTemplateDirectory(query);
 
    expect(requestMocks.get).toHaveBeenCalledWith({
      data: query,
      url: '/api/eln/templateCatalog/directory',
    });
  });
 
  it('uses lowerCamelCase lifecycle paths', () => {
    switchCurrentTemplate('TPL-1', 'template-1', 'switch');
    confirmRemoveMissing('binding-1', {
      clientReportedMissing: true,
      expectedVersion: 1,
      operationCode: 'remove-1',
      reason: 'missing',
    });
 
    expect(requestMocks.post.mock.calls.map(([request]) => request.url)).toEqual([
      '/api/eln/templateCatalog/currentVersion',
      '/api/eln/templateCatalog/bindings/binding-1/confirmRemoveMissing',
    ]);
  });
});