解决海外仓前端提交冲突

This commit is contained in:
2026-08-28 14:41:40 +08:00
13 changed files with 122 additions and 71 deletions
@@ -0,0 +1,27 @@
import { readFileSync } from 'node:fs'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
const source = (relativePath: string) => readFileSync(path.resolve(process.cwd(), relativePath), 'utf8')
const palletsApi = source('src/modules/overseas-warehouse/api/pallets.ts')
const palletsPage = source('src/modules/overseas-warehouse/pages/PalletsView.vue')
const iamApi = source('src/modules/iam/api/platformIam.ts')
describe('Admin pallet warehouse routing contract', () => {
it('loads ACTIVE OVERSEAS receiving warehouse candidates from domestic Warehouse only', () => {
expect(palletsApi).toContain("import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'")
expect(palletsApi).toContain('await listSharedReceivingOverseasWarehouseOptions()')
expect(palletsPage).toContain('listReceivingOverseasWarehouses()')
expect(iamApi).toContain("'/platform/v1/warehouse-admin'")
for (const filter of ["tenantId: '0'", "capabilityCode: 'RECEIVING'", "warehouseType: 'OVERSEAS'", "status: 'ACTIVE'"]) {
expect(iamApi).toContain(filter)
}
})
it('never calls the nonexistent overseas warehouse-admin root and always scopes pallet calls by warehouseId', () => {
expect(palletsApi).not.toMatch(/overseasHttp\.get[^\n]*\(\s*['"]\/platform\/v1\/warehouse-admin['"]/)
expect(palletsApi).not.toContain('listCustomerWarehouses')
expect(palletsApi).toContain('`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets`')
expect(palletsApi).toContain('`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}`')
})
})
@@ -1,7 +1,9 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { overseasHttp } from '@/shared/api/overseasHttp'
import { createPallet, getPallet, listCustomerWarehouses, listPallets, updatePallet } from './pallets'
import { createPallet, getPallet, listPallets, listReceivingOverseasWarehouses, updatePallet } from './pallets'
vi.mock('@/modules/iam', () => ({ listSharedReceivingOverseasWarehouseOptions: vi.fn() }))
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
describe('overseas pallet API', () => {
@@ -12,20 +14,21 @@ describe('overseas pallet API', () => {
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', data: page })
vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', data: '9' })
vi.mocked(overseasHttp.put).mockResolvedValue({ code: '200', data: null })
const payload = { palletCode: 'PLT-NEW', palletType: 'WOOD', fbaWarehouseCode: 'ONT8', capacityCbm: 2, unitPrice: 10, status: 'IDLE' }
vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockResolvedValue([{ id: '200', warehouseCode: 'LAX', warehouseName: '洛杉矶仓', countryCode: 'US' }])
const payload = { palletCode: 'PLT-NEW', palletType: 'WOOD', fbaWarehouseCode: 'ABE3', capacityCbm: 2, unitPrice: 10, status: 'IDLE' }
await listCustomerWarehouses()
await expect(listReceivingOverseasWarehouses()).resolves.toMatchObject({ records: [{ id: '200', customerId: '0', warehouseCode: 'LAX', warehouseType: 'OVERSEAS', status: 'ACTIVE' }] })
await listPallets('200', { page: 1, size: 20, keyword: 'PLT' })
await getPallet('200', '9')
await createPallet('200', payload)
await updatePallet('200', '9', { ...payload, version: 7 })
expect(overseasHttp.get).toHaveBeenNthCalledWith(1, '/platform/v1/warehouse-admin', { params: { page: 1, size: 200 } })
expect(overseasHttp.get).toHaveBeenNthCalledWith(2, '/platform/v1/warehouse-admin/200/pallets', { params: { page: 1, size: 20, keyword: 'PLT' } })
expect(overseasHttp.get).toHaveBeenNthCalledWith(3, '/platform/v1/warehouse-admin/200/pallets/9', {})
expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce()
expect(overseasHttp.get).toHaveBeenNthCalledWith(1, '/platform/v1/warehouse-admin/200/pallets', { params: { page: 1, size: 20, keyword: 'PLT' } })
expect(overseasHttp.get).toHaveBeenNthCalledWith(2, '/platform/v1/warehouse-admin/200/pallets/9', {})
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets', payload)
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9', { ...payload, version: 7 })
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9', expect.objectContaining({ palletCode: 'PLT-NEW', fbaWarehouseCode: 'ONT8', version: 7 }))
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets/9', expect.objectContaining({ palletCode: 'PLT-NEW', fbaWarehouseCode: 'ABE3', status: 'IDLE', version: 7 }))
expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin/200/pallets', expect.not.objectContaining({ version: expect.anything() }))
})
})
+12 -7
View File
@@ -1,8 +1,9 @@
import { overseasHttp } from '@/shared/api/overseasHttp'
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { normalizeOverseasPage, type OverseasPagePayload } from './lastMileOrders'
export interface CustomerWarehouseDto {
export interface ReceivingOverseasWarehouseDto {
id: string
customerId: string
warehouseCode: string
@@ -43,12 +44,16 @@ export interface UpdatePalletPayload extends SavePalletPayload {
version: number
}
export async function listCustomerWarehouses() {
const response = await overseasHttp.get<ApiEnvelope<OverseasPagePayload<CustomerWarehouseDto>>, ApiEnvelope<OverseasPagePayload<CustomerWarehouseDto>>>(
'/platform/v1/warehouse-admin',
{ params: { page: 1, size: 200 } },
)
return normalizeOverseasPage(unwrapApiResponse(response))
export async function listReceivingOverseasWarehouses() {
const records: ReceivingOverseasWarehouseDto[] = (await listSharedReceivingOverseasWarehouseOptions()).map((warehouse) => ({
id: warehouse.id,
customerId: '0',
warehouseCode: warehouse.warehouseCode,
warehouseName: warehouse.warehouseName,
warehouseType: 'OVERSEAS',
status: 'ACTIVE',
}))
return { records, page: 1, size: 200, total: records.length, pages: records.length ? 1 : 0 }
}
export async function listPallets(warehouseId: string | undefined, query: { page: number; size: number; keyword?: string; palletType?: string; status?: string }) {
@@ -1,7 +1,9 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { overseasHttp } from '@/shared/api/overseasHttp'
import { changeRelabelOrderStatus, createRelabelOrder, getRelabelOrder, listRelabelOrders, listRelabelWarehouseOptions } from './relabelOrders'
vi.mock('@/modules/iam', () => ({ listSharedReceivingOverseasWarehouseOptions: vi.fn() }))
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
describe('relabel overseas API', () => {
@@ -9,6 +11,7 @@ describe('relabel overseas API', () => {
vi.mocked(overseasHttp.get).mockReset()
vi.mocked(overseasHttp.post).mockReset()
vi.mocked(overseasHttp.put).mockReset()
vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockReset()
})
it('uses the platform page endpoint without customer scope', async () => {
@@ -33,11 +36,10 @@ describe('relabel overseas API', () => {
expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/last-leg/relabel-applications/RL%2F1/status', { status: 'PROCESSING', remark: 'ok' })
})
it('loads ACTIVE overseas warehouses for the explicitly selected customer', async () => {
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: 1, size: 200, total: 0, pages: 0 } })
await listRelabelWarehouseOptions('10001')
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/warehouse-admin', {
params: { customerId: '10001', page: 1, size: 200, status: 'ACTIVE' },
})
it('loads shared ACTIVE OVERSEAS RECEIVING warehouses from the domestic candidate contract', async () => {
vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockResolvedValue([{ id: '200', warehouseCode: 'LAX', warehouseName: '洛杉矶仓', countryCode: 'US' }])
await expect(listRelabelWarehouseOptions()).resolves.toMatchObject({ records: [{ id: '200', customerId: '0', warehouseType: 'OVERSEAS', status: 'ACTIVE' }] })
expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce()
expect(overseasHttp.get).not.toHaveBeenCalledWith('/platform/v1/warehouse-admin', expect.anything())
})
})
@@ -1,5 +1,6 @@
import { overseasHttp } from '@/shared/api/overseasHttp'
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import { listSharedReceivingOverseasWarehouseOptions } from '@/modules/iam'
import { normalizeOverseasPage, type OverseasPagePayload } from './lastMileOrders'
export interface RelabelOrderQuery {
@@ -106,12 +107,16 @@ export async function getRelabelOrder(relabelNo: string) {
return unwrapApiResponse(response)
}
export async function listRelabelWarehouseOptions(customerId: string) {
const response = await overseasHttp.get<ApiEnvelope<OverseasPagePayload<RelabelWarehouseOptionDto>>, ApiEnvelope<OverseasPagePayload<RelabelWarehouseOptionDto>>>(
'/platform/v1/warehouse-admin',
{ params: { customerId, page: 1, size: 200, status: 'ACTIVE' } },
)
return normalizeOverseasPage(unwrapApiResponse(response))
export async function listRelabelWarehouseOptions() {
const records: RelabelWarehouseOptionDto[] = (await listSharedReceivingOverseasWarehouseOptions()).map((warehouse) => ({
id: warehouse.id,
customerId: '0',
warehouseCode: warehouse.warehouseCode,
warehouseName: warehouse.warehouseName,
warehouseType: 'OVERSEAS',
status: 'ACTIVE',
}))
return { records, page: 1, size: 200, total: records.length, pages: records.length ? 1 : 0 }
}
export async function createRelabelOrder(customerId: string, payload: CreateRelabelPayload) {