preflight.test.mjs
7.21 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { PREFLIGHT_METHODS, runPreflight } from './preflight.mjs'
const context = {
park: { id: 11, name: '目标园区' },
store: { id: 22, name: '目标门店' },
user: { uuid: 'staff-1', name: '测试员工' },
sceneType: 1
}
Object.defineProperty(context, 'sessionId', {
value: 'session-private',
enumerable: false
})
const goods = [
{
goodsFlag: 1,
goods: {
merchantGoodsId: 101,
upgradeGoodsId: 1001,
goodsName: '普通商品一',
sellPrice: 100,
imageUrl: 'https://image.test/goods-1.png'
}
},
{
goodsFlag: 1,
goods: {
merchantGoodsId: 102,
upgradeGoodsId: 1002,
goodsName: '普通商品二',
sellPrice: 200
}
},
{ goodsFlag: 2, multipleSpecificationsGoods: { merchantGoodsId: 103 } },
{ goodsFlag: 3, packageGoods: { packageGoodsId: 104, goodsList: [] } }
]
const createClient = (overrides = {}) => ({
calls: [],
async post(method, payload) {
this.calls.push({ method, payload })
if (overrides[method]) return overrides[method]
if (method === PREFLIGHT_METHODS.employees) {
return {
code: 0,
data: [{ uuid: 'staff-1', userId: 501, name: '测试员工', merchantId: 11 }]
}
}
if (method === PREFLIGHT_METHODS.scenes) {
return {
code: 0,
data: [
{
id: 81,
name: '精品升级测试场景',
baseSceneCode: 'PREMIUM_TEST',
sceneType: 1,
status: 1
}
]
}
}
if (method === PREFLIGHT_METHODS.goods) return { code: 0, data: goods }
if (method === PREFLIGHT_METHODS.merchantCoupons) {
return {
code: 0,
data: [
{
id: 401,
merchantId: 22,
couponName: '测试礼券',
merchantCouponCode: 'COUPON-001-SUFFIX',
couponInfo: { couponType: 1 }
}
]
}
}
if (method === PREFLIGHT_METHODS.subShops) {
return {
code: 0,
data: [
{
subMerchantId: 301,
subMerchantName: context.store.name
}
]
}
}
if (method === PREFLIGHT_METHODS.technicians) {
return {
code: 0,
data: [
{
uuid: 'tech-1',
userId: 601,
name: '测试技师',
staffPhone: 'masked-phone'
}
]
}
}
if (method === PREFLIGHT_METHODS.serviceItems) {
return {
code: 0,
data: [
{
categoryName: '装饰',
itemName: '安装',
serviceItemList: [
{
id: 701,
serviceItemsName: '精品安装',
categoryId: 801,
itemsConfigName: '标准安装',
materialStandard: '1套',
timeStandard: 30,
serviceCost: 20
}
]
}
]
}
}
if (method === PREFLIGHT_METHODS.filmRolls) {
return { code: 0, data: ['ROLL-TEST-1'] }
}
throw new Error(`Unexpected fake method: ${method}`)
}
})
describe('order lifecycle capability preflight', () => {
it('IT-OL-PREFLIGHT-001: ready report exposes required resources and optional catalog types', async () => {
const client = createClient()
const report = await runPreflight(client, context)
assert.equal(report.ok, true)
assert.deepEqual(report.missing, [])
assert.equal(report.resources.ordinaryGoods.length, 2)
assert.equal(report.resources.baseScene.baseSceneCode, 'PREMIUM_TEST')
assert.equal(report.resources.merchantCoupon.id, 401)
assert.equal(report.resources.subShop.subMerchantId, 301)
assert.equal(report.resources.packageGoods.goodsFlag, 3)
assert.equal(report.resources.multiSpecGoods.goodsFlag, 2)
assert.equal(report.resources.employee.id, 501)
assert.equal(report.resources.technician.id, 601)
assert.equal(report.resources.technician.staffPhone, 'masked-phone')
assert.equal(report.resources.serviceItem.id, 701)
assert.equal(report.resources.serviceItem.name, '精品安装')
assert.equal(report.resources.serviceItem.categoryId, 801)
assert.equal(report.resources.inventory.mode, 'film-roll')
assert.equal(
report.resources.constructionPictureUrl,
'https://image.test/goods-1.png'
)
})
it('IT-OL-PREFLIGHT-002: missing requirements name query method and next field', async () => {
const client = createClient({
[PREFLIGHT_METHODS.goods]: { code: 0, data: [] },
[PREFLIGHT_METHODS.scenes]: { code: 0, data: [] },
[PREFLIGHT_METHODS.merchantCoupons]: { code: 0, data: [] },
[PREFLIGHT_METHODS.subShops]: { code: 0, data: [] },
[PREFLIGHT_METHODS.technicians]: { code: 0, data: [] },
[PREFLIGHT_METHODS.serviceItems]: { code: 0, data: [] }
})
const report = await runPreflight(client, context)
assert.equal(report.ok, false)
assert.ok(report.missing.some(item => item.resource === 'ordinaryGoods'))
assert.ok(report.missing.some(item => item.resource === 'baseScene'))
assert.ok(report.missing.some(item => item.resource === 'merchantCoupon'))
assert.ok(report.missing.some(item => item.resource === 'subShop'))
assert.ok(report.missing.some(item => item.resource === 'technician'))
assert.ok(report.missing.some(item => item.resource === 'serviceItem'))
for (const item of report.missing) {
assert.ok(item.method)
assert.ok(item.neededField)
}
})
it('IT-OL-PREFLIGHT-003: package and multi-spec goods are optional diagnostics', async () => {
const client = createClient({
[PREFLIGHT_METHODS.goods]: { code: 0, data: goods.slice(0, 2) }
})
const report = await runPreflight(client, context)
assert.equal(report.ok, true)
assert.equal(report.resources.packageGoods, null)
assert.equal(report.resources.multiSpecGoods, null)
assert.ok(!report.missing.some(item => item.resource === 'packageGoods'))
assert.ok(!report.missing.some(item => item.resource === 'multiSpecGoods'))
})
it('IT-OL-PREFLIGHT-004: business query failure is diagnostic and contains no session', async () => {
const client = createClient({
[PREFLIGHT_METHODS.employees]: {
code: -1,
message: 'session-private',
data: null
}
})
const report = await runPreflight(client, context)
assert.equal(report.ok, false)
assert.ok(report.missing.some(item => item.resource === 'employee'))
assert.ok(report.diagnostics.some(item => item.code === -1))
assert.doesNotMatch(JSON.stringify(report), /session-private/)
})
it('IT-OL-PREFLIGHT-005: technician aliases match the construction picker response', async () => {
const client = createClient({
[PREFLIGHT_METHODS.technicians]: {
code: 0,
data: [
{
userId: 602,
technicianUuid: 'tech-alias-uuid',
staffName: 'alias technician'
}
]
}
})
const report = await runPreflight(client, context)
assert.equal(report.resources.technician.uuid, 'tech-alias-uuid')
assert.equal(report.resources.technician.name, 'alias technician')
})
})