Skip to content

Commit

Permalink
Make test JS-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jan 5, 2021
1 parent 801802d commit 70b5dee
Showing 1 changed file with 12 additions and 9 deletions.
Expand Up @@ -2,32 +2,35 @@ package sttp.client3

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.client3.testing.{RecordingSttpBackend, SttpBackendStub}
import sttp.client3.testing.SttpBackendStub
import sttp.model.StatusCode

class ResolveRelativeUrisBackendTest extends AnyFlatSpec with Matchers {
it should "not resolve absolute URIs" in {
// given
val delegate = new RecordingSttpBackend(SttpBackendStub.synchronous.whenAnyRequest.thenRespondOk())
val delegate = SttpBackendStub.synchronous.whenRequestMatchesPartial { case r =>
Response(r.uri.toString, StatusCode.Ok)
}
val backend = ResolveRelativeUrisBackend(delegate, uri"http://example.org")

// when
basicRequest.get(uri"http://example2.org/test?a=1").send(backend)
val response = basicRequest.response(asStringAlways).get(uri"http://example2.org/test?a=1").send(backend)

// then
delegate.allInteractions should have size (1)
delegate.allInteractions.head._1.uri.toString shouldBe "http://example2.org/test?a=1"
response.body shouldBe "http://example2.org/test?a=1"
}

it should "resolve relative URIs" in {
// given
val delegate = new RecordingSttpBackend(SttpBackendStub.synchronous.whenAnyRequest.thenRespondOk())
val delegate = SttpBackendStub.synchronous.whenRequestMatchesPartial { case r =>
Response(r.uri.toString, StatusCode.Ok)
}
val backend = ResolveRelativeUrisBackend(delegate, uri"http://example.org")

// when
basicRequest.get(uri"/test?a=1").send(backend)
val response = basicRequest.response(asStringAlways).get(uri"/test?a=1").send(backend)

// then
delegate.allInteractions should have size (1)
delegate.allInteractions.head._1.uri.toString shouldBe "http://example.org/test?a=1"
response.body shouldBe "http://example.org/test?a=1"
}
}

0 comments on commit 70b5dee

Please sign in to comment.