import assert from 'node:assert/strict' import test from 'node:test' import { formatFenMoney, formatSignedFenMoney, PAYMENT_PRICE_DIFF_COLOR, resolvePaymentPriceDiff, } from '../src/utils/consignment-payment-price-diff.ts' test('金额展示:分转元,未知返回 -', () => { assert.equal(formatFenMoney(11000), '¥110.00') assert.equal(formatFenMoney(0), '¥0.00') assert.equal(formatFenMoney(null), '-') assert.equal(formatFenMoney(undefined), '-') }) test('差价展示:正数带 +、负数带 -、0 不带符号', () => { assert.equal(formatSignedFenMoney(2000), '+¥20.00') assert.equal(formatSignedFenMoney(-2000), '-¥20.00') assert.equal(formatSignedFenMoney(0), '¥0.00') }) test('售价差价:用户付款 - 售价,正绿负红零黄', () => { assert.deepEqual(resolvePaymentPriceDiff(15000, 11000), { diffFen: 4000, text: '+¥40.00', color: PAYMENT_PRICE_DIFF_COLOR.positive, }) assert.deepEqual(resolvePaymentPriceDiff(10000, 11000), { diffFen: -1000, text: '-¥10.00', color: PAYMENT_PRICE_DIFF_COLOR.negative, }) assert.deepEqual(resolvePaymentPriceDiff(11000, 11000), { diffFen: 0, text: '¥0.00', color: PAYMENT_PRICE_DIFF_COLOR.zero, }) }) test('售价差价:付款未知、售价缺失或拼单不展示', () => { assert.equal(resolvePaymentPriceDiff(null, 11000), null) assert.equal(resolvePaymentPriceDiff(undefined, 11000), null) assert.equal(resolvePaymentPriceDiff(15000, undefined), null) assert.equal(resolvePaymentPriceDiff(15000, 11000, { sharingEnabled: true }), null) })