This commit is contained in:
2026-08-06 13:56:13 +08:00
parent 356bec03fb
commit 85ca013928
14 changed files with 727 additions and 78 deletions
@@ -4,6 +4,7 @@ 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')
const unifiedApiSource = readFileSync(new URL('../api/unifiedOrders.ts', import.meta.url), 'utf8')
test('declares the documented merchant warehouse and first-leg endpoints', () => {
assert.match(apiSource, /url: '\/merchant\/v1\/warehouses'/)
@@ -18,16 +19,57 @@ test('maps transport and status fields instead of treating container mode as tra
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'/)
assert.match(storeSource, /status === 'APPROVED' \|\| status === 'ACCEPTED' \|\| status === 'PROCESSING'\) return 'WAIT_MEASURE'/)
assert.match(storeSource, /status === 'COMPLETED'\) return 'DELIVERED'/)
})
test('uses real API data without falling back to demo warehouses or orders', () => {
test('prefers unified reads and only falls back to the real legacy API when C02 is unavailable', () => {
assert.match(storeSource, /orders\.value = \[\]/)
assert.match(storeSource, /warehouses\.value = \[\]/)
assert.match(storeSource, /Promise\.allSettled\(\[getMerchantFirstLegOrders\(\), getMerchantWarehouses\(\)\]\)/)
assert.match(storeSource, /Promise\.allSettled\(\[getOrdersForClient\(query\), getMerchantWarehouses\(\)\]\)/)
assert.match(storeSource, /getMerchantUnifiedOrders\(unifiedQuery\)/)
assert.match(storeSource, /isUnifiedOrderQueryUnavailable\(error\)/)
assert.match(storeSource, /getMerchantFirstLegOrders\(legacyQuery\(query\)\)/)
assert.doesNotMatch(storeSource, /DEMO_PLATFORM_RECEIVING_WAREHOUSES|initialOrders/)
})
test('declares the final C02 row and detail contract in the API adapter', () => {
assert.match(unifiedApiSource, /const unifiedOrderBaseUrl = '\/merchant\/v1\/orders'/)
assert.doesNotMatch(unifiedApiSource, /orders\/unified/)
assert.match(unifiedApiSource, /orderId: number \| string/)
assert.match(unifiedApiSource, /mainStatus: ApiUnifiedOrderMainStatus/)
assert.match(unifiedApiSource, /nextAction: string \| null/)
assert.match(unifiedApiSource, /loadingVersion: number/)
assert.match(unifiedApiSource, /pickingVersion: number/)
assert.match(unifiedApiSource, /summary: MerchantUnifiedOrderRow/)
assert.match(unifiedApiSource, /order: MerchantFirstLegOrderDetail/)
assert.match(unifiedApiSource, /timeline: MerchantUnifiedTimelineEvent\[\]/)
assert.match(unifiedApiSource, /customNodes\?: MerchantUnifiedCustomNode\[\]/)
assert.match(unifiedApiSource, /error\.status === 404 \|\| error\.code === 'A0404'/)
})
test('keeps drafts on the legacy read path without assigning a unified main status', () => {
assert.match(storeSource, /getMerchantFirstLegOrders\(legacyQuery\(query, 'DRAFT'\)\)/)
assert.match(storeSource, /getById\(id\)\?\.status === 'DRAFT' \? loadLegacyDetail\(id\) : loadUnifiedDetail\(id\)/)
assert.match(storeSource, /return loadLegacyDetail\(String\(createdId\)\)/)
assert.match(storeSource, /draftLoadError/)
})
test('routes supported filters to C02 without sending DRAFT as a main status', () => {
assert.match(storeSource, /interface ClientOrderReadQuery extends MerchantUnifiedOrderQuery/)
assert.match(storeSource, /if \(query\.draftOnly\)/)
assert.match(storeSource, /const unifiedQuery: MerchantUnifiedOrderQuery/)
assert.match(storeSource, /getMerchantUnifiedOrders\(unifiedQuery\)/)
})
test('maps C02 rows by orderId and leaves absent transport details unknown', () => {
assert.match(storeSource, /id: String\(summary\.orderId\)/)
assert.match(storeSource, /transportMode: null/)
assert.match(storeSource, /summary\?\.loading\?\.loadingVersion/)
assert.match(storeSource, /summary\?\.loading\?\.pickingVersion/)
assert.match(storeSource, /summary\?\.inboundId == null \? '' : String\(summary\.inboundId\)/)
})
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))
@@ -63,7 +105,17 @@ test('sends an idempotency key for create and submit writes', () => {
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'/)
assert.match(storeSource, /item\.toStatus === 'REJECTED' \? '订单信息已补充'/)
})
test('maps the final backend timeline and keeps missing custom nodes empty', () => {
assert.match(storeSource, /detail\.timeline\.flatMap/)
assert.match(storeSource, /item\.mainStatus/)
assert.match(storeSource, /\(detail\.customNodes \?\? \[\]\)/)
assert.match(storeSource, /\.filter\(\(item\) => item\.customerVisible\)/)
assert.match(storeSource, /kind: 'CUSTOM_NODE'/)
assert.match(storeSource, /status: null/)
assert.match(storeSource, /\.sort\(\(left, right\)/)
})
test('maps backend warehouse snapshots and fulfillment courier fields', () => {
@@ -78,5 +130,5 @@ test('keeps failed order loads distinct from empty results', () => {
assert.match(storeSource, /const loadError = ref\(''\)/)
assert.match(storeSource, /orderResult\.reason instanceof Error/)
assert.match(storeSource, /warehouseLoadError/)
assert.match(storeSource, /return \{ orders, warehouses, loading, loadedFromApi, loadError, warehouseLoadError/)
assert.match(storeSource, /return \{ orders, warehouses, loading, loadedFromApi, loadError, warehouseLoadError, draftLoadError/)
})