feat(pricing): 开发定价方案
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { parseCbrCny } from '../src/exchange-rate-sync.ts';
|
||||
const xml = (nominal, value) =>
|
||||
`<ValCurs Date="28.09.2026"><Valute ID="CNY"><CharCode>CNY</CharCode><Nominal>${nominal}</Nominal><Value>${value}</Value></Valute></ValCurs>`;
|
||||
test('CBR 按面额做精确十进制换算', () => {
|
||||
assert.deepEqual(parseCbrCny(xml(10, '123,4567')), {
|
||||
effectiveOn: '2026-09-28',
|
||||
rate: '12.3456700000',
|
||||
});
|
||||
assert.equal(parseCbrCny(xml(3, '1,0000')).rate, '0.3333333333');
|
||||
});
|
||||
test('缺失货币、非法日期和零面额不能覆盖有效汇率', () => {
|
||||
assert.throws(() => parseCbrCny('<error/>'));
|
||||
assert.throws(() => parseCbrCny(xml(0, '12,3')));
|
||||
assert.throws(() => parseCbrCny(xml(1, '12,3').replace('28.09', '32.09')));
|
||||
});
|
||||
Reference in New Issue
Block a user