This commit is contained in:
2026-08-06 18:02:04 +08:00
parent 16ab992c61
commit 08982b87ff
8 changed files with 213 additions and 138 deletions
@@ -20,7 +20,7 @@ import {
const payload = {
id: '9007199254740995',
tenantId: '10001',
tenantId: '0',
rateCode: 'RATE-US-WEST',
rateVersion: 2,
originWarehouseId: '20001',
@@ -48,38 +48,36 @@ const payload = {
describe('platformCarrierRates api', () => {
beforeEach(() => vi.clearAllMocks())
it('queries the real carrier-rate path and keeps every long id as a string', async () => {
it('queries the platform-wide carrier-rate path and keeps every long id as a string', async () => {
mocks.get.mockResolvedValue({ data: [payload] })
const result = await listPlatformCarrierRates({ customerId: ' 10001 ', rateCode: ' RATE-US ' })
const result = await listPlatformCarrierRates({ rateCode: ' RATE-US ' })
expect(mocks.get).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates', {
params: { tenantId: '10001', rateCode: 'RATE-US' },
params: { rateCode: 'RATE-US' },
})
expect(result[0]).toMatchObject({
id: '9007199254740995',
tenantId: '10001',
tenantId: '0',
originWarehouseId: '20001',
carrierId: '30001',
})
})
it('omits the compatibility tenant parameter for an all-customer list query', async () => {
it('omits the tenant parameter for the platform-wide list query', async () => {
mocks.get.mockResolvedValue({ data: [payload] })
await listPlatformCarrierRates()
await listPlatformCarrierRates({ customerId: '', rateCode: ' ' })
await listPlatformCarrierRates({ rateCode: ' ' })
expect(mocks.get).toHaveBeenNthCalledWith(1, '/platform/v1/fba-pricing/carrier-rates', { params: {} })
expect(mocks.get).toHaveBeenNthCalledWith(2, '/platform/v1/fba-pricing/carrier-rates', { params: {} })
})
it('loads a version detail with tenant scope', async () => {
it('loads a platform-wide version detail without tenant scope', async () => {
mocks.get.mockResolvedValue({ data: payload })
await getPlatformCarrierRate('10001', '9001')
expect(mocks.get).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/9001', {
params: { tenantId: '10001' },
})
await getPlatformCarrierRate('9001')
expect(mocks.get).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/9001')
})
it('creates immutable versions and retires an active version', async () => {
@@ -103,14 +101,10 @@ describe('platformCarrierRates api', () => {
remark: null,
}
await createPlatformCarrierRateVersion('10001', request)
await retirePlatformCarrierRate('10001', '9001')
await createPlatformCarrierRateVersion(request)
await retirePlatformCarrierRate('9001')
expect(mocks.post).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/versions', request, {
params: { tenantId: '10001' },
})
expect(mocks.delete).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/9001', {
params: { tenantId: '10001' },
})
expect(mocks.post).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/versions', request)
expect(mocks.delete).toHaveBeenCalledWith('/platform/v1/fba-pricing/carrier-rates/9001')
})
})
@@ -59,7 +59,6 @@ export interface CreatePlatformCarrierRateVersionRequest {
}
export interface PlatformCarrierRateQuery {
customerId?: string
rateCode?: string
}
@@ -87,38 +86,32 @@ function normalizeCarrierRate(value: PlatformCarrierRatePayload): PlatformCarrie
}
export async function listPlatformCarrierRates(query: PlatformCarrierRateQuery = {}) {
const customerId = query.customerId?.trim()
const rateCode = query.rateCode?.trim()
const response = await http.get<ApiEnvelope<PlatformCarrierRatePayload[]>, ApiEnvelope<PlatformCarrierRatePayload[]>>(
basePath,
{ params: { ...(customerId ? { tenantId: customerId } : {}), ...(rateCode ? { rateCode } : {}) } },
{ params: rateCode ? { rateCode } : {} },
)
return unwrapApiResponse(response).map(normalizeCarrierRate)
}
export async function getPlatformCarrierRate(tenantId: string, id: string) {
export async function getPlatformCarrierRate(id: string) {
const response = await http.get<ApiEnvelope<PlatformCarrierRatePayload>, ApiEnvelope<PlatformCarrierRatePayload>>(
`${basePath}/${id}`,
{ params: { tenantId } },
)
return normalizeCarrierRate(unwrapApiResponse(response))
}
export async function createPlatformCarrierRateVersion(
tenantId: string,
payload: CreatePlatformCarrierRateVersionRequest,
) {
const response = await http.post<ApiEnvelope<PlatformCarrierRatePayload>, ApiEnvelope<PlatformCarrierRatePayload>>(
`${basePath}/versions`,
payload,
{ params: { tenantId } },
)
return normalizeCarrierRate(unwrapApiResponse(response))
}
export async function retirePlatformCarrierRate(tenantId: string, id: string) {
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, {
params: { tenantId },
})
export async function retirePlatformCarrierRate(id: string) {
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`)
return unwrapApiResponse(response)
}