From a63e16fb65548f8c46333a0a62514e8aae426638 Mon Sep 17 00:00:00 2001 From: jubnl Date: Thu, 18 Jun 2026 14:12:41 +0200 Subject: [PATCH] fix(airtrail): don't use cabin class as seat on import When an AirTrail flight has a cabin class but no seat number, the mapper fell back to the class for metadata.seat, so reservations showed e.g. "economy" as the seat. Use only the seat number; leave the seat blank otherwise. The class is still surfaced separately in the import picker. Closes #1246 --- .../src/services/airtrail/airtrailMapper.ts | 2 +- .../unit/services/airtrailMapper.test.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/server/src/services/airtrail/airtrailMapper.ts b/server/src/services/airtrail/airtrailMapper.ts index e7ee158a..7d614b25 100644 --- a/server/src/services/airtrail/airtrailMapper.ts +++ b/server/src/services/airtrail/airtrailMapper.ts @@ -147,7 +147,7 @@ export function mapFlightToReservation(raw: AirtrailFlightRaw): MappedReservatio if (aircraftCode) metadata.aircraft = aircraftCode; if (raw.aircraftReg) metadata.aircraft_reg = raw.aircraftReg; if (raw.flightReason) metadata.flight_reason = raw.flightReason; - if (seat?.seatNumber || seat?.seatClass) metadata.seat = seat.seatNumber || seat.seatClass; + if (seat?.seatNumber) metadata.seat = seat.seatNumber; // The flight number already carries the airline prefix (e.g. "SAS983"), so it // makes the clearest title; fall back to the route. diff --git a/server/tests/unit/services/airtrailMapper.test.ts b/server/tests/unit/services/airtrailMapper.test.ts index dd808141..f4bc381e 100644 --- a/server/tests/unit/services/airtrailMapper.test.ts +++ b/server/tests/unit/services/airtrailMapper.test.ts @@ -88,6 +88,26 @@ describe('airtrailMapper.mapFlightToReservation', () => { expect(m.notes).toBe('window seat'); }); + it('uses only the seat number for the seat, not the cabin class (#1246)', () => { + // AirTrail often has a class but no seat number until check-in; the class + // must not leak into the seat field. + const m = mapFlightToReservation( + flight({ seats: [{ userId: 'u1', guestName: null, seat: null, seatNumber: null, seatClass: 'economy' }] }), + ); + expect(m.metadata).not.toHaveProperty('seat'); + }); + + it('keeps the seat number when present even with no class', () => { + const m = mapFlightToReservation( + flight({ seats: [{ userId: 'u1', guestName: null, seat: null, seatNumber: '3F', seatClass: null }] }), + ); + expect(m.metadata).toMatchObject({ seat: '3F' }); + }); + + it('omits the seat for a flight with no seats', () => { + expect(mapFlightToReservation(flight({ seats: [] })).metadata).not.toHaveProperty('seat'); + }); + it('flags needs_review for a non-day date precision', () => { expect(mapFlightToReservation(flight({ datePrecision: 'month' })).needs_review).toBe(1); });