30 lines
1.5 KiB
JavaScript
30 lines
1.5 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', () => {
|
||
|
|
assert.match(source, /url: `\/merchant\/v1\/first-leg\/orders\/\$\{orderId\}\/inbound-billing`/)
|
||
|
|
assert.match(source, /method: 'GET'/)
|
||
|
|
assert.doesNotMatch(source, /tenantId|method: '(?:POST|PUT|PATCH|DELETE)'/)
|
||
|
|
})
|
||
|
|
|
||
|
|
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/)
|
||
|
|
})
|