Release/test 合并上生产 #2
@@ -1,8 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { createTruckAppointment, getTruckAppointment, listTruckAppointments, performTruckAppointmentAction } from './platformTrucking'
|
||||
import { createTruckAppointment, deleteTruckAppointmentAttachment, getTruckAppointment, listTruckAppointmentAttachments, listTruckAppointmentHistory, listTruckAppointments, performTruckAppointmentAction, referenceTruckAppointmentAttachment } from './platformTrucking'
|
||||
|
||||
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() }, unwrapApiResponse: (response: { data: unknown }) => response.data }))
|
||||
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn() }, unwrapApiResponse: (response: { data: unknown }) => response.data }))
|
||||
|
||||
describe('truck appointment API', () => {
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
@@ -22,4 +22,22 @@ describe('truck appointment API', () => {
|
||||
await expect(performTruckAppointmentAction('9001', 'DISPATCH', 2)).resolves.toMatchObject({ status: 'DISPATCHED' })
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/v1/truck-appointments/9001/dispatch', { expectedVersion: 2, reason: null }, { headers: {} })
|
||||
})
|
||||
|
||||
it('uses scoped attachment and immutable history contracts', async () => {
|
||||
vi.mocked(http.get)
|
||||
.mockResolvedValueOnce({ data: [{ id: 1, fileId: 9007199254740993, fileName: '派车单.pdf' }] })
|
||||
.mockResolvedValueOnce({ data: [{ id: 2, action: 'DISPATCH', fromStatus: 'PENDING_DISPATCH', toStatus: 'DISPATCHED', operatorId: 3 }] })
|
||||
vi.mocked(http.post).mockResolvedValue({ data: { id: '1', fileId: '9007199254740993', fileName: '派车单.pdf' } })
|
||||
vi.mocked(http.delete).mockResolvedValue({ data: null })
|
||||
|
||||
await expect(listTruckAppointmentAttachments('77')).resolves.toMatchObject([{ id: '1', fileName: '派车单.pdf' }])
|
||||
await expect(listTruckAppointmentHistory('77')).resolves.toMatchObject([{ id: '2', operatorId: '3', action: 'DISPATCH' }])
|
||||
await referenceTruckAppointmentAttachment('77', { fileId: '9007199254740993', fileName: '派车单.pdf' })
|
||||
await deleteTruckAppointmentAttachment('77', '1')
|
||||
|
||||
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/truck-appointments/77/attachments')
|
||||
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/truck-appointments/77/history')
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/v1/truck-appointments/77/attachments', { fileId: '9007199254740993', fileName: '派车单.pdf' })
|
||||
expect(http.delete).toHaveBeenCalledWith('/platform/v1/truck-appointments/77/attachments/1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ export async function listTruckAppointmentAttachments(id: string | number) {
|
||||
}
|
||||
|
||||
export async function referenceTruckAppointmentAttachment(id: string | number, payload: { fileId: string; attachmentType?: string | null; fileName?: string | null; fileHash?: string | null }) {
|
||||
const response = await http.post<ApiEnvelope<TruckAttachmentReference>, ApiEnvelope<TruckAttachmentReference>>(`${basePath}/${id}/attachments`, { ...payload, fileId: Number(payload.fileId) })
|
||||
const response = await http.post<ApiEnvelope<TruckAttachmentReference>, ApiEnvelope<TruckAttachmentReference>>(`${basePath}/${id}/attachments`, payload)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user