customerProfileOnlyImport.integration.test.mjs
3.9 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
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
async function loadPageConfig() {
let pageConfig
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
getUserInfo: () => ({}),
showLoading: () => {},
hideLoading: () => {}
}
}
await import(`../createOrder.js?customer-only=${Date.now()}-${Math.random()}`)
return pageConfig
}
function createPage(pageConfig, lowPriceFlag) {
const currentGoods = [{ goodsCode: 'CURRENT' }]
let profileEchoCustomerId
let routeCount = 0
const page = {
data: {
...pageConfig.data,
customerInfoBox: true,
goodsList: currentGoods,
orderObj: {
...pageConfig.data.orderObj,
lowPriceFlag,
merchantId: 100,
selectPayType: 3,
payeeType: 1,
remark: '旧客户备注',
subOrderList: currentGoods,
customer: { customerId: 1, customerName: '旧客户' }
}
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
async echoCustomerProfileIfNeeded(detail) {
profileEchoCustomerId = detail?.customer?.customerId
},
async onRoute(detail) {
routeCount += 1
this.data.orderObj = { ...detail }
await this.echoCustomerProfileIfNeeded(detail)
},
settingPayType() {}
}
return {
currentGoods,
page,
getProfileEchoCustomerId: () => profileEchoCustomerId,
getRouteCount: () => routeCount
}
}
const selectedRecord = {
selectPayType: 5,
payeeType: 0,
remark: '新客户备注',
subOrderList: [{ goodsCode: 'HISTORY' }],
packageGoodsList: [{ packageCode: 'HISTORY-PKG' }],
customer: {
customerId: 2,
customerName: '新客户',
customerPhone: '13800000000'
}
}
describe('createOrder customer profile import', () => {
it('low-price profile selection keeps current goods and payment fields', async () => {
const pageConfig = await loadPageConfig()
const context = createPage(pageConfig, 1)
await pageConfig.chooseCustomerInfo.call(context.page, {
detail: structuredClone(selectedRecord)
})
assert.equal(context.page.data.orderObj.customer.customerId, 2)
assert.equal(context.page.data.orderObj.customer.customerName, '新客户')
assert.equal(context.page.data.orderObj.customer.customerSex, 1)
assert.equal(context.page.data.orderObj.customer.experienceFlag, 'N')
assert.equal(context.page.data.orderObj.customer.salesType, 0)
assert.equal(context.page.data.orderObj.remark, '新客户备注')
assert.equal(context.page.data.currentWordNumber, 5)
assert.equal(context.page.data.orderObj.selectPayType, 3)
assert.equal(context.page.data.orderObj.payeeType, 1)
assert.deepEqual(context.page.data.orderObj.subOrderList, [
{ goodsCode: 'CURRENT' }
])
assert.equal(context.page.data.orderObj.packageGoodsList, undefined)
assert.equal(context.page.data.goodsList, context.currentGoods)
assert.equal(context.page.data.customerInfoBox, false)
assert.equal(context.getProfileEchoCustomerId(), 2)
assert.equal(context.getRouteCount(), 0)
})
it('normal-order profile selection keeps the existing order routing path', async () => {
const pageConfig = await loadPageConfig()
const context = createPage(pageConfig, 0)
await pageConfig.chooseCustomerInfo.call(context.page, {
detail: structuredClone(selectedRecord)
})
assert.equal(context.getRouteCount(), 1)
assert.equal(context.page.data.orderObj.customer.customerId, 2)
})
})