Skip to content

Commit

Permalink
Merge pull request #2334 from vasiliybondarenko/stub-interpreter-rail…
Browse files Browse the repository at this point in the history
…ing-slash

Ignore trailing slash in stub request
  • Loading branch information
adamw authored Jul 28, 2022
2 parents 67ee810 + 7b6c361 commit ebf688b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ case class SttpRequest(r: Request[_, _], attributes: AttributeMap = AttributeMap
override def protocol: String = "HTTP/1.1"
override def connectionInfo: ConnectionInfo = ConnectionInfo(None, None, None)
override def underlying: Any = r
override def pathSegments: List[String] = r.uri.pathSegments.segments.map(_.v).toList
override def pathSegments: List[String] = (r.uri.pathSegments.segments.map(_.v) match {
case other :+ "" => other
case s => s
}).toList
override def uri: Uri = r.uri
override def attribute[T](k: AttributeKey[T]): Option[T] = attributes.get(k)
override def attribute[T](k: AttributeKey[T], v: T): SttpRequest = copy(attributes = attributes.put(k, v))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ class TapirStubInterpreterTest extends AnyFlatSpec with Matchers {
response.body shouldBe Right("computer")
}

it should "stub endpoint logic with trailing slash with success response" in {
// given
val server = TapirStubInterpreter(options, SttpBackendStub(IdMonad))
.whenEndpoint(getProduct)
.thenRespond("computer")
.backend()

// when
val response = sttp.client3.basicRequest.get(uri"http://test.com/api/products/").send(server)

// then
response.body shouldBe Right("computer")
}

it should "stub endpoint logic with error response" in {
// given
val server = TapirStubInterpreter[Identity, Nothing, ServerOptions](options, SttpBackendStub(IdMonad))
Expand Down

0 comments on commit ebf688b

Please sign in to comment.