Skip to content

Commit

Permalink
Merge pull request #292 from ibi-group/fix-trip-companion-checks
Browse files Browse the repository at this point in the history
fix(MonitoredTrip): Handle primary and companion fields with null emails
  • Loading branch information
binh-dam-ibigroup authored Jan 27, 2025
2 parents 0b40441 + 0db6a08 commit bc16e28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,17 @@ public TripUsers(MobilityProfileLite primary, RelatedUser companion, List<Relate
* Trip created by primary user.
*/
public boolean ownedByPrimary() {
return primary != null && primary.userId.equalsIgnoreCase(userId);
return primary != null && userId.equalsIgnoreCase(primary.userId);
}

/**
* Trip created by companion user.
*/
public boolean ownedByCompanion() {
OtpUser tripOwner = Persistence.otpUsers.getById(userId);
return tripOwner != null && companion != null && companion.email.equalsIgnoreCase(tripOwner.email);
return tripOwner != null &&
tripOwner.email != null &&
companion != null &&
tripOwner.email.equalsIgnoreCase(companion.email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -123,4 +124,18 @@ private static Stream<Arguments> createLegTransitionNotifyUsersTestCases() {
Arguments.of(companion.id, Set.of(primary, observer))
);
}

@Test
void testLegTransitionNotifyUsersIncompleteData() {
MonitoredTrip trip = new MonitoredTrip();
// Set as owner an existing user that is not the primary or the companion user from the setup method.
trip.userId = observer.id;
trip.primary = new MobilityProfileLite();
trip.companion = new RelatedUser();
trip.observers.add(new RelatedUser());

Set<OtpUser> users = LegTransitionNotification.getLegTransitionNotifyUsers(trip);
assertNotNull(users);
assertTrue(users.isEmpty());
}
}

0 comments on commit bc16e28

Please sign in to comment.