mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(booking-import): import a booking the document calls confirmed as confirmed
The mail import already wrote a booking as confirmed when its metadata held reservationStatus, but nothing ever filled that field: the KItinerary mapper dropped schema.org's reservationStatus, the AI reading was neither asked for it nor given it in its response schema (a schema-bound provider fills declared properties only), and the review form, the file import confirm path and the assistant's import card all started every booking as pending. The mapper now reads reservationStatus from every node, schema.org URL, bare ReservationConfirmed or a plain word alike, and keeps it in the item's metadata as TREK's word. The AI prompt and response schema ask for it. One shared helper turns it into the status a booking is saved with: confirmed when the document said so, pending otherwise, so a cancellation or an unknown value still lands as pending. The review form prefill, the mail import, the confirm path and the assistant card all use it. Closes #3238
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { BookingImportPreviewItem } from '@trek/shared';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { parsedItemToDraft } from './parsedItemToDraft';
|
||||
|
||||
const item = (metadata?: Record<string, unknown>): BookingImportPreviewItem => ({
|
||||
type: 'flight',
|
||||
title: 'Kuala Lumpur to Bangkok',
|
||||
metadata,
|
||||
source: { fileName: 'airasia.eml', index: 0 },
|
||||
});
|
||||
|
||||
describe('parsedItemToDraft', () => {
|
||||
// #3238: the review form opens with the status the document states.
|
||||
it('FE-PARSED-DRAFT-001: a booking the document calls confirmed opens confirmed, anything else pending', () => {
|
||||
expect(parsedItemToDraft(item({ reservationStatus: 'confirmed' })).status).toBe('confirmed');
|
||||
expect(parsedItemToDraft(item({ reservationStatus: 'cancelled' })).status).toBe('pending');
|
||||
expect(parsedItemToDraft(item({ reservationStatus: 'pending' })).status).toBe('pending');
|
||||
expect(parsedItemToDraft(item()).status).toBe('pending');
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BookingImportPreviewItem, Reservation, ReservationEndpoint } from '@trek/shared'
|
||||
import { importedReservationStatus, type BookingImportPreviewItem, type Reservation, type ReservationEndpoint } from '@trek/shared'
|
||||
|
||||
/**
|
||||
* A pre-fill draft for the reservation/transport edit modals built from a parsed
|
||||
@@ -29,7 +29,8 @@ export function parsedItemToDraft(item: BookingImportPreviewItem): BookingReview
|
||||
return {
|
||||
type: item.type,
|
||||
title: item.title,
|
||||
status: 'pending',
|
||||
// Confirmed when the document said so, pending otherwise (#3238).
|
||||
status: importedReservationStatus(item.metadata),
|
||||
reservation_time: item.reservation_time ?? null,
|
||||
reservation_end_time: item.reservation_end_time ?? null,
|
||||
location: item.location ?? item._venue?.address ?? item._venue?.name ?? null,
|
||||
|
||||
Reference in New Issue
Block a user