orderSettingMerchantContext.test.mjs
2.47 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
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { register } from 'node:module'
import test from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
test('order settings use and cache the park store selected before low-price order creation', async () => {
const app = {
globalData: {
YQorderSetting: { marker: 'wrong-cache' },
YQorderSettingMerchantId: 999
}
}
const requests = []
globalThis.getApp = () => app
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
setStorageSync: () => {},
removeStorageSync: () => {},
$util: {
getUserInfo: () => ({
subLoginUser: { merchantId: 777, merchantName: '登录园区店' }
}),
showLoading: () => {},
hideLoading: () => {}
}
}
globalThis.__WORK_ORDER_MOCK_API__ = {
getMerchantRecordingSettings(params) {
requests.push(params)
return {
code: 0,
data: {
marker: 'selected-store-setting',
yqPhoneConfig: JSON.stringify([
{
yqMerchantId: 100,
shopMerchantPhoneList: [{ shopMerchantId: 201 }]
}
])
}
}
}
}
const { getYQorderInfo } = await import(
`../../../../store/index.js?selected-order-setting=${Date.now()}`
)
const result = await getYQorderInfo({
merchantId: 100,
merchantName: '已选园区店'
})
assert.deepEqual(requests, [
{ merchantId: 100, merchantName: '已选园区店' }
])
assert.equal(result.marker, 'selected-store-setting')
assert.deepEqual(result.yqPhoneConfig, [{ shopMerchantId: 201 }])
assert.equal(app.globalData.YQorderSettingMerchantId, 100)
assert.equal(app.globalData.YQorderSetting.marker, 'selected-store-setting')
})
test('createOrder passes the selected park store to the order-settings query', () => {
const source = readFileSync(new URL('../createOrder.js', import.meta.url), 'utf8')
assert.match(source, /const selectedYqMerchantId =\s*orderObj\.yqMerchantId \|\| orderObj\.sellerMerchantId/)
assert.match(source, /merchantId: selectedYqMerchantId/)
assert.match(source, /merchantName:\s*orderObj\.yqMerchantName \|\| orderObj\.sellerMerchantName/)
assert.match(source, /getYQorderInfo\(selectedYqMerchant\)/)
})