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
| import { beforeEach, describe, expect, it, vi } from 'vitest';
|
| const requestMocks = vi.hoisted(() => ({
| post: vi.fn(),
| put: vi.fn(),
| }));
|
| vi.mock('#/api/request', () => ({
| defHttp: {
| delete: vi.fn(),
| get: vi.fn(),
| post: requestMocks.post,
| put: requestMocks.put,
| },
| }));
|
| import { createModel, updateModel } from './visualDev';
|
| describe('online form submit API audit header', () => {
| beforeEach(() => vi.clearAllMocks());
|
| it.each([
| ['createModel', createModel, requestMocks.post, { data: JSON.stringify({ biz_sign: '839875756384423365' }) }],
| ['updateModel', updateModel, requestMocks.put, { id: '1', data: JSON.stringify({ biz_sign: '839875756384423365' }) }],
| ])('%s sends X-Audit-Biz-Sign', (_name, submit, request, payload) => {
| submit('model-1', payload as any);
|
| expect(request).toHaveBeenCalledWith(
| expect.objectContaining({
| headers: { 'X-Audit-Biz-Sign': '839875756384423365' },
| }),
| );
| });
|
| it('uses the event correlation id when an online form has no biz_sign', () => {
| const correlationId = '0123456789abcdef0123456789abcdef';
|
| createModel('model-1', { data: '{}' }, correlationId);
|
| expect(requestMocks.post).toHaveBeenCalledWith(expect.objectContaining({ headers: { 'X-Audit-Biz-Sign': correlationId } }));
| });
| });
|
|