Files
admin-web/src/modules/customers/overseasStorageFee.test.ts
T
2026-08-08 14:41:17 +08:00

38 lines
2.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import { getCustomerOverseasStorageFees, updateCustomerOverseasStorageFees } from './overseasStorageFee'
import { http } from '@/shared/api/http'
vi.mock('@/shared/api/http', () => ({
http: { get: vi.fn(), put: vi.fn() },
unwrapApiResponse: <T>(response: { data: T }) => response.data,
}))
const config = { id: 12, customerId: 9007199254740993n.toString(), customerName: '客户', currency: 'USD', tiers: [], version: 0, createdAt: null, updatedAt: null }
describe('customer overseas storage fee api', () => {
beforeEach(() => vi.clearAllMocks())
it('keeps customer ids as strings and uses the customer detail path', async () => {
vi.mocked(http.get).mockResolvedValue({ data: config })
const result = await getCustomerOverseasStorageFees(config.customerId)
expect(http.get).toHaveBeenCalledWith(`/platform/v1/iam/tenants/${config.customerId}/overseas-storage-fees`)
expect(result.id).toBe('12')
expect(result.customerId).toBe(config.customerId)
})
it('submits the complete group and reloads the new version', async () => {
vi.mocked(http.put).mockResolvedValue({ data: null })
vi.mocked(http.get).mockResolvedValue({ data: { ...config, version: 1 } })
const request = { customerId: config.customerId, customerName: '客户', currency: 'CNY', version: 0, tiers: [{ feeType: 'STORAGE' as const, billingUnit: 'CBM' as const, startDay: 1, endDay: null, unitPrice: 0 }] }
const result = await updateCustomerOverseasStorageFees(config.customerId, request)
expect(http.put).toHaveBeenCalledWith(`/platform/v1/iam/tenants/${config.customerId}/overseas-storage-fees`, request)
expect(result.version).toBe(1)
})
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)
expect(result.tiers[0]?.endDay).toBeNull()
})
})