createOrderPage.contract.test.mjs
4.4 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 { readFileSync } from 'node:fs'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
const pageSource = readFileSync(
fileURLToPath(new URL('../createOrder.js', import.meta.url)),
'utf8'
)
const submitSource = readFileSync(
fileURLToPath(new URL('../submitStrategy.js', import.meta.url)),
'utf8'
)
const routeSource = readFileSync(
fileURLToPath(new URL('../routeStrategy.js', import.meta.url)),
'utf8'
)
const secondStageServiceSources = [
'./services/orderValidation.helpers.js',
'./services/paymentSelection.helpers.js',
'./services/orderHydration.helpers.js',
'./services/goodsChooseEcho.workflow.js'
].map(relativePath =>
readFileSync(
fileURLToPath(new URL(`../${relativePath}`, import.meta.url)),
'utf8'
)
)
test('boutique create page contains no temporary console logging', () => {
assert.doesNotMatch(pageSource, /console\.log\s*\(/)
})
test('boutique create page removes the disabled wait-order polling path', () => {
assert.doesNotMatch(pageSource, /\bgetWaitOrder\s*\(/)
assert.doesNotMatch(pageSource, /\bwaitinputorder\s*\(/)
assert.doesNotMatch(pageSource, /\bwaitInputCount\b/)
})
test('boutique create page does not retain empty lifecycle handlers', () => {
assert.doesNotMatch(
pageSource,
/onPullDownRefresh\s*:\s*function\s*\(\)\s*\{\s*\}/
)
assert.doesNotMatch(
pageSource,
/onReachBottom\s*:\s*function\s*\(\)\s*\{\s*\}/
)
})
test('boutique create page delegates second-stage decisions while retaining compatibility methods', () => {
const contracts = [
['checkRequired', 'validateBoutiqueRequiredFields'],
['checkPhoneUseConfig', 'resolveConfiguredPhone'],
['setOrderObj', 'buildBoutiqueOrderHydration'],
['getChooseList', 'buildBoutiqueChooseList'],
['settingPayType', 'buildBoutiquePaymentSelectionPatch']
]
for (const [methodName, serviceName] of contracts) {
assert.match(pageSource, new RegExp(`\\b${methodName}\\s*\\(`))
assert.match(pageSource, new RegExp(`\\b${serviceName}\\s*\\(`))
}
assert.equal((pageSource.match(/\bcloseTips\s*\(/g) || []).length, 1)
assert.doesNotMatch(pageSource, /\bhandleSpecificationsEcho\s*\(/)
assert.doesNotMatch(pageSource, /\bresolveEchoMarketingMeta\s*\(/)
})
test('boutique second-stage modules keep wx effects and cross-package imports outside services', () => {
for (const source of secondStageServiceSources) {
assert.doesNotMatch(source, /\bsetData\s*\(/)
assert.doesNotMatch(source, /\bgetPageInstance\s*\(/)
assert.doesNotMatch(source, /\bwx\.\$router\b/)
assert.doesNotMatch(source, /packageEquity/)
}
assert.doesNotMatch(pageSource + submitSource + routeSource, /packageEquity/)
})
test('boutique create page uses ESM imports and route or submit strategies contain no temporary logs', () => {
assert.match(
pageSource,
/import timeUtil from '~\/utils\/timeFormat\/time-utils\.js'/
)
assert.doesNotMatch(pageSource, /\brequire\s*\(/)
assert.doesNotMatch(submitSource + routeSource, /console\.log\s*\(/)
})
test('boutique validation strategy preserves toast presentation while other messages stay modal', () => {
assert.match(
submitSource,
/function ValidationResult\(isValid, message, errorKey, presentation\)/
)
assert.match(
submitSource,
/new ValidationResult\(\s*false,\s*result\.message,\s*result\.errorKey,\s*result\.presentation\s*\)/
)
assert.match(
submitSource,
/validation\.presentation === ['"]toast['"][\s\S]*this\.page\.showToast\(validation\.message\)/
)
assert.match(
submitSource,
/else\s*\{[\s\S]*wx\.showModal\(\{[\s\S]*content:\s*validation\.message/
)
assert.match(
submitSource,
/if \(validation\.errorKey\)[\s\S]*this\.page\.handleRequiredError\(validation\.errorKey\)/
)
})
test('sales staff confirmation resets Coupon in setData callback while delivery does not', () => {
const start = pageSource.indexOf('onStaffPickerConfirm(e)')
const end = pageSource.indexOf('/**', start + 1)
const methodSource = pageSource.slice(start, end)
assert.notEqual(start, -1)
assert.match(
methodSource,
/this\.setData\([\s\S]*\(\) => \{[\s\S]*if \(mode === STAFF_MODE\.SALES\) \{[\s\S]*resetCouponComponent\(this\)/
)
assert.equal((methodSource.match(/resetCouponComponent\(this\)/g) || []).length, 1)
assert.doesNotMatch(
methodSource,
/mode === STAFF_MODE\.DELIVERY[\s\S]*resetCouponComponent\(this\)/
)
})