index.spec.js
2.57 KB
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
const mockRequest = jest.fn();
const mockRequestMethods = { POST: "POST", GET: "GET" };
jest.mock("@/api/request", () => mockRequest);
jest.mock("@/api/request.methods", () => mockRequestMethods);
const {
getList,
getMarketingPushStrategyDetailApi,
createStrategy,
updateStrategy,
statusStrategy,
deleteStrategy,
confirmStrategy,
recordsStrategy,
recordDetail,
getMetaData,
getMetaOptionsApi,
} = require("./index.js");
describe("marketingPushStrategy api/index.js", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("getList 应追加 list 方法名并走默认请求方式", async () => {
const params = { pageNo: 1 };
mockRequest.mockResolvedValue({ list: [] });
await getList(params);
expect(mockRequest).toHaveBeenCalledWith({
pageNo: 1,
method: "dj.api.smartcarlife.sop.strategy.list",
});
});
it("详情与创建更新相关接口应使用 post", async () => {
mockRequest.mockResolvedValue({});
await getMarketingPushStrategyDetailApi({ strategyId: 1 });
await createStrategy({ strategyName: "A" });
await updateStrategy({ strategyId: 1 });
await statusStrategy({ strategyId: 1, status: 1 });
await deleteStrategy({ strategyId: 1 });
await confirmStrategy({ strategyIds: [1] });
await recordsStrategy({ strategyId: 1 });
await recordDetail({ recordId: 1 });
await getMetaData({});
expect(mockRequest.mock.calls).toEqual([
[{ strategyId: 1, method: "dj.api.smartcarlife.sop.strategy.query" }, "post"],
[{ strategyName: "A", method: "dj.api.smartcarlife.sop.strategy.create" }, "post"],
[{ strategyId: 1, method: "dj.api.smartcarlife.sop.strategy.update" }, "post"],
[{ strategyId: 1, status: 1, method: "dj.api.smartcarlife.sop.strategy.status" }, "post"],
[{ strategyId: 1, method: "dj.api.smartcarlife.sop.strategy.delete" }, "post"],
[{ strategyIds: [1], method: "dj.api.smartcarlife.sop.strategy.confirm" }, "post"],
[{ strategyId: 1, method: "dj.api.smartcarlife.sop.strategy.records" }, "post"],
[{ recordId: 1, method: "dj.api.smartcarlife.sop.strategy.record.detail" }, "post"],
[{ method: "dj.api.smartcarlife.sop.strategy.meta" }, "post"],
]);
});
it("getMetaOptionsApi 应默认空对象并使用 RequestMethods.POST", async () => {
mockRequest.mockResolvedValue({});
await getMetaOptionsApi();
await getMetaOptionsApi({ bizType: 1 });
expect(mockRequest.mock.calls).toEqual([
[
{ method: "dj.api.smartcarlife.sop.strategy.meta" },
mockRequestMethods.POST,
],
[
{ bizType: 1, method: "dj.api.smartcarlife.sop.strategy.meta" },
mockRequestMethods.POST,
],
]);
});
});