liveProfiles.test.mjs
4.56 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 fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath, pathToFileURL } from 'node:url'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const profilesPath = path.join(projectRoot, 'tests/order-lifecycle/liveProfiles.mjs')
async function loadProfiles() {
assert.equal(fs.existsSync(profilesPath), true, 'live profile resolver must exist')
return import(pathToFileURL(profilesPath))
}
test('resolves the approved development and test profiles from runtime-only credentials', async () => {
const { resolveLiveProfile } = await loadProfiles()
const development = resolveLiveProfile('regional-dev-login', {
LIVE_REGIONAL_DEV_MOBILE: 'runtime-mobile-dev',
LIVE_REGIONAL_DEV_CODE: 'runtime-code-dev',
})
const functional = resolveLiveProfile('regional-test', {
LIVE_REGIONAL_TEST_MOBILE: 'runtime-mobile-test',
LIVE_REGIONAL_TEST_CODE: 'runtime-code-test',
})
assert.deepEqual(development, {
name: 'regional-dev-login',
environment: 'development',
mode: 'login-only',
baseUrl: 'http://dj.dev.glsx.com.cn/rop-dj-car-boutique',
mobile: 'runtime-mobile-dev',
code: 'runtime-code-dev',
})
assert.equal(functional.name, 'regional-test')
assert.equal(functional.environment, 'test')
assert.equal(functional.mode, 'functional')
assert.equal(functional.yqName, '流程测试园区门店')
assert.equal(functional.storeName, '波波的单店门店')
assert.equal(functional.sceneName, '精品升级')
})
test('requires explicit selection and only the declared credential variables', async () => {
const { resolveLiveProfile } = await loadProfiles()
assert.throws(() => resolveLiveProfile('', {}), /profile.*required/i)
assert.throws(() => resolveLiveProfile('unknown', {}), /unknown live profile/i)
assert.throws(
() => resolveLiveProfile('regional-test', {}),
/LIVE_REGIONAL_TEST_MOBILE.*LIVE_REGIONAL_TEST_CODE/,
)
assert.throws(
() =>
resolveLiveProfile('regional-dev-login', {
LIVE_REGIONAL_TEST_MOBILE: 'wrong-mobile',
LIVE_REGIONAL_TEST_CODE: 'wrong-code',
}),
/LIVE_REGIONAL_DEV_MOBILE.*LIVE_REGIONAL_DEV_CODE/,
)
})
test('development is login-only while test writes require an independent gate', async () => {
const { resolveLiveProfile, assertLiveWriteAllowed } = await loadProfiles()
const development = resolveLiveProfile('regional-dev-login', {
LIVE_REGIONAL_DEV_MOBILE: 'runtime-mobile',
LIVE_REGIONAL_DEV_CODE: 'runtime-code',
})
const functional = resolveLiveProfile('regional-test', {
LIVE_REGIONAL_TEST_MOBILE: 'runtime-mobile',
LIVE_REGIONAL_TEST_CODE: 'runtime-code',
})
assert.throws(
() => assertLiveWriteAllowed(development, { LIVE_ALLOW_WRITES: '1' }),
/does not allow Live writes/,
)
assert.throws(() => assertLiveWriteAllowed(functional, {}), /LIVE_ALLOW_WRITES=1/)
assert.equal(
assertLiveWriteAllowed(functional, { LIVE_ALLOW_WRITES: '1' }),
true,
)
})
test('profile metadata never contains credential literals', async () => {
const { LIVE_PROFILE_DEFINITIONS } = await loadProfiles()
const serialized = JSON.stringify(LIVE_PROFILE_DEFINITIONS)
assert.doesNotMatch(serialized, /\b1\d{10}\b/)
assert.doesNotMatch(serialized, /(?:mobile|code)Value/i)
})
test('order E2E accepts only the functional profile and keeps guarded legacy support', async () => {
const { loadE2EConfig } = await import('./e2e/testConfig.mjs')
const profile = loadE2EConfig({
ORDER_E2E_PROFILE: 'regional-test',
LIVE_REGIONAL_TEST_MOBILE: 'runtime-mobile',
LIVE_REGIONAL_TEST_CODE: 'runtime-code',
LIVE_ALLOW_WRITES: '1',
RUN_ORDER_E2E: '1',
})
assert.equal(profile.profile, 'regional-test')
assert.equal(profile.baseUrl, 'http://dj.test.glsx.com.cn/rop-dj-car-boutique')
assert.equal(profile.storeName, '波波的单店门店')
assert.throws(
() =>
loadE2EConfig({
ORDER_E2E_PROFILE: 'regional-dev-login',
LIVE_REGIONAL_DEV_MOBILE: 'runtime-mobile',
LIVE_REGIONAL_DEV_CODE: 'runtime-code',
LIVE_ALLOW_WRITES: '1',
RUN_ORDER_E2E: '1',
}),
/does not allow Live writes/,
)
assert.throws(
() =>
loadE2EConfig({
RUN_ORDER_E2E: '1',
ORDER_E2E_BASE_URL: 'http://dj.test.glsx.com.cn/rop-dj-car-boutique',
ORDER_E2E_MOBILE: 'runtime-mobile',
ORDER_E2E_CODE: 'runtime-code',
ORDER_E2E_YQ_NAME: '流程测试园区门店',
ORDER_E2E_STORE_NAME: '波波的单店门店',
}),
/LIVE_ALLOW_WRITES=1/,
)
})