mapDetailResponse.spec.js
2.28 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
const { mapDetailResponse } = require("@/api/adapters/journalRecord/mapDetailResponse");
describe("mapDetailResponse", () => {
it("应保留接口返回的模板类型", () => {
expect(mapDetailResponse({ templateType: 2 }).templateType).toBe(2);
});
it("接口缺少模板类型时使用调用上下文", () => {
expect(mapDetailResponse({}, { templateType: 2 }).templateType).toBe(2);
});
it("路由中的单个品牌应归一化成品牌数组", () => {
expect(mapDetailResponse({}, { brandIds: "3454" }).brandIds).toEqual(["3454"]);
});
it("接口缺少场景码时应保留路由上下文", () => {
expect(mapDetailResponse({}, { baseSceneCode: "100101" }).baseSceneCode).toBe("100101");
});
it("详情应使用精确场景码识别延保", () => {
const detail = mapDetailResponse({
sceneType: 0,
baseSceneCode: 110201,
});
expect(detail.bizTypeName).toBe("延保");
});
it("详情应使用精确场景码识别二手车", () => {
const detail = mapDetailResponse({
sceneType: 7,
baseSceneCode: 120101,
});
expect(detail.bizType).toBe(7);
expect(detail.bizTypeName).toBe("二手车");
});
it("列表业务兜底应优先于旧 sceneType 映射", () => {
const detail = mapDetailResponse(
{ sceneType: "0" },
{ bizType: 9, bizTypeName: "延保" },
);
expect(detail.bizType).toBe(9);
expect(detail.bizTypeName).toBe("延保");
});
it("精确场景码应优先于列表业务兜底", () => {
const detail = mapDetailResponse(
{ sceneType: "1" },
{ baseSceneCode: 110201, bizType: 9, bizTypeName: "列表兜底" },
);
expect(detail.bizType).toBe("延保");
expect(detail.bizTypeName).toBe("延保");
});
it("详情接口明确业务字段应优先于精确场景和列表兜底", () => {
const detail = mapDetailResponse(
{
sceneType: "0",
baseSceneCode: 110201,
bizType: 7,
bizTypeName: "接口业务",
},
{ bizType: 9, bizTypeName: "列表兜底" },
);
expect(detail.bizType).toBe(7);
expect(detail.bizTypeName).toBe("接口业务");
});
it("空字符串列表兜底应视为缺失并继续使用旧 sceneType", () => {
const detail = mapDetailResponse(
{ sceneType: "1" },
{ bizType: "", bizTypeName: "" },
);
expect(detail.bizType).toBe(1);
expect(detail.bizTypeName).toBe("轻改");
});
});