createOrderRoute.contract.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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../')
const appConfig = JSON.parse(fs.readFileSync(path.join(repoRoot, 'app.json'), 'utf8'))
const source = fs.readFileSync(
path.join(repoRoot, 'tabWorkOrder/pages/createOrder/submitStrategy.js'),
'utf8'
)
const workflowSource = fs.readFileSync(
path.join(repoRoot, 'tabWorkOrder/pages/createOrder/services/submitWorkflow.js'),
'utf8'
)
const routeSource = fs.readFileSync(
path.join(repoRoot, 'tabWorkOrder/pages/createOrder/routeStrategy.js'),
'utf8'
)
function hasPage(root, page) {
const subpackage = (appConfig.subPackages || appConfig.subpackages || []).find(
item => item.root === root
)
return Boolean(subpackage?.pages?.includes(page))
}
describe('boutique createOrder route contract', () => {
it('keeps create and confirmation pages in tabWorkOrder', () => {
assert.equal(hasPage('tabWorkOrder', 'pages/createOrder/createOrder'), true)
assert.equal(hasPage('tabWorkOrder', 'pages/confirmOrder/confirmOrder'), true)
})
it('keeps the prerecorded success target in the main package', () => {
assert.equal(
appConfig.pages.includes('pages/tabDateIndex/pages/tabDateIndex'),
true
)
assert.match(workflowSource, /alias:\s*['"]pages\.tabDateIndex['"]/)
})
it('uses an in-package confirmation alias and never embeds query text in aliases', () => {
assert.match(workflowSource, /alias:\s*['"]confirmOrder['"]/)
assert.doesNotMatch(
source + workflowSource,
/\$router\.[a-zA-Z]+\(['"][^'"]+\?[^'"]*['"]/
)
})
it('does not import the equity business subpackage', () => {
assert.doesNotMatch(source, /packageEquity/)
})
it('validates and exactly sums supplemental associated fees before mutating page state', () => {
assert.match(
routeSource,
/import \{ sumBoutiqueAssociatedFeeCents \} from ['"]\.\/services\/goodsPriceEdit\.helpers\.js['"]/
)
assert.match(
routeSource,
/sumBoutiqueAssociatedFeeCents\([\s\S]*selectOutTradeNoArr\.map\([\s\S]*item\.totalFee/
)
assert.match(
routeSource,
/if \(!totalFeeResult\.ok\) \{[\s\S]*this\.page\.showToast\([\s\S]*return false/
)
assert.doesNotMatch(
routeSource,
/reduce\(function \(num, item\) \{\s*return num \+ item\.totalFee/
)
})
})