优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { appendCarrierScheduleManualNode, getCarrierScheduleQuery, listCarrierScheduleQueries } from './platformCarrierScheduleQueries'
|
||||
import { appendCarrierScheduleManualNode, ensureCarrierScheduleQueryForContainer, getCarrierScheduleQuery, listCarrierScheduleQueries } from './platformCarrierScheduleQueries'
|
||||
|
||||
vi.mock('@/shared/api/http', async () => {
|
||||
const actual = await vi.importActual<typeof import('@/shared/api/http')>('@/shared/api/http')
|
||||
@@ -61,4 +61,11 @@ describe('platformCarrierScheduleQueries', () => {
|
||||
await appendCarrierScheduleManualNode('9007199254740993', 'manual-session-key', request)
|
||||
expect(vi.mocked(http.post)).toHaveBeenCalledWith('/platform/v1/carrier-schedule-queries/9007199254740993/manual-nodes', request, { headers: { 'Idempotency-Key': 'manual-session-key' } })
|
||||
})
|
||||
|
||||
it('ensures a missing departed-container task before manual entry', async () => {
|
||||
const detail = { query: { query: { ...query, customerId: 0 }, expired: false }, nodes: [], exceptions: [], histories: [] }
|
||||
vi.mocked(http.post).mockResolvedValue({ code: '200', data: detail })
|
||||
await expect(ensureCarrierScheduleQueryForContainer('303', 'ensure-key')).resolves.toMatchObject({ query: { query: { customerId: '0', containerBookingId: '303' } } })
|
||||
expect(vi.mocked(http.post)).toHaveBeenCalledWith('/platform/v1/carrier-schedule-queries/containers/303/ensure', null, { headers: { 'Idempotency-Key': 'ensure-key' } })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -56,6 +56,16 @@ export async function getCarrierScheduleQuery(queryId: string): Promise<CarrierS
|
||||
return { ...result, query: view(result.query), nodes: (result.nodes || []).map(node), exceptions: (result.exceptions || []).map(exception), histories: (result.histories || []).map(history) }
|
||||
}
|
||||
|
||||
export async function ensureCarrierScheduleQueryForContainer(containerBookingId: string, idempotencyKey: string): Promise<CarrierScheduleQueryDetail> {
|
||||
const response = await http.post<ApiEnvelope<CarrierScheduleQueryDetail>, ApiEnvelope<CarrierScheduleQueryDetail>>(
|
||||
`${basePath}/containers/${encodeURIComponent(containerBookingId)}/ensure`,
|
||||
null,
|
||||
{ headers: { 'Idempotency-Key': idempotencyKey } },
|
||||
)
|
||||
const result = unwrapApiResponse(response)
|
||||
return { ...result, query: view(result.query), nodes: (result.nodes || []).map(node), exceptions: (result.exceptions || []).map(exception), histories: (result.histories || []).map(history) }
|
||||
}
|
||||
|
||||
export async function appendCarrierScheduleManualNode(queryId: string, idempotencyKey: string, request: CarrierScheduleManualNodeRequest): Promise<CarrierScheduleQueryDetail> {
|
||||
const response = await http.post<ApiEnvelope<CarrierScheduleQueryDetail>, ApiEnvelope<CarrierScheduleQueryDetail>>(
|
||||
`${basePath}/${encodeURIComponent(queryId)}/manual-nodes`,
|
||||
|
||||
Reference in New Issue
Block a user