Skip to content

Commit

Permalink
Merge pull request #6313 from ibi-group/booking-info-durations
Browse files Browse the repository at this point in the history
Convert booking notices to duration in GTFS GraphQL API
  • Loading branch information
leonardehrenfried authored Dec 10, 2024
2 parents c2b70d5 + 4a63ca1 commit e15f69b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public DataFetcher<BookingTime> latestBookingTime() {
return environment -> getSource(environment).getLatestBookingTime();
}

@Override
public DataFetcher<Duration> maximumBookingNotice() {
return env -> getSource(env).getMaximumBookingNotice().orElse(null);
}

@Override
public DataFetcher<Long> maximumBookingNoticeSeconds() {
return environment ->
Expand All @@ -41,6 +46,11 @@ public DataFetcher<String> message() {
return environment -> getSource(environment).getMessage();
}

@Override
public DataFetcher<Duration> minimumBookingNotice() {
return env -> getSource(env).getMinimumBookingNotice().orElse(null);
}

@Override
public DataFetcher<Long> minimumBookingNoticeSeconds() {
return environment ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ public interface GraphQLBookingInfo {

public DataFetcher<BookingTime> latestBookingTime();

public DataFetcher<java.time.Duration> maximumBookingNotice();

public DataFetcher<Long> maximumBookingNoticeSeconds();

public DataFetcher<String> message();

public DataFetcher<java.time.Duration> minimumBookingNotice();

public DataFetcher<Long> minimumBookingNoticeSeconds();

public DataFetcher<String> pickupMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,16 @@ type BookingInfo {
earliestBookingTime: BookingTime
"When is the latest time the service can be booked"
latestBookingTime: BookingTime
"Maximum duration before travel to make the request."
maximumBookingNotice: Duration
"Maximum number of seconds before travel to make the request"
maximumBookingNoticeSeconds: Long
maximumBookingNoticeSeconds: Long @deprecated(reason : "Use `maximumBookingNotice`")
"A general message for those booking the service"
message: String
"Minimum duration before travel to make the request"
minimumBookingNotice: Duration
"Minimum number of seconds before travel to make the request"
minimumBookingNoticeSeconds: Long
minimumBookingNoticeSeconds: Long @deprecated(reason : "Use `minimumBookingNotice`")
"A message specific to the pick up"
pickupMessage: String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,40 @@ class BookingInfoImplTest {

private static final BookingInfoImpl SUBJECT = new BookingInfoImpl();
private static final Duration TEN_MINUTES = Duration.ofMinutes(10);
private static final BookingInfo WITH_NOTICE_DURATIONS = BookingInfo
.of()
.withMinimumBookingNotice(TEN_MINUTES)
.withMaximumBookingNotice(TEN_MINUTES)
.build();

@Test
void emptyDurations() throws Exception {
void emptyNoticeSeconds() throws Exception {
var env = dataFetchingEnvironment(BookingInfo.of().build());
assertNull(SUBJECT.minimumBookingNoticeSeconds().get(env));
assertNull(SUBJECT.maximumBookingNoticeSeconds().get(env));
}

@Test
void durations() throws Exception {
var env = dataFetchingEnvironment(
BookingInfo
.of()
.withMinimumBookingNotice(TEN_MINUTES)
.withMaximumBookingNotice(TEN_MINUTES)
.build()
);
void emptyNoticeDurations() throws Exception {
var env = dataFetchingEnvironment(BookingInfo.of().build());
assertNull(SUBJECT.minimumBookingNotice().get(env));
assertNull(SUBJECT.maximumBookingNotice().get(env));
}

@Test
void seconds() throws Exception {
var env = dataFetchingEnvironment(WITH_NOTICE_DURATIONS);
assertEquals(600, SUBJECT.minimumBookingNoticeSeconds().get(env));
assertEquals(600, SUBJECT.maximumBookingNoticeSeconds().get(env));
}

@Test
void durations() throws Exception {
var env = dataFetchingEnvironment(WITH_NOTICE_DURATIONS);
assertEquals(TEN_MINUTES, SUBJECT.minimumBookingNotice().get(env));
assertEquals(TEN_MINUTES, SUBJECT.maximumBookingNotice().get(env));
}

private DataFetchingEnvironment dataFetchingEnvironment(BookingInfo bookingInfo) {
var executionContext = newExecutionContextBuilder()
.executionId(ExecutionId.from(this.getClass().getName()))
Expand Down

0 comments on commit e15f69b

Please sign in to comment.