Skip to content

Commit

Permalink
Overwrites directMode when it is not set in the request.
Browse files Browse the repository at this point in the history
Defaulting it to walk when it was not set caused issues when the user expected no results because transportModes are defined.
  • Loading branch information
eibakke committed Apr 2, 2024
1 parent 8d15a0d commit fb26d55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RequestModesMapper {
* Maps GraphQL Modes input type to RequestModes.
* <p>
* This only maps access, egress, direct & transfer modes. Transport modes are set using filters.
* Default modes are WALK for access, egress, direct & transfer.
* Default modes are WALK for access, egress & transfer.
*/
static RequestModes mapRequestModes(Map<String, ?> modesInput) {
RequestModesBuilder mBuilder = RequestModes.of();
Expand All @@ -28,9 +28,8 @@ static RequestModes mapRequestModes(Map<String, ?> modesInput) {
if (modesInput.containsKey(egressModeKey)) {
mBuilder.withEgressMode((StreetMode) modesInput.get(egressModeKey));
}
if (modesInput.containsKey(directModeKey)) {
mBuilder.withDirectMode((StreetMode) modesInput.get(directModeKey));
}
// An unset directMode should overwrite the walk default, so we don't check for existence first.
mBuilder.withDirectMode((StreetMode) modesInput.get(directModeKey));

return mBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class RequestModesMapperTest {
void testMapRequestModesEmptyMapReturnsDefaults() {
Map<String, StreetMode> inputModes = Map.of();

RequestModes wantModes = RequestModes.of().withDirectMode(null).build();

RequestModes mappedModes = RequestModesMapper.mapRequestModes(inputModes);

assertEquals(RequestModes.of().build(), mappedModes);
assertEquals(wantModes, mappedModes);
}

@Test
Expand All @@ -26,6 +28,7 @@ void testMapRequestModesAccessSetReturnsDefaultsForOthers() {
.of()
.withAccessMode(StreetMode.BIKE)
.withTransferMode(StreetMode.BIKE)
.withDirectMode(null)
.build();

RequestModes mappedModes = RequestModesMapper.mapRequestModes(inputModes);
Expand All @@ -37,7 +40,11 @@ void testMapRequestModesAccessSetReturnsDefaultsForOthers() {
void testMapRequestModesEgressSetReturnsDefaultsForOthers() {
Map<String, StreetMode> inputModes = Map.of("egressMode", StreetMode.CAR);

RequestModes wantModes = RequestModes.of().withEgressMode(StreetMode.CAR).build();
RequestModes wantModes = RequestModes
.of()
.withEgressMode(StreetMode.CAR)
.withDirectMode(null)
.build();

RequestModes mappedModes = RequestModesMapper.mapRequestModes(inputModes);

Expand Down

0 comments on commit fb26d55

Please sign in to comment.