Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serialize's tests #1907

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application/json is always utf-8, so there should be no charset=, maybe that's why the tests are failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it and in println we have "application/json; charset=utf-8", but sbt has problem with matching contentType to proper type


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
Loading