paymentSelection.helpers.test.mjs
5.3 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
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { buildBoutiquePaymentSelectionPatch } from "../services/paymentSelection.helpers.js";
function createContext(overrides = {}) {
return {
configPayTypeList: [
{ name: "门店收款", value: 2 },
{ name: "微信支付", value: 1 },
{ name: "POS机", value: 3 },
{ name: "嘀加收款", value: 5 },
],
isErrorOrder: false,
switchVlaue: "",
selectOutTradeNoArr: [],
paymentMethod: "",
isAppointment: false,
orderObj: {
selectPayType: "",
payeeType: "",
isNewOrder: "Y",
},
...overrides,
};
}
function assertPatchWithoutMutation(context, expected, message) {
const snapshot = structuredClone(context);
assert.deepEqual(buildBoutiquePaymentSelectionPatch(context), expected, message);
assert.deepEqual(context, snapshot, `${message || "payment selection"}: input mutated`);
}
const djPayList = [
{ name: "微信支付", value: 1 },
{ name: "POS机", value: 3 },
{ name: "对公转账", value: 6 },
{ name: "其它收款", value: 7 },
];
const merchantPayList = [{ name: "门店收款", value: 2 }];
describe("paymentSelection.helpers", () => {
it("IT-WO-PAYMENT-001: payment guide entries produce one complete and internally consistent patch", () => {
const cases = [
{
name: "online guide",
context: createContext({ paymentMethod: 1 }),
expected: {
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": 1,
"orderObj.payeeType": 0,
},
},
{
name: "shop collection guide",
context: createContext({ paymentMethod: 3 }),
expected: {
djPayList,
merchantPayList,
showPayList: merchantPayList,
"orderObj.selectPayType": 2,
"orderObj.payeeType": 1,
},
},
{
name: "bank transfer guide",
context: createContext({ paymentMethod: 4 }),
expected: {
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": 6,
"orderObj.payeeType": 0,
},
},
{
name: "other collection guide",
context: createContext({ paymentMethod: 6 }),
expected: {
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": 7,
"orderObj.payeeType": 0,
},
},
];
for (const { name, context, expected } of cases) {
assertPatchWithoutMutation(context, expected, name);
}
});
it("IT-WO-PAYMENT-002: correction and supplemental records retain the existing transaction-count matrix", () => {
const cases = [
{
context: createContext({ isErrorOrder: true }),
selected: 5,
},
{
context: createContext({
switchVlaue: 1,
selectOutTradeNoArr: [{ outTradeNo: "trade-1" }],
}),
selected: 1,
},
{
context: createContext({
switchVlaue: 1,
selectOutTradeNoArr: [{ outTradeNo: "trade-1" }, { outTradeNo: "trade-2" }],
}),
selected: 5,
},
];
for (const { context, selected } of cases) {
assertPatchWithoutMutation(context, {
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": selected,
"orderObj.payeeType": 0,
});
}
});
it("IT-WO-PAYMENT-003: a historical shop payment keeps the shop payee and list", () => {
assertPatchWithoutMutation(
createContext({
orderObj: { selectPayType: 2, payeeType: 0, isNewOrder: "N" },
}),
{
djPayList,
merchantPayList,
showPayList: merchantPayList,
"orderObj.selectPayType": 2,
"orderObj.payeeType": 1,
},
);
});
it("IT-WO-PAYMENT-004: a new order with no saved method selects the first configured online method", () => {
assertPatchWithoutMutation(createContext(), {
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": 1,
"orderObj.payeeType": 0,
});
});
it("IT-WO-PAYMENT-005: a historical order with no method falls back to shop collection", () => {
assertPatchWithoutMutation(
createContext({
orderObj: { selectPayType: "", payeeType: "", isNewOrder: "N" },
}),
{
djPayList,
merchantPayList,
showPayList: merchantPayList,
"orderObj.selectPayType": 2,
"orderObj.payeeType": 1,
},
);
});
it("IT-WO-PAYMENT-006: a saved payment that is no longer selectable is cleared atomically", () => {
assertPatchWithoutMutation(
createContext({
orderObj: { selectPayType: 4, payeeType: 0, isNewOrder: "N" },
}),
{
djPayList,
merchantPayList,
showPayList: [],
"orderObj.selectPayType": "",
"orderObj.payeeType": "",
},
);
});
it("IT-WO-PAYMENT-007: readonly payment entry preserves a saved shop selection in one complete patch", () => {
assertPatchWithoutMutation(
createContext({
paymentMethod: 5,
orderObj: { selectPayType: 2, payeeType: 1, isNewOrder: "N" },
}),
{
djPayList,
merchantPayList,
showPayList: merchantPayList,
"orderObj.selectPayType": 2,
"orderObj.payeeType": 1,
},
);
});
it("IT-WO-PAYMENT-008: readonly payment entry preserves string-valued DJ fields without stale lists", () => {
assertPatchWithoutMutation(
createContext({
paymentMethod: 5,
orderObj: { selectPayType: "6", payeeType: "0", isNewOrder: "N" },
}),
{
djPayList,
merchantPayList,
showPayList: djPayList,
"orderObj.selectPayType": "6",
"orderObj.payeeType": "0",
},
);
});
});