21 lines
1.2 KiB
JavaScript
21 lines
1.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { readFileSync } from 'node:fs'
|
|
import ts from 'typescript'
|
|
|
|
test('计费重确认保留大整数来源和原幂等键,只提交预期重量版本', async () => {
|
|
const calls = []
|
|
const source = readFileSync(new URL('./chargeableWeights.ts', import.meta.url), 'utf8')
|
|
const code = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }).outputText
|
|
const exports = {}
|
|
new Function('require', 'exports', code)(() => ({ apiRequest: async request => { calls.push(request); return [] } }), exports)
|
|
const id = '9223372036854775806'
|
|
await exports.getChargeableWeights(id)
|
|
await exports.confirmChargeableWeight({ inboundId: id, fingerprint: 'abc' }, 'original-command')
|
|
assert.equal(calls[0].url, `/merchant/v1/first-leg/orders/${id}/chargeable-weights`)
|
|
assert.equal(calls[1].url, `/merchant/v1/first-leg/chargeable-weights/${id}/confirm`)
|
|
assert.deepEqual(calls[1].headers, { 'Idempotency-Key': 'original-command' })
|
|
assert.deepEqual(calls[1].data, { expectedFingerprint: 'abc' })
|
|
assert.equal(calls.some(call => call.url.includes('inbound-billing')), false)
|
|
})
|