36 lines
2.1 KiB
JavaScript
36 lines
2.1 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { groupDiscountLabel, modelStandardPriceLabel, platformPriceLabel, standardPriceLabel } from '../src/services/pricing.ts'
|
|
|
|
test('fixed-unit pricing shows platform task price without inventing a standard price or discount', () => {
|
|
const tripo = { price: 1.44, unit: 'CNY / task', upstreamCredits: 20, exchangeRate: 7.2, priceSource: 'Tripo 官方', standardPrice: { price: 0.2, unit: 'USD / task', credits: 20 } }
|
|
assert.equal(standardPriceLabel(tripo), '$0.2 / task')
|
|
assert.equal(modelStandardPriceLabel([tripo]), '$0.2 / task')
|
|
assert.equal(platformPriceLabel(tripo), '平台售价 ¥1.44 / task')
|
|
assert.equal(groupDiscountLabel(tripo), '折扣未提供')
|
|
})
|
|
|
|
test('official standard price source is displayed, while a standard-price marker is not treated as a discount', () => {
|
|
const tripo = { price: 1.44, unit: 'CNY / task', discountLabel: '标准价', standardPrice: { price: 0.2, unit: 'USD / task', credits: 20, priceSource: 'Tripo 官方 API 定价' } }
|
|
assert.equal(standardPriceLabel(tripo), '$0.2 / task · Tripo 官方 API 定价')
|
|
assert.equal(groupDiscountLabel(tripo), '折扣未提供')
|
|
})
|
|
|
|
test('token pricing retains explicit source list price and discount', () => {
|
|
const pricing = { input: 1.2, output: 4.8, unit: 'CNY / 1M tokens', discount: 6.5, discountLabel: '6.5折', listPriceUsd: { input: 1, output: 4 } }
|
|
assert.equal(standardPriceLabel(pricing), '$1 输入 / $4 输出 · USD / 1M')
|
|
assert.equal(platformPriceLabel(pricing), '¥1.2 输入 / ¥4.8 输出 · CNY / 1M tokens')
|
|
assert.equal(groupDiscountLabel(pricing), '6.5折')
|
|
})
|
|
|
|
test('different route list prices are not presented as one universal model price', () => {
|
|
assert.equal(modelStandardPriceLabel([
|
|
{ unit: 'CNY / 1M tokens', listPriceUsd: { input: 1, output: 4 } },
|
|
{ unit: 'CNY / 1M tokens', listPriceUsd: { input: 2, output: 8 } },
|
|
]), '各分组标准价见详情')
|
|
assert.equal(modelStandardPriceLabel([
|
|
{ unit: 'CNY / 1M tokens', listPriceUsd: { input: 1, output: 4 } },
|
|
{ price: 1.44, unit: 'CNY / task' },
|
|
]), '部分分组标准价见详情')
|
|
})
|