@@ -656,4 +656,107 @@ describe('useUpcomingTravelReservations', () => {
656656 expect ( result . current ) . toEqual ( [ ] ) ;
657657 } ) ;
658658 } ) ;
659+
660+ it ( 'should skip reservations with invalid start date and keep valid ones' , async ( ) => {
661+ const invalidFlight = makeAirPnr ( 'PNR_INVALID' , 'not-a-date' , 'not-a-date' ) ;
662+ const validFlight = makeAirPnr ( 'PNR_VALID' , daysFromNow ( 2 ) , daysFromNow ( 2 , 15 ) ) ;
663+ const tripRoom = makeTripRoomReport ( '1000' , [ invalidFlight , validFlight ] ) ;
664+
665+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1000` , tripRoom ) ;
666+ await waitForBatchedUpdates ( ) ;
667+
668+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
669+
670+ await waitFor ( ( ) => {
671+ expect ( result . current ) . toHaveLength ( 1 ) ;
672+ } ) ;
673+ expect ( result . current . at ( 0 ) ?. reservation . reservationID ) . toBe ( 'PNR_VALID' ) ;
674+ } ) ;
675+
676+ it ( 'should return empty array when all reservations have invalid start dates' , async ( ) => {
677+ const invalidFlight = makeAirPnr ( 'PNR_INVALID_ALL' , '' , '' ) ;
678+ const tripRoom = makeTripRoomReport ( '1001' , [ invalidFlight ] ) ;
679+
680+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1001` , tripRoom ) ;
681+ await waitForBatchedUpdates ( ) ;
682+
683+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
684+
685+ await waitFor ( ( ) => {
686+ expect ( result . current ) . toEqual ( [ ] ) ;
687+ } ) ;
688+ } ) ;
689+
690+ it ( 'should include reservation at the exact 7-day boundary' , async ( ) => {
691+ const boundaryFlight = makeAirPnr ( 'PNR_BOUNDARY' , daysFromNow ( CONST . UPCOMING_TRAVEL_WINDOW_DAYS , 0 ) , daysFromNow ( CONST . UPCOMING_TRAVEL_WINDOW_DAYS , 3 ) ) ;
692+ const tripRoom = makeTripRoomReport ( '1002' , [ boundaryFlight ] ) ;
693+
694+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1002` , tripRoom ) ;
695+ await waitForBatchedUpdates ( ) ;
696+
697+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
698+
699+ await waitFor ( ( ) => {
700+ expect ( result . current ) . toHaveLength ( 1 ) ;
701+ } ) ;
702+ expect ( result . current . at ( 0 ) ?. reservation . reservationID ) . toBe ( 'PNR_BOUNDARY' ) ;
703+ } ) ;
704+
705+ it ( 'should return empty array for trip room without tripData' , async ( ) => {
706+ const tripRoom = {
707+ reportID : '1003' ,
708+ ownerAccountID : TEST_ACCOUNT_ID ,
709+ type : CONST . REPORT . TYPE . CHAT ,
710+ chatType : CONST . REPORT . CHAT_TYPE . TRIP_ROOM ,
711+ reportName : 'Trip 1003' ,
712+ policyID : 'policy1' ,
713+ } as Report ;
714+
715+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1003` , tripRoom ) ;
716+ await waitForBatchedUpdates ( ) ;
717+
718+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
719+
720+ await waitFor ( ( ) => {
721+ expect ( result . current ) . toEqual ( [ ] ) ;
722+ } ) ;
723+ } ) ;
724+
725+ it ( 'should return empty array for trip room with empty pnrs array' , async ( ) => {
726+ const tripRoom = makeTripRoomReport ( '1004' , [ ] ) ;
727+
728+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1004` , tripRoom ) ;
729+ await waitForBatchedUpdates ( ) ;
730+
731+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
732+
733+ await waitFor ( ( ) => {
734+ expect ( result . current ) . toEqual ( [ ] ) ;
735+ } ) ;
736+ } ) ;
737+
738+ it ( 'should ignore non-trip-room reports' , async ( ) => {
739+ const flight = makeAirPnr ( 'PNR_NON_TRIP' , daysFromNow ( 2 ) , daysFromNow ( 2 , 15 ) ) ;
740+ const nonTripReport = {
741+ reportID : '1005' ,
742+ ownerAccountID : TEST_ACCOUNT_ID ,
743+ type : CONST . REPORT . TYPE . CHAT ,
744+ chatType : CONST . REPORT . CHAT_TYPE . POLICY_ROOM ,
745+ reportName : 'Policy Room' ,
746+ policyID : 'policy1' ,
747+ tripData : {
748+ tripID : 'trip-1005' ,
749+ payload : { pnrs : [ flight ] } ,
750+ } ,
751+ } as Report ;
752+
753+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } 1005` , nonTripReport ) ;
754+ await waitForBatchedUpdates ( ) ;
755+
756+ const { result} = renderHook ( ( ) => useUpcomingTravelReservations ( ) ) ;
757+
758+ await waitFor ( ( ) => {
759+ expect ( result . current ) . toEqual ( [ ] ) ;
760+ } ) ;
761+ } ) ;
659762} ) ;
0 commit comments