From 91edf0c565faae9e6fced7af7112622a0a52b86f Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 23 Nov 2026 14:56:18 +0100 Subject: [PATCH] fix(mail-ingest): announce a place a mail created with its whole row The open planners of the trip received only the new place's id and kept a nameless place without coordinates until a reload. The broadcast now carries the row the place routes send. --- .../mail-ingest/mail-ingest-apply.service.ts | 6 +- .../mail-ingest/mail-ingest.pipeline.test.ts | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/server/src/nest/mail-ingest/mail-ingest-apply.service.ts b/server/src/nest/mail-ingest/mail-ingest-apply.service.ts index b4a92eb3c..700cfc2f5 100644 --- a/server/src/nest/mail-ingest/mail-ingest-apply.service.ts +++ b/server/src/nest/mail-ingest/mail-ingest-apply.service.ts @@ -43,6 +43,7 @@ const FINGERPRINT_KEYS = [ 'metadata', ] as const; type Written = Awaited>; +type CreatedPlace = Awaited>; /** A booking ready to write: everything that needs the network (geocoding, the frozen rate) is done. */ export interface PreparedBooking { @@ -59,7 +60,8 @@ export interface PreparedBooking { export interface WrittenBooking { tripId: number; reservation: Written['reservation']; - place: { id: number } | null; + /** The place the write created, as the place routes announce it. */ + place: CreatedPlace | null; accommodationCreated: boolean; costEvents: CostEvent[]; stayMirror: Written['stayMirror']; @@ -137,7 +139,7 @@ export class MailIngestApplyService { return { tripId: prepared.tripId, reservation: written.reservation, - place: place ? { id: place.id } : null, + place, accommodationCreated: written.accommodationCreated, costEvents: written.costEvents, stayMirror: written.stayMirror, diff --git a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts index bd7f6967d..44ddd11fd 100644 --- a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts +++ b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts @@ -504,6 +504,61 @@ describe('the AI’s trip pick', () => { }); }); +describe('what a mail names', () => { + const RETURN: BookingImportPreviewItem = { + ...FLIGHT, + title: 'LH 717 Osaka to Tokyo', + reservation_time: '2030-03-08T18:00', + reservation_end_time: '2030-03-08T19:10', + metadata: { flight_number: 'LH717' }, + endpoints: [ + endpoint('from', 'Osaka Itami', 'ITM', 34.78, 135.44), + endpoint('to', 'Tokyo Haneda', 'HND', 35.55, 139.78), + ], + }; + const DINNER: BookingImportPreviewItem = { + type: 'restaurant', + title: 'Dinner at Sora', + reservation_time: '2030-03-03T19:00', + _venue: { name: 'Sora', lat: 34.7, lng: 135.5 }, + source: { fileName: 'mail.eml', index: 1 }, + }; + const BOTH = `${BODY} Return flight LH 717 from Osaka to Tokyo on 2030-03-08. Dinner at Sora.`; + + /** The AI reads the mail as one booking whose reservations map to these items. */ + function aiReads(items: BookingImportPreviewItem[]): void { + reader.isAvailable.mockResolvedValue(true); + bookingImport.mapAiReservations.mockResolvedValueOnce(items.map((item) => ({ ...item }))); + aiRead.mockResolvedValue({ + outcome: 'ok', + documentText: BOTH, + imageOnly: false, + bookings: [ + { + kind: 'new_booking', + reservations: [{ '@type': 'FlightReservation' }], + tripRef: null, + tripConfidence: 0.9, + uncertainFields: [], + suggestedNewTrip: null, + }, + ], + } as AiReading); + } + + it('announces the place it created as the place routes do, with its name and position', async () => { + const user = await person(); + const trip = await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' }); + machine.mockResolvedValue([DINNER]); + + await forward(user.id, eml('dinner', 'Fwd: Your table', BOTH)); + expect(t.realtime.broadcastMock).toHaveBeenCalledWith(trip.id, 'place:created', { + place: expect.objectContaining({ id: expect.any(Number), name: 'Sora', lat: 34.7, lng: 135.5 }), + }); + }); + +}); + describe('a mail that keeps failing', () => { it('is tried again later and given up after its last try', async () => { const user = await person();