60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|||
|
|
import { http } from '@/api/http'
|
||
|
|
import {
|
||
|
|
changePlatformPartnerStatus,
|
||
|
|
createPlatformPartner,
|
||
|
|
listPlatformPartners,
|
||
|
|
updatePlatformPartner,
|
||
|
|
type SavePlatformPartnerRequest,
|
||
|
|
} from './platformPartners'
|
||
|
|
|
||
|
|
vi.mock('@/api/http', () => ({
|
||
|
|
http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() },
|
||
|
|
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
||
|
|
}))
|
||
|
|
|
||
|
|
const payload: SavePlatformPartnerRequest = {
|
||
|
|
partnerCode: 'CUS-001',
|
||
|
|
partnerName: '测试往来单位',
|
||
|
|
partnerType: 'CUSTOMER',
|
||
|
|
contactName: '测试联系人',
|
||
|
|
contactPhone: '13800000000',
|
||
|
|
contactEmail: null,
|
||
|
|
countryCode: 'CN',
|
||
|
|
province: '广东省',
|
||
|
|
city: '深圳市',
|
||
|
|
district: null,
|
||
|
|
addressLine: '测试地址 1 号',
|
||
|
|
postalCode: null,
|
||
|
|
status: 'ACTIVE',
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('platform partner API', () => {
|
||
|
|
beforeEach(() => vi.clearAllMocks())
|
||
|
|
|
||
|
|
it('queries the platform partner page with tenant and filters', async () => {
|
||
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: { records: [], page: '1', size: '20', total: '1', pages: '1' } })
|
||
|
|
|
||
|
|
const result = await listPlatformPartners(10001, { page: 1, size: 20, keyword: '测试', type: 'CUSTOMER', status: 'ACTIVE' })
|
||
|
|
|
||
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/partners', {
|
||
|
|
params: { tenantId: 10001, page: 1, size: 20, keyword: '测试', type: 'CUSTOMER', status: 'ACTIVE' },
|
||
|
|
})
|
||
|
|
expect(result).toMatchObject({ page: 1, size: 20, total: 1, pages: 1 })
|
||
|
|
})
|
||
|
|
|
||
|
|
it('uses the backend 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 createPlatformPartner(10001, payload)
|
||
|
|
await updatePlatformPartner(10001, '19001', payload)
|
||
|
|
await changePlatformPartnerStatus(10001, '19001', 'INACTIVE')
|
||
|
|
|
||
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/partners', payload, { params: { tenantId: 10001 } })
|
||
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/partners/19001', payload, { params: { tenantId: 10001 } })
|
||
|
|
expect(http.patch).toHaveBeenCalledWith('/platform/v1/partners/19001/status', { status: 'INACTIVE' }, { params: { tenantId: 10001 } })
|
||
|
|
})
|
||
|
|
})
|