接入前端P0页面真实接口

This commit is contained in:
andy
2026-07-08 16:20:06 +08:00
parent 5c5b8e33b0
commit 66a613d6cd
45 changed files with 8719 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
EndpointPendingError,
fetchReservationOrderDetail,
fetchReservationOrders,
fetchReservationTaskDetail,
fetchReservationTaskList,
fetchSourceMessageConversation,
} from '@/services/reservationService'
const jsonHeaders = {
headers: {
get: (name: string) => (name.toLowerCase() === 'content-type' ? 'application/json' : null),
},
}
function mockJsonResponse(payload: unknown): Response {
return {
ok: true,
status: 200,
json: async () => payload,
text: async () => JSON.stringify(payload),
...jsonHeaders,
} as Response
}
describe('reservationService real API mode', () => {
beforeEach(() => {
vi.restoreAllMocks()
})
it('fetches the task list from the backend by default', async () => {
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
mockJsonResponse({
items: [
{
task_id: '10001',
order_id: '20001',
hotel_id: 'HOTEL-TEST',
display_order_key: 'GRP-001',
temporary_order_no: null,
task_type: 'NEW_BOOKING',
task_subtype: 'NEW_BOOKING',
task_status: 'PENDING_CONFIRM',
card_name: 'New Booking',
queue_sequence: 1,
queue_participation: true,
can_process: true,
readonly_reason_code: null,
source_message_id: '30001',
source_subject: 'Booking Request',
created_at: '2026-07-08T03:00:00Z',
updated_at: '2026-07-08T03:10:00Z',
},
],
page: {
page_num: 1,
page_size: 20,
total: 1,
},
}),
)
const result = await fetchReservationTaskList({
task_status: 'PENDING_CONFIRM',
page_num: 1,
page_size: 20,
})
expect(fetchMock).toHaveBeenCalledWith(
'/api/reservation/tasks?task_status=PENDING_CONFIRM&page_num=1&page_size=20',
expect.objectContaining({ method: 'GET' }),
)
expect(result.items).toHaveLength(1)
expect(result.items[0]?.source_subject).toBe('Booking Request')
})
it('fetches order detail from the backend by default', async () => {
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
mockJsonResponse({
order: {
order_id: '20001',
hotel_id: 'HOTEL-TEST',
order_status: 'ACTIVE',
temporary_order_no: null,
confirmation_number: 'CNF123456',
group_code: 'GRP-001',
block_code: null,
allotment_code: null,
display_name: 'GRP-001',
created_at: '2026-07-08T03:00:00Z',
updated_at: '2026-07-08T03:10:00Z',
},
tasks: [],
warnings: [],
}),
)
const result = await fetchReservationOrderDetail('20001')
expect(fetchMock).toHaveBeenCalledWith(
'/api/reservation/orders/20001?include_tasks=true&include_source_summary=true',
expect.objectContaining({ method: 'GET' }),
)
expect(result.order.display_name).toBe('GRP-001')
})
it('fetches task detail from the backend by default', async () => {
const fetchMock = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
mockJsonResponse({
task_id: '10001',
order_id: '20001',
source_message_id: '30001',
system_task_type: 'NEW_BOOKING',
task_card_type: 'NEW_BOOKING',
task_status: 'PENDING_CONFIRM',
field_contract_version: '20260708-3.0',
draft_payload: null,
confirmed_payload: null,
availability: {
blocked: false,
read_only: false,
editable: true,
confirmable: true,
executable: false,
blocked_by_task_id: null,
blocked_reason: null,
},
fields: [],
opera_operations: [],
}),
)
const result = await fetchReservationTaskDetail('10001')
expect(fetchMock).toHaveBeenCalledWith(
'/api/reservation/tasks/10001',
expect.objectContaining({ method: 'GET' }),
)
expect(result.task_id).toBe('10001')
})
it('marks order list as pending instead of returning fixture data', async () => {
await expect(fetchReservationOrders()).rejects.toBeInstanceOf(EndpointPendingError)
})
it('marks source message conversation as pending instead of returning fixture data', async () => {
await expect(fetchSourceMessageConversation('30001')).rejects.toBeInstanceOf(EndpointPendingError)
})
})