Skip to content

Commit

Permalink
Add checking content type to serialize's tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Domin committed Jul 24, 2023
1 parent f642903 commit fa48e55
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
8 changes: 5 additions & 3 deletions json/circe/src/test/scala/sttp/client4/circe/CirceTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ class CirceTests extends AnyFlatSpec with Matchers with EitherValues {
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 request = basicRequest.get(Uri("http://example.org")).body(jObject)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

case class Inner(a: Int, b: Boolean, c: String)
Expand Down
8 changes: 5 additions & 3 deletions json/json4s/src/test/scala/sttp/client4/Json4sTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ class Json4sTests extends AnyFlatSpec with Matchers with EitherValues {

it should "serialize from JObject using implicit json4sBodySerializer" in {
val jObject: JObject = JObject(JField("location", JString("hometown")), JField("bio", JString("Scala programmer")))
val result = basicRequest.get(Uri("http://example.org")).body(jObject).body.show
val request = basicRequest.get(Uri("http://example.org")).body(jObject)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

def extractBody[T](request: PartialRequest[T]): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ class JsoniterJsonTests extends AnyFlatSpec with Matchers with EitherValues {

it should "serialize from case class Person using implicit jsoniterBodySerializer" in {
val person = Person("John")
val result = basicRequest.get(Uri("http://example.org")).body(person).body.show
val request = basicRequest.get(Uri("http://example.org")).body(person)

val expectedResult = "string: {\"name\":\"John\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

def extractBody[T](request: PartialRequest[T]): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ class PlayJsonTests extends AnyFlatSpec with Matchers with EitherValues {
val fields: Seq[(String, JsValue)] =
Seq[(String, JsValue)](("location", JsString("hometown")), ("bio", JsString("Scala programmer")))
val json: JsObject = JsObject(fields)
val result = basicRequest.get(Uri("http://example.org")).body(json).body.show
val request = basicRequest.get(Uri("http://example.org")).body(json)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

case class Inner(a: Int, b: Boolean, c: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ class SprayJsonTests extends AnyFlatSpec with Matchers with EitherValues {
"location" -> "hometown".toJson,
"bio" -> "Scala programmer".toJson
)
val result = basicRequest.get(Uri("http://example.org")).body(json).body.show
val request = basicRequest.get(Uri("http://example.org")).body(json)

val expectedResult = "string: {\"bio\":\"Scala programmer\",\"location\":\"hometown\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

def extractBody[T](request: PartialRequest[T]): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ class UpickleTests extends AnyFlatSpec with Matchers with EitherValues {
"location" -> "hometown",
"bio" -> "Scala programmer"
)
val result = basicRequest.get(Uri("http://example.org")).body(json).body.show
val request = basicRequest.get(Uri("http://example.org")).body(json)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

case class Inner(a: Int, b: Boolean, c: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ class ZioJsonTests extends AnyFlatSpec with Matchers with EitherValues {
it should "serialize from Json.Obj using implicit zioJsonBodySerializer" in {
val fields: Chunk[(String, Json)] = Chunk(("location", Json.Str("hometown")), ("bio", Json.Str("Scala programmer")))
val jObject: Json.Obj = Json.Obj(fields)
val result = basicRequest.get(Uri("http://example.org")).body(jObject).body.show
val request = basicRequest.get(Uri("http://example.org")).body(jObject)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

def extractBody[T](request: PartialRequest[T]): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ class ZioJsonTests extends AnyFlatSpec with Matchers with EitherValues {
it should "serialize from Json.Obj using implicit zioJsonBodySerializer" in {
val fields: Chunk[(String, Json)] = Chunk(("location", Json.Str("hometown")), ("bio", Json.Str("Scala programmer")))
val jObject: Json.Obj = Json.Obj(fields)
val result = basicRequest.get(Uri("http://example.org")).body(jObject).body.show
val request = basicRequest.get(Uri("http://example.org")).body(jObject)

val expectedResult = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedBody = "string: {\"location\":\"hometown\",\"bio\":\"Scala programmer\"}"
val expectedContentType = Some("application/json; charset=utf-8")

result should be(expectedResult)
request.contentType should be(expectedContentType)
request.body.show should be(expectedBody)
}

def extractBody[T](request: PartialRequest[T]): String =
Expand Down

0 comments on commit fa48e55

Please sign in to comment.