fix: reconcile source currencies and retail token pricing
This commit is contained in:
1 parent
ea9069e332
commit
512ca52262
12 files changed
+458
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { groupDiscountLabel, modelStandardPriceLabel, platformPriceLabel, standardPriceLabel } from '../src/services/pricing.ts'
|
||||
import { calculateTokenRetailPricing, 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 } }
|
||||
@@ -18,11 +18,28 @@ test('official standard price source is displayed, while a standard-price marker
|
||||
|
||||
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(standardPriceLabel(pricing), '$1 输入 / $4 输出 · USD / 1M(一百万 Token)')
|
||||
assert.equal(platformPriceLabel(pricing), '¥1.2 输入 / ¥4.8 输出 · 人民币 / 1M(一百万 Token)')
|
||||
assert.equal(groupDiscountLabel(pricing), '6.5折')
|
||||
})
|
||||
|
||||
test('CNY source keeps its currency and never multiplies the USD exchange rate', () => {
|
||||
const result = calculateTokenRetailPricing('CNY', {input: 0.8, output: 2.8, cachedInput: 0.23}, 3, 7.2)
|
||||
assert.deepEqual([result.input, result.output, result.cachedInput, result.exchangeRate], [0.24, 0.84, 0.069, 1])
|
||||
assert.equal(standardPriceLabel({listPriceCny:{input:0.8,output:2.8}}), '¥0.8 输入 / ¥2.8 输出 · CNY / 1M(一百万 Token)')
|
||||
assert.equal(modelStandardPriceLabel([{listPriceUsd:{input:1,output:4}},{listPriceCny:{input:1,output:4}}]), '各分组标准价见详情')
|
||||
})
|
||||
|
||||
test('retail discount is in tenths; USD conversion and eight-place rounding happen once', () => {
|
||||
const result = calculateTokenRetailPricing('USD', {input:1.25, output:10, cachedInput:0.125}, 3.5, 7.2)
|
||||
assert.deepEqual([result.input,result.output,result.cachedInput],[3.15,25.2,0.315])
|
||||
assert.equal(calculateTokenRetailPricing('CNY',{input:0.00000001,output:0},5).input,0.00000001)
|
||||
assert.equal(calculateTokenRetailPricing('CNY',{input:0,output:0,cachedInput:0},10).cachedInput,0)
|
||||
assert.throws(()=>calculateTokenRetailPricing('USD',{input:1,output:1},5),/汇率/)
|
||||
assert.throws(()=>calculateTokenRetailPricing('CNY',{input:1,output:1},55),/折扣/)
|
||||
assert.throws(()=>calculateTokenRetailPricing('CNY',{input:NaN,output:1},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 } },
|
||||
|
||||
Reference in new issue
Block a user