feat(fleet): connect operations quotes costs and handover workspaces
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { listTripHandovers, previewTripHandover, confirmTripHandover, releaseHandoverResource, handoverVersion } from './tripHandovers'
|
||||
vi.mock('@/shared/api/http', async original => ({ ...(await original<typeof import('@/shared/api/http')>()), http: { get: vi.fn(), post: vi.fn() } }))
|
||||
beforeEach(() => vi.clearAllMocks())
|
||||
it('encodes trip scope and normalizes pagination without per-row requests', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [], page: '1', size: '10', total: '0', pages: '0' } })
|
||||
expect(await listTripHandovers('TR/ONE')).toEqual({ records: [], page: 1, size: 10, total: 0, pages: 0 })
|
||||
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/fleet/trips/TR%2FONE/handovers', { params: { page: 1, size: 10 } })
|
||||
})
|
||||
it('keeps preview separate from the exact immutable confirmation payload', async () => {
|
||||
vi.mocked(http.post).mockResolvedValue({ code: '200', data: {} })
|
||||
const selection = { recordVersion: 7, vehicleId: '90071992547409931', driverId: '90071992547409932', handedOverAt: '2026-10-03T01:00:00Z', expectedDriverEndAt: '2026-10-04T01:00:00Z' }
|
||||
await previewTripHandover('TR-ONE', selection)
|
||||
const command = { selection, cargoHash: 'a'.repeat(64), location: '交接点', idempotencyKey: 'original-key' }
|
||||
await confirmTripHandover('TR-ONE', command)
|
||||
expect(http.post).toHaveBeenNthCalledWith(1, '/platform/v1/last-leg/fleet/trips/TR-ONE/handovers/preview', selection)
|
||||
expect(http.post).toHaveBeenNthCalledWith(2, '/platform/v1/last-leg/fleet/trips/TR-ONE/handovers', command)
|
||||
})
|
||||
it('ends only the selected old resource within its handover and trip', async () => {
|
||||
vi.mocked(http.post).mockResolvedValue({ code: '200', data: {} })
|
||||
const command = { recordVersion: 0, resourceKind: 'DRIVER' as const, actualEndAt: '2026-10-03T02:00:00Z', location: '司机任务结束点', idempotencyKey: 'end-original' }
|
||||
await releaseHandoverResource('TR-ONE', 'HO/ONE', command)
|
||||
expect(http.post).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/fleet/trips/TR-ONE/handovers/HO%2FONE/resources/release', command)
|
||||
})
|
||||
it('refuses blank fractional or unsafe versions', () => {
|
||||
for (const value of ['', ' ', '1.5', '90071992547409931']) expect(() => handoverVersion(value)).toThrow()
|
||||
})
|
||||
Reference in New Issue
Block a user