Merge remote-tracking branch 'origin/release/test' into dev
This commit is contained in:
@@ -6,9 +6,17 @@ const source = readFileSync(new URL('./inboundBilling.ts', import.meta.url), 'ut
|
||||
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)'/)
|
||||
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', () => {
|
||||
|
||||
@@ -65,6 +65,8 @@ function sanitizeFee(fee: MerchantInboundFeeSnapshot): MerchantInboundFeeSnapsho
|
||||
feeStatus: fee.feeStatus,
|
||||
inboundId: fee.inboundId,
|
||||
inboundCode: fee.inboundCode,
|
||||
measurementId: fee.measurementId == null ? null : String(fee.measurementId),
|
||||
measurementSource: fee.measurementSource,
|
||||
chargeRuleId: fee.chargeRuleId,
|
||||
ruleCode: fee.ruleCode,
|
||||
chargeRuleVersion: fee.chargeRuleVersion,
|
||||
@@ -101,6 +103,10 @@ function sanitizeFee(fee: MerchantInboundFeeSnapshot): MerchantInboundFeeSnapsho
|
||||
confirmedAt: fee.confirmedAt,
|
||||
sentAt: fee.sentAt,
|
||||
nextProcessStatus: fee.nextProcessStatus,
|
||||
customerConfirmationStatus: fee.customerConfirmationStatus,
|
||||
customerConfirmedBy: fee.customerConfirmedBy == null ? null : String(fee.customerConfirmedBy),
|
||||
customerConfirmedByName: fee.customerConfirmedByName,
|
||||
customerConfirmedAt: fee.customerConfirmedAt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +121,7 @@ function sanitizeMeasurementSummary(item: MerchantInboundBilling['measurementSum
|
||||
actualVolumeCbm: item.actualVolumeCbm,
|
||||
volumeWeightKg: item.volumeWeightKg,
|
||||
actualGoodsName: item.actualGoodsName,
|
||||
calculationSource: item.calculationSource,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +137,9 @@ function sanitizeMeasurementItem(item: MerchantInboundBilling['measurementItems'
|
||||
unitVolumeCbm: item.unitVolumeCbm,
|
||||
totalVolumeCbm: item.totalVolumeCbm,
|
||||
volumeWeightKg: item.volumeWeightKg,
|
||||
chargeRuleId: item.chargeRuleId == null ? null : String(item.chargeRuleId),
|
||||
coefficientMode: item.coefficientMode,
|
||||
calculationRuleVersion: item.calculationRuleVersion,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,3 +164,19 @@ export async function getMerchantInboundBilling(orderId: string): Promise<Mercha
|
||||
})
|
||||
return sanitizeInboundBilling(response)
|
||||
}
|
||||
|
||||
function createFeeConfirmationKey(orderId: string, feeVersion: number) {
|
||||
const randomPart = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||
return `inbound-fee-confirm-${orderId}-${feeVersion}-${randomPart}`
|
||||
}
|
||||
|
||||
export async function confirmMerchantInboundFee(orderId: string, expectedFeeVersion: number,
|
||||
idempotencyKey = createFeeConfirmationKey(orderId, expectedFeeVersion)) {
|
||||
const response = await apiRequest<MerchantInboundFeeSnapshot>({
|
||||
method: 'POST',
|
||||
url: `/merchant/v1/first-leg/orders/${encodeURIComponent(orderId)}/inbound-billing/confirm`,
|
||||
headers: { 'Idempotency-Key': idempotencyKey },
|
||||
data: { expectedFeeVersion },
|
||||
})
|
||||
return sanitizeFee(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user