Files
client-web/src/modules/first-leg/api/inboundBilling.test.mjs
T
2026-09-03 17:49:09 +08:00

38 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const source = readFileSync(new URL('./inboundBilling.ts', import.meta.url), 'utf8')
const typesSource = readFileSync(new URL('../types/inboundBilling.ts', import.meta.url), 'utf8')
test('queries the merchant order inbound-billing endpoint without tenant parameters', () => {
const readSource = source.slice(source.indexOf('export async function getMerchantInboundBilling'), source.indexOf('function createFeeConfirmationKey'))
assert.match(readSource, /url: `\/merchant\/v1\/first-leg\/orders\/\$\{orderId\}\/inbound-billing`/)
assert.match(readSource, /method: 'GET'/)
assert.doesNotMatch(readSource, /tenantId|method: '(?:POST|PUT|PATCH|DELETE)'/)
})
test('confirms the latest customer fee version with an idempotency key', () => {
assert.match(source, /function confirmMerchantInboundFee/)
assert.match(source, /\/inbound-billing\/confirm/)
assert.match(source, /headers: \{ 'Idempotency-Key': idempotencyKey \}/)
assert.match(source, /data: \{ expectedFeeVersion \}/)
})
test('sanitizes the platform-shaped response into a merchant whitelist', () => {
assert.match(source, /function sanitizeInboundBilling/)
assert.match(source, /summary: sanitizeSummary\(response\.inbound\.summary\)/)
assert.match(source, /palletLocations: response\.inbound\.palletLocations\.map\(sanitizePalletLocation\)/)
assert.match(source, /latestFee: sanitizeFee\(response\.latestFee\)/)
assert.doesNotMatch(source, /\.\.\.response|\.\.\.summary|\.\.\.fee/)
assert.doesNotMatch(source, /internalNotes|statusHistory|files/)
})
test('keeps all backend Long identifiers as strings', () => {
for (const field of ['id', 'orderId', 'warehouseId', 'palletId', 'locationId', 'feeId', 'inboundId', 'chargeRuleId', 'carrierRateId', 'customerId', 'carrierId']) {
assert.match(typesSource, new RegExp(`${field}: string`))
}
assert.doesNotMatch(typesSource, /(?:id|Id): number/)
assert.doesNotMatch(typesSource, /internalNotes|statusHistory|files/)
})