2026-07-30 17:59:42 +08:00
|
|
|
import assert from 'node:assert/strict'
|
|
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import test from 'node:test'
|
|
|
|
|
|
|
|
|
|
const storeSource = readFileSync(new URL('./firstLegOrders.ts', import.meta.url), 'utf8')
|
|
|
|
|
const apiSource = readFileSync(new URL('../api/firstLeg.ts', import.meta.url), 'utf8')
|
|
|
|
|
|
|
|
|
|
test('declares the documented merchant warehouse and first-leg endpoints', () => {
|
|
|
|
|
assert.match(apiSource, /url: '\/merchant\/v1\/warehouses'/)
|
|
|
|
|
assert.match(apiSource, /url: '\/merchant\/v1\/orders\/first-leg'/)
|
|
|
|
|
assert.match(apiSource, /`\/merchant\/v1\/orders\/first-leg\/\$\{id\}`/)
|
|
|
|
|
assert.match(apiSource, /`\/merchant\/v1\/orders\/first-leg\/\$\{id\}\/submit`/)
|
2026-07-30 21:23:06 +08:00
|
|
|
assert.match(apiSource, /`\/merchant\/v1\/warehouses\/\$\{id\}`/)
|
2026-07-30 17:59:42 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('maps transport and status fields instead of treating container mode as transport mode', () => {
|
|
|
|
|
assert.match(storeSource, /order\.transportMode === 'SEA'.*order\.containerMode === 'FULL_CONTAINER' \? 'FCL' : 'LCL'/s)
|
|
|
|
|
assert.match(storeSource, /draft\.transportMode === 'ROAD'\) return 'TRUCK'/)
|
|
|
|
|
assert.match(storeSource, /status === 'SUBMITTED'\) return 'PENDING_REVIEW'/)
|
|
|
|
|
assert.match(storeSource, /status === 'REJECTED'\) return 'PENDING_REVIEW'/)
|
|
|
|
|
assert.match(storeSource, /status === 'PROCESSING'\) return 'IN_TRANSIT'/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('uses real API data without falling back to demo warehouses or orders', () => {
|
|
|
|
|
assert.match(storeSource, /orders\.value = \[\]/)
|
|
|
|
|
assert.match(storeSource, /warehouses\.value = \[\]/)
|
2026-08-04 11:14:29 +08:00
|
|
|
assert.match(storeSource, /Promise\.allSettled\(\[getMerchantFirstLegOrders\(\), getMerchantWarehouses\(\)\]\)/)
|
2026-07-30 17:59:42 +08:00
|
|
|
assert.doesNotMatch(storeSource, /DEMO_PLATFORM_RECEIVING_WAREHOUSES|initialOrders/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('sends backend-required channel, customs, destination and cargo fields', () => {
|
|
|
|
|
for (const field of ['pickupMethod', 'channelCode', 'channelName', 'taxMode', 'customsInspection', 'destinationType', 'packageType']) {
|
|
|
|
|
assert.match(storeSource, new RegExp(field))
|
|
|
|
|
}
|
|
|
|
|
assert.match(storeSource, /containerMode: draft\.transportMode === 'FCL' \? 'FULL_CONTAINER'/)
|
2026-08-04 12:01:05 +08:00
|
|
|
assert.doesNotMatch(storeSource, /customerId: draft\.shipperPartyId/)
|
|
|
|
|
assert.match(storeSource, /customerName: customerName\.trim\(\)/)
|
2026-08-04 11:14:29 +08:00
|
|
|
assert.match(storeSource, /destinationWarehouseId: draft\.destinationType === 'PRIVATE' \? undefined : draft\.destinationWarehouseId/)
|
2026-08-04 12:01:05 +08:00
|
|
|
assert.match(storeSource, /draft\.pickupMethod === 'PICKUP'.*draft\.shipperPartySnapshot/s)
|
|
|
|
|
assert.match(storeSource, /draft\.destinationType === 'PRIVATE'.*draft\.consigneePartySnapshot/s)
|
2026-08-04 11:14:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('separates domestic receiving warehouses from public destinations', () => {
|
|
|
|
|
assert.match(storeSource, /warehouse\.warehouseType !== 'DOMESTIC'/)
|
|
|
|
|
assert.match(storeSource, /item\.warehouseType === draft\.destinationType/)
|
|
|
|
|
assert.match(storeSource, /draft\.amazonWarehouseCode = draft\.destinationType === 'FBA' \? destinationWarehouse\.code : ''/)
|
2026-08-04 10:31:53 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('only blocks submission when a known company audit status is not active', () => {
|
|
|
|
|
assert.match(storeSource, /companyAuditStatus\?: MerchantTenantStatus/)
|
|
|
|
|
assert.match(storeSource, /if \(companyAuditStatus && companyAuditStatus !== 'ACTIVE'\)/)
|
2026-07-30 17:59:42 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('does not expose the out-of-scope cancellation write', () => {
|
|
|
|
|
assert.doesNotMatch(storeSource, /cancelMerchant|function cancel|\/cancel/)
|
|
|
|
|
assert.doesNotMatch(apiSource, /\/cancel/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('sends an idempotency key for create and submit writes', () => {
|
|
|
|
|
assert.match(apiSource, /'Idempotency-Key': createIdempotencyKey\('first-leg-create'\)/)
|
|
|
|
|
assert.match(apiSource, /'Idempotency-Key': createIdempotencyKey\(`first-leg-submit-\$\{id\}`\)/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('does not expose the contradictory backend rejected state in the client model', () => {
|
|
|
|
|
assert.match(storeSource, /status === 'REJECTED'\) return 'PENDING_REVIEW'/)
|
|
|
|
|
assert.match(storeSource, /item\.toStatus === 'SUBMITTED' \|\| item\.toStatus === 'REJECTED' \? 'SUBMITTED'/)
|
|
|
|
|
})
|
2026-07-30 21:23:06 +08:00
|
|
|
|
|
|
|
|
test('maps backend warehouse snapshots and fulfillment courier fields', () => {
|
|
|
|
|
assert.match(storeSource, /order\.receivingWarehouseAddress/)
|
|
|
|
|
assert.match(storeSource, /order\.expressCompany \?\? ''/)
|
|
|
|
|
assert.match(storeSource, /order\.expressTrackingNo \?\? ''/)
|
|
|
|
|
assert.match(storeSource, /getMerchantWarehouseDetail\(id\)/)
|
|
|
|
|
assert.match(storeSource, /receivingCapability\.cutoffTime/)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('keeps failed order loads distinct from empty results', () => {
|
|
|
|
|
assert.match(storeSource, /const loadError = ref\(''\)/)
|
2026-08-04 11:14:29 +08:00
|
|
|
assert.match(storeSource, /orderResult\.reason instanceof Error/)
|
|
|
|
|
assert.match(storeSource, /warehouseLoadError/)
|
|
|
|
|
assert.match(storeSource, /return \{ orders, warehouses, loading, loadedFromApi, loadError, warehouseLoadError/)
|
2026-07-30 21:23:06 +08:00
|
|
|
})
|