v211-template-brand-id-prod.test.mjs
3.5 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixtureV211 } from './schemaFixture.mjs'
import {
FILTER_BRAND_IDS,
FIVE_REALM_BRAND_IDS
} from '../fixtures/brand-id-env-maps.mjs'
const staffDaily = loadSchemaFixtureV211('staff', 'daily')
const staffProd = loadSchemaFixtureV211('staff', 'production')
const storeDaily = loadSchemaFixtureV211('store', 'daily')
const storeProd = loadSchemaFixtureV211('store', 'production')
const PROD_FILTER = FILTER_BRAND_IDS.production
const PROD_FIVE_REALM = FIVE_REALM_BRAND_IDS.production
function findFieldByKey(list, key) {
return list.find(item => item.key === key)
}
function findChildByKey(group, key) {
return (group?.children || []).find(child => child.key === key)
}
/** 递归收集 schema 内全部 key */
function collectAllKeys(list = []) {
const keys = []
function walk(field) {
if (!field?.key) return
keys.push(field.key)
const children = field.children
if (!Array.isArray(children)) return
for (const child of children) {
if (Array.isArray(child)) {
child.forEach(walk)
} else {
walk(child)
}
}
}
list.forEach(walk)
return keys.sort()
}
describe('V2.1.1 production brandId fixtures — structure parity with daily', () => {
it('IT-V211-PROD-001: prod and daily share identical field keys', () => {
assert.deepEqual(collectAllKeys(staffProd.list), collectAllKeys(staffDaily.list))
assert.deepEqual(collectAllKeys(storeProd.list), collectAllKeys(storeDaily.list))
})
})
describe('V2.1.1 staff production brandId', () => {
it('IT-V211-PROD-STAFF-001: F1-5 问界 group uses production brandId', () => {
const group = findFieldByKey(staffProd.list, 'F1-5')
assert.deepEqual(group?.brandId, [2695])
})
it('IT-V211-PROD-STAFF-002: F1-10 岚图 group uses production brandId', () => {
const group = findFieldByKey(staffProd.list, 'F1-10')
assert.deepEqual(group?.brandId, [2188])
})
it('IT-V211-PROD-STAFF-003: F1-11 other-brand filterBrandId', () => {
const group = findFieldByKey(staffProd.list, 'F1-11')
assert.deepEqual(group?.filterBrandId, PROD_FILTER)
})
it('IT-V211-PROD-STAFF-004: F1-12/F1-13 five-realm production brandIds', () => {
for (const key of ['F1-12', 'F1-13']) {
const field = findFieldByKey(staffProd.list, key)
assert.deepEqual(field?.brandId, PROD_FIVE_REALM, key)
}
})
it('IT-V211-PROD-STAFF-005: F1-11-1 lantu-or-other uses five-realm filterBrandId', () => {
const group = findFieldByKey(staffProd.list, 'F1-11')
const child = findChildByKey(group, 'F1-11-1')
assert.deepEqual(child?.filterBrandId, PROD_FIVE_REALM)
})
})
describe('V2.1.1 store production brandId', () => {
it('IT-V211-PROD-STORE-001: F2-38 问界 uses production brandId', () => {
const field = findFieldByKey(storeProd.list, 'F2-38')
assert.deepEqual(field?.brandId, [2695])
})
it('IT-V211-PROD-STORE-002: F2-44/F2-11 other-brand filterBrandId', () => {
for (const key of ['F2-44', 'F2-11']) {
const field = findFieldByKey(storeProd.list, key)
assert.deepEqual(field?.filterBrandId, PROD_FILTER, key)
}
})
it('IT-V211-PROD-STORE-003: F2-57/F2-58 lantu-or-other five-realm filterBrandId', () => {
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeProd.list, key)
assert.deepEqual(field?.filterBrandId, PROD_FIVE_REALM, key)
}
})
it('IT-V211-PROD-STORE-004: F2-37 other-brand boutique metric filterBrandId', () => {
const field = findFieldByKey(storeProd.list, 'F2-37')
assert.deepEqual(field?.filterBrandId, PROD_FIVE_REALM)
})
})