orderHydration.helpers.test.mjs
7.65 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { buildBoutiqueOrderHydration } from "../services/orderHydration.helpers.js";
const orderTypeList = [
{ text: "正常订单", value: 1 },
{ text: "打折策略", value: 2 },
{ text: "内部结算", value: 6 },
];
function buildWithoutMutation(input) {
const snapshot = structuredClone(input);
const result = buildBoutiqueOrderHydration(input);
assert.deepEqual(input, snapshot);
return result;
}
describe("orderHydration.helpers", () => {
it("IT-WO-HYDRATION-001: a new order keeps the previously selected scene and applies customer defaults", () => {
const result = buildWithoutMutation({
options: {
merchantId: "merchant-new",
merchantName: "新门店",
employeeName: "销售顾问",
customer: {
customerName: "张三",
customerPhone: "13800138000",
},
},
previousOrderObj: {
baseSceneCode: "scene-selected",
baseSceneName: "已选场景",
sceneType: 1,
},
orderTypeList,
isErrorOrder: false,
associateOrderType: false,
merchantBrands: [],
});
assert.deepEqual(result, {
orderObj: {
merchantId: "merchant-new",
merchantName: "新门店",
employeeName: "销售顾问",
customer: {
customerName: "张三",
customerPhone: "13800138000",
customerSex: 1,
experienceFlag: "N",
salesType: 0,
},
baseSceneCode: "scene-selected",
baseSceneName: "已选场景",
sceneType: 1,
djOrderType: 1,
},
patch: {
currentWordNumber: 0,
orderTypeName: "正常订单",
customerTagsText: "",
showCustomerTags: true,
showActualDeliveryDate: false,
first: true,
flag: true,
isErrorOrder: false,
associateOrderType: false,
isAppointment: false,
},
effects: [],
});
});
it("IT-WO-HYDRATION-002: an edited order cleans null fields, converts numeric fields and echoes its coupon", () => {
const result = buildWithoutMutation({
options: {
id: "order-id-1",
orderCode: "DJ-20260908-1",
merchantId: "merchant-edit",
orderType: "2",
selectPayType: "1",
payeeType: "0",
orderSource: "3",
discountType: "3",
remark: "编辑备注",
ignoredRootField: null,
customer: {
customerName: "李四",
customerPhone: "13900139000",
customerSex: 2,
experienceFlag: "Y",
salesType: 1,
customerTags: "1,3",
ignoredCustomerField: null,
},
customerCoupon: {
id: "coupon-record-1",
couponName: "精品满减券",
customerCouponCode: "COUPON-88-SUFFIX",
ignoredCouponField: null,
},
},
previousOrderObj: {},
orderTypeList,
isErrorOrder: false,
associateOrderType: false,
merchantBrands: [],
});
assert.deepEqual(result, {
orderObj: {
id: "order-id-1",
orderCode: "DJ-20260908-1",
merchantId: "merchant-edit",
orderType: "2",
selectPayType: 1,
payeeType: 0,
orderSource: 3,
discountType: 3,
remark: "编辑备注",
customer: {
customerName: "李四",
customerPhone: "13900139000",
customerSex: 2,
experienceFlag: "Y",
salesType: 1,
customerTags: "1,3",
},
customerCoupon: {
id: "coupon-record-1",
couponName: "精品满减券",
customerCouponCode: "COUPON-88-SUFFIX",
},
djOrderType: 2,
couponName: "精品满减券",
customerCouponCode: "COUPON",
customerCouponId: "coupon-record-1",
},
patch: {
currentWordNumber: 4,
orderTypeName: "打折策略",
customerTagsText: "已触客/已交付引荐",
showCustomerTags: true,
showActualDeliveryDate: false,
first: true,
flag: true,
isErrorOrder: false,
associateOrderType: false,
isAppointment: false,
},
effects: [],
});
});
it("IT-WO-HYDRATION-003: a reorder preserves its explicit reorder markers and numeric payment snapshot", () => {
const result = buildWithoutMutation({
options: {
againOrder: true,
resetOrder: true,
merchantId: "merchant-reorder",
orderSource: "4",
selectPayType: "3",
payeeType: "0",
djOrderType: "6",
discountType: "3",
customer: {
customerName: "王五",
customerPhone: "13700137000",
customerSex: 1,
experienceFlag: "N",
salesType: 2,
},
},
previousOrderObj: {},
orderTypeList,
isErrorOrder: false,
associateOrderType: false,
merchantBrands: [],
});
assert.deepEqual(result, {
orderObj: {
againOrder: true,
resetOrder: true,
merchantId: "merchant-reorder",
orderSource: 4,
selectPayType: 3,
payeeType: 0,
djOrderType: 6,
discountType: 3,
customer: {
customerName: "王五",
customerPhone: "13700137000",
customerSex: 1,
experienceFlag: "N",
salesType: 2,
},
},
patch: {
currentWordNumber: 0,
orderTypeName: "内部结算",
customerTagsText: "",
showCustomerTags: false,
showActualDeliveryDate: false,
first: true,
flag: true,
isErrorOrder: false,
associateOrderType: false,
isAppointment: false,
},
effects: [],
});
});
it("IT-WO-HYDRATION-004: a correction forces DJ collection and describes both page-only effects", () => {
const result = buildWithoutMutation({
options: {
associateOrderCode: "WRONG-ORDER-1",
merchantId: "merchant-correction",
selectPayType: 2,
payeeType: 1,
customer: {
customerName: "赵六",
customerPhone: "13600136000",
customerSex: 1,
experienceFlag: "N",
salesType: 0,
},
},
previousOrderObj: {},
orderTypeList,
isErrorOrder: false,
associateOrderType: false,
merchantBrands: [],
});
assert.deepEqual(result, {
orderObj: {
associateOrderCode: "WRONG-ORDER-1",
merchantId: "merchant-correction",
selectPayType: 5,
payeeType: 0,
customer: {
customerName: "赵六",
customerPhone: "13600136000",
customerSex: 1,
experienceFlag: "N",
salesType: 0,
},
djOrderType: 1,
},
patch: {
currentWordNumber: 0,
orderTypeName: "正常订单",
customerTagsText: "",
showCustomerTags: true,
showActualDeliveryDate: false,
first: true,
flag: true,
isErrorOrder: true,
associateOrderType: false,
isAppointment: false,
},
effects: [
{ type: "setNavigationBarTitle", title: "修正订单" },
{
type: "enableAlertBeforeUnload",
title: "提示",
message: "您需完成正确工单的信息录入",
},
],
});
});
it("IT-WO-HYDRATION-005: an appointment uses its YQ merchant as seller merchant", () => {
const result = buildWithoutMutation({
options: {
isAppointment: true,
yqMerchantId: "yq-merchant-9",
merchantId: "merchant-appointment",
sellerMerchantId: "stale-seller-merchant",
customer: {
customerName: "钱七",
customerPhone: "13500135000",
customerSex: 1,
experienceFlag: "N",
salesType: 3,
},
},
previousOrderObj: {},
orderTypeList,
isErrorOrder: false,
associateOrderType: false,
merchantBrands: [],
});
assert.deepEqual(result, {
orderObj: {
isAppointment: true,
yqMerchantId: "yq-merchant-9",
merchantId: "merchant-appointment",
sellerMerchantId: "yq-merchant-9",
customer: {
customerName: "钱七",
customerPhone: "13500135000",
customerSex: 1,
experienceFlag: "N",
salesType: 3,
},
djOrderType: 1,
},
patch: {
currentWordNumber: 0,
orderTypeName: "正常订单",
customerTagsText: "",
showCustomerTags: true,
showActualDeliveryDate: false,
first: true,
flag: true,
isErrorOrder: false,
associateOrderType: false,
isAppointment: true,
},
effects: [],
});
});
});