import { beforeEach, describe, expect, it, vi } from 'vitest' import { http } from '@/api/http' import { changePlatformExpressCompanyStatus, createPlatformExpressCompany, getPlatformExpressCompany, listPlatformExpressCompanies, updatePlatformExpressCompany, type SavePlatformExpressCompanyRequest, } from './platformExpressCompanies' vi.mock('@/api/http', () => ({ http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() }, unwrapApiResponse: (response: { data: T }) => response.data, })) const payload: SavePlatformExpressCompanyRequest = { companyCode: 'SF', companyName: '顺丰速运', servicePhone: '95338', website: 'https://www.sf-express.com', trackingUrlTemplate: 'https://example.com/track/{trackingNo}', status: 'ACTIVE', remark: null, } describe('platform express company API', () => { beforeEach(() => { vi.mocked(http.get).mockReset() vi.mocked(http.post).mockReset() vi.mocked(http.put).mockReset() vi.mocked(http.patch).mockReset() }) it('uses the implemented list and detail contracts', async () => { const page = { records: [], page: '1', size: '20', total: '0', pages: '0' } vi.mocked(http.get) .mockResolvedValueOnce({ code: '200', message: 'success', data: page }) .mockResolvedValueOnce({ code: '200', message: 'success', data: { id: '19001' } }) await expect(listPlatformExpressCompanies(10001, 2, 20, ' 顺丰 ', 'ACTIVE')).resolves.toEqual({ records: [], page: 1, size: 20, total: 0, pages: 0, }) await expect(getPlatformExpressCompany(10001, '19001')).resolves.toEqual({ id: '19001' }) expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/express-companies', { params: { tenantId: 10001, page: 2, size: 20, keyword: '顺丰', status: 'ACTIVE' }, }) expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/express-companies/19001', { params: { tenantId: 10001 }, }) }) it('uses the implemented create, update, and status contracts', async () => { vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: '19001' }) vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: null }) vi.mocked(http.patch).mockResolvedValue({ code: '200', message: 'success', data: null }) await expect(createPlatformExpressCompany(10001, payload)).resolves.toBe('19001') await expect(updatePlatformExpressCompany(10001, '19001', payload)).resolves.toBeNull() await expect(changePlatformExpressCompanyStatus(10001, '19001', 'INACTIVE')).resolves.toBeNull() expect(http.post).toHaveBeenCalledWith('/platform/v1/express-companies', payload, { params: { tenantId: 10001 } }) expect(http.put).toHaveBeenCalledWith('/platform/v1/express-companies/19001', payload, { params: { tenantId: 10001 } }) expect(http.patch).toHaveBeenCalledWith( '/platform/v1/express-companies/19001/status', { status: 'INACTIVE' }, { params: { tenantId: 10001 } }, ) }) })