mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
fix(airtrail): read and write the passenger list under both its names
AirTrail 3.12.0 renamed the flight's passenger list from `seats` to `passengers` and moved flightReason from the flight onto each passenger. There is no alias in either direction: a 3.12.0 instance returns `passengers` and `null` for `seats`, and its save schema accepts only `passengers`. TREK read `raw.seats` everywhere, so against a 3.12.0 instance it found nothing. The seat never made it into the import, and because a pull rebuilds the metadata from the AirTrail payload, flights that had already been imported lost the seat they had. That is the report. Flights whose sync is switched off were never re-pulled, which is why theirs survived. Two more breaks came from the same rename and were not reported. The flight reason stopped importing for the same reason. And the writeback pushed the seat under `seats`, which the new schema strips, so a seat edited in TREK was quietly dropped on the way out; it did not fail loudly because the spread of the fetched flight carried AirTrail's own `passengers` through untouched. Both shapes are handled rather than switched between, because instances on 3.11 and older are still out there: reads take `passengers ?? seats`, and the save body carries the manifest under both keys. Neither schema is strict, so each version keeps the key it knows and strips the other. The snapshot hash deliberately keeps feeding the manifest in under the same key. An unchanged flight on an older instance therefore hashes exactly as before and does not re-sync, while a 3.12.0 flight hashes differently once and pulls the missing seat back in. There is a pinned-hash test guarding the first half. Verified against real instances rather than the docs: a 3.11.1 and a 3.12.0 container, seat imported from each, a seat edited in TREK written back and read out of AirTrail again, and the pre-fix build failing the same checks on 3.12.0. Closes #1931
This commit is contained in:
@@ -309,3 +309,68 @@ describe('airtrailMapper.mapFlightsToMultiLegReservation (#1535)', () => {
|
||||
expect(mapFlightsToMultiLegReservation([flight()])).toEqual(mapFlightToReservation(flight()));
|
||||
});
|
||||
});
|
||||
|
||||
// AirTrail 3.12.0 renamed the passenger list from `seats` to `passengers` and
|
||||
// moved flightReason from the flight onto each passenger, with no alias either
|
||||
// way (#1931). The shapes below are the ones a real 3.12.0 and a real 3.11.1
|
||||
// return: each sends its own key and null for the other.
|
||||
describe('airtrailMapper — AirTrail 3.12.0 passengers', () => {
|
||||
const newShape = (over: Partial<AirtrailFlightRaw> = {}) =>
|
||||
flight({
|
||||
seats: null as never,
|
||||
flightReason: null,
|
||||
passengers: [{ userId: 'u1', guestName: null, seat: 'window', seatNumber: '12A', seatClass: 'economy', flightReason: 'business' }],
|
||||
...over,
|
||||
});
|
||||
|
||||
it('reads the seat off passengers', () => {
|
||||
expect(mapFlightToReservation(newShape()).metadata.seat).toBe('12A');
|
||||
});
|
||||
|
||||
it('reads the seat class off passengers', () => {
|
||||
expect(normalizeFlight(newShape()).seatClass).toBe('economy');
|
||||
});
|
||||
|
||||
it('takes the flight reason off the passenger now that the flight has none', () => {
|
||||
expect(mapFlightToReservation(newShape()).metadata.flight_reason).toBe('business');
|
||||
});
|
||||
|
||||
it('prefers the entry belonging to the key owner over a co-passenger', () => {
|
||||
const m = mapFlightToReservation(newShape({
|
||||
passengers: [
|
||||
{ userId: null, guestName: 'Plus One', seat: null, seatNumber: '30C', seatClass: null },
|
||||
{ userId: 'u1', guestName: null, seat: 'window', seatNumber: '12A', seatClass: 'economy' },
|
||||
],
|
||||
}));
|
||||
expect(m.metadata.seat).toBe('12A');
|
||||
});
|
||||
|
||||
it('still reads the old shape, so an older instance keeps working', () => {
|
||||
const m = mapFlightToReservation(flight());
|
||||
expect(m.metadata.seat).toBe('12A');
|
||||
expect(m.metadata.flight_reason).toBe('leisure');
|
||||
});
|
||||
|
||||
it('carries the per-leg seat through the multi-leg mapping', () => {
|
||||
const legs = mapFlightsToMultiLegReservation([
|
||||
newShape({ id: 1 }),
|
||||
newShape({ id: 2, passengers: [{ userId: 'u1', guestName: null, seat: null, seatNumber: '3F', seatClass: null }] }),
|
||||
]).metadata.legs as any[];
|
||||
expect(legs.map(l => l.seat)).toEqual(['12A', '3F']);
|
||||
});
|
||||
|
||||
// The snapshot hash decides whether a pull re-imports a flight. Feeding it from
|
||||
// either shape under the same key keeps an unchanged old-shape flight hashing
|
||||
// exactly as before, so upgrading TREK must not re-sync every flight.
|
||||
it('leaves the hash of an unchanged old-shape flight alone', () => {
|
||||
// Pinned to what the pre-#1931 snapshot produced for this fixture. If this
|
||||
// ever has to be re-pinned, every existing AirTrail flight re-syncs once.
|
||||
expect(canonicalHash(flight())).toBe('81d00fb3b22dffa5575221f73c959f5762e50e20e9c5cf7ecc5a485a1845b358');
|
||||
});
|
||||
|
||||
it('hashes the new shape as the same flight as the old one', () => {
|
||||
const asOld = flight({ flightReason: 'business' });
|
||||
const asNew = newShape();
|
||||
expect(canonicalHash(asNew)).toBe(canonicalHash(asOld));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -183,3 +183,64 @@ describe('airtrailSync.buildSavePayload', () => {
|
||||
expect(payload).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// AirTrail 3.12.0 renamed the passenger list from `seats` to `passengers`, with
|
||||
// no alias on the save endpoint either (#1931). Neither schema is strict, so the
|
||||
// payload carries both names and each version keeps the one it knows.
|
||||
describe('airtrailSync.buildSavePayload — AirTrail 3.12.0 passengers', () => {
|
||||
const newShape = (over: Partial<AirtrailFlightRaw> & Record<string, unknown> = {}) =>
|
||||
existingFlight({
|
||||
seats: undefined,
|
||||
flightReason: undefined,
|
||||
passengers: [{ userId: 'u1', guestName: null, seat: 'window', seatNumber: '12A', seatClass: 'economy', flightReason: 'leisure' }],
|
||||
...over,
|
||||
});
|
||||
|
||||
const own = (list: unknown) => (list as Array<{ userId: string | null }>).find(s => s.userId);
|
||||
|
||||
it('sends the manifest under both names', () => {
|
||||
const payload = buildSavePayload(reservation(), newShape()) as SavePayloadWithPassthrough;
|
||||
expect(payload.passengers).toEqual(payload.seats);
|
||||
expect(own(payload.passengers)).toMatchObject({ seatNumber: '12A', seatClass: 'economy' });
|
||||
});
|
||||
|
||||
it('reads the existing manifest off passengers and pushes the TREK seat onto it', () => {
|
||||
const res = reservation({ metadata: JSON.stringify({ seat: '22F' }) });
|
||||
const payload = buildSavePayload(res, newShape()) as SavePayloadWithPassthrough;
|
||||
expect(own(payload.passengers)).toMatchObject({ seatNumber: '22F' });
|
||||
expect(own(payload.seats)).toMatchObject({ seatNumber: '22F' });
|
||||
// A co-passenger's seat is not TREK's to touch.
|
||||
const withGuest = buildSavePayload(res, newShape({
|
||||
passengers: [
|
||||
{ userId: null, guestName: 'Plus One', seat: null, seatNumber: '30C', seatClass: null },
|
||||
{ userId: 'u1', guestName: null, seat: 'window', seatNumber: '12A', seatClass: 'economy' },
|
||||
],
|
||||
})) as SavePayloadWithPassthrough;
|
||||
const guest = (withGuest.passengers as Array<{ guestName: string | null; seatNumber: string | null }>).find(s => s.guestName);
|
||||
expect(guest?.seatNumber).toBe('30C');
|
||||
});
|
||||
|
||||
it('writes the flight reason both on the flight and on the passenger', () => {
|
||||
const payload = buildSavePayload(reservation(), newShape()) as SavePayloadWithPassthrough;
|
||||
expect(payload.flightReason).toBe('leisure');
|
||||
expect(own(payload.passengers)).toMatchObject({ flightReason: 'leisure' });
|
||||
});
|
||||
|
||||
it('recovers the reason from the passenger when the flight no longer carries one', () => {
|
||||
const res = reservation({ metadata: JSON.stringify({ seat: '12A' }) });
|
||||
const payload = buildSavePayload(res, newShape()) as SavePayloadWithPassthrough;
|
||||
expect(payload.flightReason).toBe('leisure');
|
||||
});
|
||||
|
||||
it('still fills the manifest from the old shape', () => {
|
||||
const payload = buildSavePayload(reservation(), existingFlight()) as SavePayloadWithPassthrough;
|
||||
expect(own(payload.passengers)).toMatchObject({ seatNumber: '12A' });
|
||||
expect(own(payload.seats)).toMatchObject({ seatNumber: '12A' });
|
||||
});
|
||||
|
||||
it('falls back to the key-owner placeholder when the flight has no manifest at all', () => {
|
||||
const payload = buildSavePayload(reservation(), newShape({ passengers: [] })) as SavePayloadWithPassthrough;
|
||||
expect(payload.passengers).toHaveLength(1);
|
||||
expect(own(payload.passengers)).toMatchObject({ userId: '<USER_ID>', seatNumber: '12A' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user