import { beforeEach, describe, expect, it, vi } from 'vitest' import { readFileSync } from 'node:fs' import { resolve } from 'node:path' import { getCustomerOverseasStorageFees, updateCustomerOverseasStorageFees } from './overseasStorageFee' import { http } from '@/shared/api/http' const overseasListSource = readFileSync(resolve(process.cwd(), 'src/modules/customers/pages/OverseasStorageFeesView.vue'), 'utf8') const overseasPanelSource = readFileSync(resolve(process.cwd(), 'src/modules/customers/CustomerOverseasStorageFeePanel.vue'), 'utf8') vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn(), put: vi.fn() }, unwrapApiResponse: (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 overseas fee business actions as semantic buttons at narrow widths', () => { expect(overseasListSource).toContain('border stripe') expect(overseasListSource).toContain('size="small" plain type="primary"') expect(overseasListSource).toContain('size="small" plain type="danger"') expect(overseasListSource).toContain('') expect(overseasListSource).toContain('') expect(overseasListSource).toContain('') expect(overseasListSource).toContain('@media (max-width:720px)') expect(overseasPanelSource).toContain('size="small" plain type="danger"') expect(overseasPanelSource).toContain('@media (max-width:760px)') }) 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() }) })