Skip to content

Commit

Permalink
fix(ManageTripTracking): Use profile of primary traveler.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Dec 10, 2024
1 parent fb64da8 commit dd2f246
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ public static TripUsers getAddedUsers(MonitoredTrip monitoredTrip, MonitoredTrip
return new TripUsers(addedPrimaryTraveler, addedCompanion, addedObservers);
}

/**
* @return The id of the primary traveler (the primary user of a trip,
* or the user who created the trip if no primary user has been set).
*/
public String getPrimaryTravelerId() {
return primary != null ? primary.userId : userId;
}

public static class TripUsers {
public final RelatedUser companion;
public final List<RelatedUser> observers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static TrackingResponse doUpdateTracking(Request request, TripTrackingDa
TripActions.getDefault().handleSegmentAction(
((SelfLegInstruction)instruction).getLegStep(),
travelerPosition.expectedLeg.steps,
Persistence.otpUsers.getById(tripData.trip.userId)
Persistence.otpUsers.getById(tripData.trip.getPrimaryTravelerId())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,36 @@ private static Stream<Arguments> createGetAddedUsersCases() {
)
);
}

@ParameterizedTest
@MethodSource("createGetPrimaryTravelerCases")
void canGetPrimaryTraveler(MobilityProfileLite primary, String creatorId, String expectedId, String message) {
MonitoredTrip trip = new MonitoredTrip();
trip.userId = creatorId;
trip.primary = primary;

assertEquals(expectedId, trip.getPrimaryTravelerId(), message);
}

private static Stream<Arguments> createGetPrimaryTravelerCases() {
final String creatorId = "creator-user-id";

MobilityProfileLite primary = new MobilityProfileLite();
primary.userId = "primary-user-id";

return Stream.of(
Arguments.of(
primary,
creatorId,
primary.userId,
"Should return the id of primary if it was set."
),
Arguments.of(
null,
creatorId,
creatorId,
"Should return the id of the user that created the trip if primary is null."
)
);
}
}

0 comments on commit dd2f246

Please sign in to comment.