28 lines
1.9 KiB
JavaScript
28 lines
1.9 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { frozenOuterMeasurement, publishedMeasurementItemsMatch } from './client-phase2-measurement-evidence.mjs'
|
|
|
|
const source = () => ({ id: '9007199254740993', packageCount: 1, lengthCm: 49.5, widthCm: 39.5, heightCm: 38.5,
|
|
calculatedOuterLengthCm: 53.5, calculatedOuterWidthCm: 43.5, calculatedOuterHeightCm: 42.5,
|
|
unitVolumeCbm: 0.099, totalVolumeCbm: 0.099, volumeWeightKg: 16.533,
|
|
chargeRuleId: '9007199254740994', coefficientMode: 'ADD', calculationRuleVersion: 'FROZEN-1' })
|
|
const published = () => ({ ...source(), lengthCm: 53.5, widthCm: 43.5, heightCm: 42.5 })
|
|
test('客户计费读取已冻结外尺寸,不把原始测量或当前箱规当成发布尺寸', () => {
|
|
assert.deepEqual(frozenOuterMeasurement(source()), { outer: [53.5, 43.5, 42.5], unitVolumeCbm: 0.099 })
|
|
assert.equal(publishedMeasurementItemsMatch([published()], [source()]), true)
|
|
assert.equal(publishedMeasurementItemsMatch([source()], [source()]), false)
|
|
})
|
|
test('发布值、计费规则快照及精确长整数来源不一致时拒绝', () => {
|
|
for (const mutate of [v => { v.id = '9007199254740992' }, v => { v.lengthCm++ },
|
|
v => { v.unitVolumeCbm += 0.001 }, v => { v.chargeRuleId = 'OTHER' },
|
|
v => { v.coefficientMode = 'MULTIPLY' }, v => { v.calculationRuleVersion = 'NEW' }]) {
|
|
const item = published(); mutate(item)
|
|
assert.equal(publishedMeasurementItemsMatch([item], [source()]), false)
|
|
}
|
|
assert.equal(publishedMeasurementItemsMatch([published(), published()], [source(), source()]), false)
|
|
assert.equal(publishedMeasurementItemsMatch([], []), false)
|
|
assert.equal(publishedMeasurementItemsMatch([{ ...published(), id: null }], [{ ...source(), id: null }]), false)
|
|
assert.equal(publishedMeasurementItemsMatch([{ ...published(), id: 9007199254740993 }], [source()]), false)
|
|
assert.throws(() => frozenOuterMeasurement({ ...source(), calculatedOuterLengthCm: null }))
|
|
})
|