Skip to content

Commit

Permalink
Add test to circe and remove import to check behavior on github for s…
Browse files Browse the repository at this point in the history
…cala 3
  • Loading branch information
Adrian Domin committed Jul 24, 2023
1 parent 0242e73 commit f642903
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions json/circe/src/test/scala/sttp/client4/circe/CirceTests.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sttp.client4.circe

import io.circe._
import io.circe.syntax.EncoderOps
import org.scalatest._
import sttp.client4.internal._
import sttp.client4._
Expand All @@ -10,9 +9,6 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class CirceTests extends AnyFlatSpec with Matchers with EitherValues {
// Needed for the implicit to work in Scala3. Normally this is imported explicitly, only in tests we are in the same package
import sttp.client4.circe.circeBodySerializer
import EitherDecoders._

"The circe module" should "encode arbitrary bodies given an encoder" in {
val body = Outer(Inner(42, true, "horses"), "cats")
Expand Down Expand Up @@ -105,6 +101,19 @@ class CirceTests extends AnyFlatSpec with Matchers with EitherValues {
ct shouldBe Some("horses/cats")
}

it should "serialize from JsonObject using implicit circeBodySerializer" in {
import io.circe.syntax.EncoderOps
import io.circe.JsonObject
import sttp.model.Uri

val jObject: JsonObject = JsonObject(("location", "hometown".asJson), ("bio", "Scala programmer".asJson))
val result = basicRequest.get(Uri("http://example.org")).body(jObject).body.show

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"

result should be(expectedResult)
}

case class Inner(a: Int, b: Boolean, c: String)

object Inner {
Expand Down

0 comments on commit f642903

Please sign in to comment.