40 lines
3.0 KiB
TypeScript
40 lines
3.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { http } from '@/shared/api/http'
|
|
import { changeSupplierStatus, createSupplier, getSupplier, getSupplierStats, listSuppliers, updateSupplier } from '@/modules/suppliers/api/platformSuppliers'
|
|
import type { SaveSupplierRequest } from '@/modules/suppliers/types'
|
|
|
|
vi.mock('@/shared/api/http', async (original) => ({
|
|
...await original<typeof import('@/shared/api/http')>(),
|
|
http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() },
|
|
}))
|
|
|
|
const payload: SaveSupplierRequest = { name: '测试供应商', category: 'BOOKING', scope: 'DOMESTIC', region: '宁波', legalRepresentative: '张三', contactName: '李四', phone: '13800000000', email: null, address: null, businessLicenseNo: null, licenseFileId: '9007199254740995', status: 'ACTIVE', settlementPeriod: 'MONTHLY_30', remark: null }
|
|
const resource = { id: 9007199254740993, tenantId: 0, ...payload, createdBy: 9007199254740994, createdAt: '2026-08-13T10:00:00', updatedBy: null, updatedAt: '2026-08-13T10:00:00', deleted: false, version: 1 }
|
|
|
|
describe('platform supplier API', () => {
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
it('uses real list and stats endpoints and preserves long identifiers as strings', async () => {
|
|
vi.mocked(http.get)
|
|
.mockResolvedValueOnce({ code: '200', data: { records: [resource], page: 1, size: 20, total: 1, pages: 1 } })
|
|
.mockResolvedValueOnce({ code: '200', data: { booking: 1, customs: 2, trucking: 3, certificate: 4 } })
|
|
const page = await listSuppliers({ page: 1, size: 20, category: 'BOOKING', scope: 'DOMESTIC', keyword: '测试' })
|
|
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/suppliers', { params: expect.objectContaining({ category: 'BOOKING', scope: 'DOMESTIC', keyword: '测试' }) })
|
|
expect(page.records[0]).toMatchObject({ id: expect.any(String), tenantId: '0', licenseFileId: expect.any(String), createdBy: expect.any(String) })
|
|
expect(await getSupplierStats()).toEqual({ booking: 1, customs: 2, trucking: 3, certificate: 4 })
|
|
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/suppliers/stats')
|
|
})
|
|
|
|
it('sends tenantId=0 on detail and every write', async () => {
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', data: resource })
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', data: '77' })
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', data: null })
|
|
vi.mocked(http.patch).mockResolvedValue({ code: '200', data: null })
|
|
await getSupplier('77'); await createSupplier(payload); await updateSupplier('77', payload); await changeSupplierStatus('77', 'INACTIVE')
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/suppliers/77', { params: { tenantId: 0 } })
|
|
expect(http.post).toHaveBeenCalledWith('/platform/v1/suppliers', payload, { params: { tenantId: 0 } })
|
|
expect(http.put).toHaveBeenCalledWith('/platform/v1/suppliers/77', payload, { params: { tenantId: 0 } })
|
|
expect(http.patch).toHaveBeenCalledWith('/platform/v1/suppliers/77/status', { status: 'INACTIVE' }, { params: { tenantId: 0 } })
|
|
})
|
|
})
|