Files
client-web/src/modules/first-leg/utils/inboundBilling.test.mjs
T

50 lines
2.7 KiB
JavaScript
Raw Normal View History

2026-08-04 21:01:34 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import ts from 'typescript'
2026-08-04 21:01:34 +08:00
const source = readFileSync(new URL('./inboundBilling.ts', import.meta.url), 'utf8')
const { getChargeModeLabel } = await import(`data:text/javascript;base64,${Buffer.from(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
}).outputText).toString('base64')}`)
test('describes the quantity basis from the published fee instead of treating the charge unit as the basis', () => {
assert.equal(getChargeModeLabel('KG', 393, 3.6894, 616.1298), '按体积重计费')
assert.equal(getChargeModeLabel('KG', 700, 3.6894, 616.1298), '按毛重计费')
assert.equal(getChargeModeLabel('KG', 616.1298, 3.6894, 616.1298), '按毛重计费')
assert.equal(getChargeModeLabel('CBM', 600, 1.2, 1.6), '按重量折算体积计费')
assert.equal(getChargeModeLabel('CBM', 600, 2, 1.6), '按体积计费')
assert.equal(getChargeModeLabel('CBM', 600, 1.6, 1.6), '按体积计费')
assert.equal(getChargeModeLabel('KG', 393, 3.6894, Number.NaN), '-')
assert.equal(getChargeModeLabel('KG', Number.POSITIVE_INFINITY, 3.6894, 616.1298), '-')
})
2026-08-04 21:01:34 +08:00
test('formats zero values, currencies, measurements, and backend dates without hardcoded business factors', () => {
assert.match(source, /value === null \|\| value === undefined/)
assert.match(source, /Intl\.NumberFormat\('zh-CN'/)
assert.match(source, /style: 'currency'/)
assert.match(source, /Intl\.DateTimeFormat\('zh-CN'/)
assert.doesNotMatch(source, /\b167\b|\b363\b/)
})
test('translates backend rounding modes into customer-facing calculation labels', () => {
assert.match(source, /export function getRoundingModeLabel/)
assert.match(source, /CEILING: '向上取整'/)
assert.match(source, /HALF_UP: '四舍五入'/)
2026-08-29 11:45:57 +08:00
assert.match(source, /return value \? labels\[value\] \|\| value : '-'/)
})
2026-09-21 19:36:37 +08:00
test('translates carton calculation rules into customer-facing labels', () => {
assert.match(source, /export function getCalculationRuleLabel/)
assert.match(source, /ACTUAL_DIMENSION_V1/)
assert.match(source, /按实际箱规计算/)
assert.match(source, /CUSTOMER_DIMENSION_\(SMALL\|MEDIUM\|LARGE\|EXTRA_LARGE\)_V/)
})
2026-08-29 11:45:57 +08:00
test('renders conversion metadata as one complete label or a single empty marker', () => {
assert.match(source, /export function formatConversionPrecision/)
assert.match(source, /roundingScale === null \|\| roundingScale === undefined/)
assert.match(source, /\|\| !roundingMode\) return '-'/)
assert.match(source, /`系数 \$\{formatInboundNumber\(conversionFactor\)\} · 保留 \$\{roundingScale\} 位 \$\{getRoundingModeLabel\(roundingMode\)\}`/)
2026-08-04 21:01:34 +08:00
})