|
1 | 1 | /* cspell:disable */ |
2 | | -import {getAirReservations, getPNRReservationDataFromTripReport, getReservationsFromTripReport, isPnrCancelled} from '@libs/TripReservationUtils'; |
| 2 | +import {formatTransitLocationLabel, getAirReservations, getPNRReservationDataFromTripReport, getReservationsFromTripReport, isPnrCancelled} from '@libs/TripReservationUtils'; |
3 | 3 | import CONST from '@src/CONST'; |
4 | 4 | import type {Pnr, TripData} from '@src/types/onyx/TripData'; |
5 | 5 | import {airReservationPnrData, airReservationTravelers} from '../data/TripAirReservationData'; |
@@ -2692,6 +2692,61 @@ describe('TripReservationUtils', () => { |
2692 | 2692 | }); |
2693 | 2693 | }); |
2694 | 2694 |
|
| 2695 | + describe('rail shortName sanitization', () => { |
| 2696 | + it('should drop a URN-formatted code from rail shortName', () => { |
| 2697 | + const railPnrWithUrnCodes = JSON.parse(JSON.stringify(railPnr)) as typeof railPnr; |
| 2698 | + const leg = railPnrWithUrnCodes.data.railPnr?.legInfos.at(0); |
| 2699 | + if (leg) { |
| 2700 | + leg.originInfo.code = 'urn:trainline:public:nloc:at000408'; |
| 2701 | + leg.destinationInfo.code = 'urn:trainline:public:nloc:at001685'; |
| 2702 | + } |
| 2703 | + |
| 2704 | + const report = createRandomReport(1, undefined); |
| 2705 | + report.tripData = { |
| 2706 | + tripID: 'trip123', |
| 2707 | + payload: { |
| 2708 | + ...basicTripData, |
| 2709 | + pnrs: [railPnrWithUrnCodes], |
| 2710 | + }, |
| 2711 | + }; |
| 2712 | + |
| 2713 | + const result = getReservationsFromTripReport(report, []); |
| 2714 | + expect(result).toHaveLength(1); |
| 2715 | + |
| 2716 | + const trainReservation = result.at(0)?.reservation; |
| 2717 | + expect(trainReservation?.type).toEqual(CONST.RESERVATION_TYPE.TRAIN); |
| 2718 | + expect(trainReservation?.start?.shortName).toEqual(''); |
| 2719 | + expect(trainReservation?.end?.shortName).toEqual(''); |
| 2720 | + }); |
| 2721 | + |
| 2722 | + it('should render only longName when shortName is empty (no trailing space, no empty parens)', () => { |
| 2723 | + expect(formatTransitLocationLabel({date: '', longName: 'Brockenhurst', shortName: '', cityName: ''})).toEqual('Brockenhurst'); |
| 2724 | + }); |
| 2725 | + |
| 2726 | + it('should render longName with parenthesized shortName when both are present', () => { |
| 2727 | + expect(formatTransitLocationLabel({date: '', longName: 'Solana Beach station', shortName: 'SOL', cityName: ''})).toEqual('Solana Beach station (SOL)'); |
| 2728 | + }); |
| 2729 | + |
| 2730 | + it('should preserve a clean station code in rail shortName', () => { |
| 2731 | + const report = createRandomReport(1, undefined); |
| 2732 | + report.tripData = { |
| 2733 | + tripID: 'trip123', |
| 2734 | + payload: { |
| 2735 | + ...basicTripData, |
| 2736 | + pnrs: [railPnr], |
| 2737 | + }, |
| 2738 | + }; |
| 2739 | + |
| 2740 | + const result = getReservationsFromTripReport(report, []); |
| 2741 | + expect(result).toHaveLength(1); |
| 2742 | + |
| 2743 | + const trainReservation = result.at(0)?.reservation; |
| 2744 | + expect(trainReservation?.type).toEqual(CONST.RESERVATION_TYPE.TRAIN); |
| 2745 | + expect(trainReservation?.start?.shortName).toEqual('STX'); |
| 2746 | + expect(trainReservation?.end?.shortName).toEqual('STY'); |
| 2747 | + }); |
| 2748 | + }); |
| 2749 | + |
2695 | 2750 | describe('getPNRReservationDataFromTripReport', () => { |
2696 | 2751 | it('should return an empty array when there are no transactions and trip payload', () => { |
2697 | 2752 | const report = createRandomReport(1, undefined); |
|
0 commit comments