Skip to content

Commit

Permalink
feat: add fail-safe when providing empty table type (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkaar authored Feb 14, 2023
1 parent a47c4f0 commit 6e693c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/com/resy/ResyClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class ResyClient(resyApi: ResyApi) extends Logging {
): Try[String] = {
val results = reservationMap.get(resTimeTypes.head.reservationTime).flatMap { tableTypes =>
resTimeTypes.head.tableType match {
case Some(tableType) => tableTypes.get(tableType.toLowerCase)
case None => Some(tableTypes.head._2)
case Some(tableType) if tableType.nonEmpty => tableTypes.get(tableType.toLowerCase)
case _ => Some(tableTypes.head._2)
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/com/resy/ResyClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ class ResyClientSpec extends AnyFlatSpec with Matchers {
) shouldEqual Success("CONFIG_ID5")
}

it should "find an available reservation with empty string as the table type" in new Fixture {
when(resyApi.getReservations(resDetails.date, resDetails.partySize, resDetails.venueId))
.thenReturn(Future(Source.fromResource("getReservations.json").mkString))

resyClient.findReservations(
date = resDetails.date,
partySize = resDetails.partySize,
venueId = resDetails.venueId,
resTimeTypes = Seq(
ReservationTimeType("18:00:00", "")
),
millisToRetry = (.1 seconds).toMillis
) shouldEqual Success("CONFIG_ID5")
}

it should "find an available reservation with no table type preference" in new Fixture {
when(resyApi.getReservations(resDetails.date, resDetails.partySize, resDetails.venueId))
.thenReturn(Future(Source.fromResource("getReservations.json").mkString))
Expand Down

0 comments on commit 6e693c9

Please sign in to comment.