car-brand-api.test.mjs
1.89 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
const require = createRequire(import.meta.url)
const __dirname = dirname(fileURLToPath(import.meta.url))
const apiPath = join(__dirname, '../api/carBrandApi.js')
const {
getMockCarSeriesList,
getMockCarTypeList
} = require('../fixtures/mock-car-model-api.js')
const { CAR_MODEL_QUERY_SWITCH } = require('../config/apiSwitch.js')
describe('mock-car-model-api', () => {
it('IT-CAR-MOCK-001: getMockCarSeriesList returns series for childBrandId 3454', () => {
const list = getMockCarSeriesList({ brandId: 3454, childBrandId: 3454 })
assert.ok(list.length >= 1)
assert.equal(list[0].name, '问界M7')
})
it('IT-CAR-MOCK-002: getMockCarTypeList returns types for series id', () => {
const list = getMockCarTypeList('series-m7')
assert.ok(list.some(item => item.name.includes('Max')))
})
})
describe('carBrandApi', () => {
const source = readFileSync(apiPath, 'utf8')
it('IT-CAR-API-001: defines merchant + scrm carlife methods', () => {
assert.match(source, /getMerchantCarBrandList\s*\(/)
assert.match(source, /fetchMerchantCarBrandTree\s*\(/)
assert.match(source, /fetchMerchantOperatingBrandList\s*\(/)
assert.match(source, /merchants\.api\.open\.merchant\.info/)
assert.match(source, /getCarSeriesList\s*\(/)
assert.match(source, /getCarTypeList\s*\(/)
assert.match(source, /scrm\.api\.carlife\.common\.getCarSeriesList/)
assert.match(source, /scrm\.api\.carlife\.common\.getCarTypeList/)
assert.doesNotMatch(source, /require\([^)]*carEquityApi/)
})
it('IT-CAR-API-002: car model query switch defaults to real (form picker)', () => {
assert.equal(CAR_MODEL_QUERY_SWITCH, 'real')
assert.match(source, /isCarModelQueryMockMode/)
})
})