1
This commit is contained in:
@@ -9,7 +9,14 @@ const overseasPanelSource = readFileSync(resolve(process.cwd(), 'src/modules/cus
|
||||
|
||||
vi.mock('@/shared/api/http', () => ({
|
||||
http: { get: vi.fn(), put: vi.fn() },
|
||||
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
||||
unwrapApiResponse: <T>(response: { data: T }) => {
|
||||
const value = response.data as T & { code?: string; message?: string; data?: unknown }
|
||||
if (value && typeof value === 'object' && 'code' in value) {
|
||||
if (value.code !== '200') throw new Error(value.message || 'request failed')
|
||||
return value.data as T
|
||||
}
|
||||
return value
|
||||
},
|
||||
}))
|
||||
|
||||
const config = { id: 12, customerId: 9007199254740993n.toString(), customerName: '客户', currency: 'USD', tiers: [], version: 0, createdAt: null, updatedAt: null }
|
||||
@@ -46,6 +53,19 @@ describe('customer overseas storage fee api', () => {
|
||||
expect(result.version).toBe(1)
|
||||
})
|
||||
|
||||
it('rejects a business error returned by the update endpoint', async () => {
|
||||
vi.mocked(http.put).mockResolvedValue({ data: { code: 'A0400', message: '璇锋眰鏃犳晥', data: null } })
|
||||
|
||||
await expect(updateCustomerOverseasStorageFees(config.customerId, {
|
||||
customerId: config.customerId,
|
||||
customerName: '瀹㈡埛',
|
||||
currency: 'USD',
|
||||
version: 0,
|
||||
tiers: [{ feeType: 'STORAGE', billingUnit: 'CBM', startDay: 1, endDay: null, unitPrice: 0 }],
|
||||
})).rejects.toThrow('璇锋眰鏃犳晥')
|
||||
expect(http.get).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('normalizes an omitted end day as an open-ended tier', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({ data: { ...config, tiers: [{ id: 1, startDay: 91, unitPrice: 2, sortNo: 5, feeType: 'STORAGE', billingUnit: 'CBM' }] } })
|
||||
const result = await getCustomerOverseasStorageFees(config.customerId)
|
||||
|
||||
@@ -55,7 +55,8 @@ export async function getCustomerOverseasStorageFees(tenantId: string) {
|
||||
}
|
||||
|
||||
export async function updateCustomerOverseasStorageFees(tenantId: string, request: OverseasStorageFeeUpdateRequest) {
|
||||
await http.put<never, ApiEnvelope<null>>(path(tenantId), request)
|
||||
const response = await http.put<never, ApiEnvelope<null>>(path(tenantId), request)
|
||||
unwrapApiResponse(response)
|
||||
return getCustomerOverseasStorageFees(tenantId)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user