-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IHRDS 3159 handle bad request body for /users/groups/query (#872)
* handle invalid request body for endpoint "users" / "groups" / "query" * added test case (don't expect them to be in the right format)
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/src/it/scala/com/iheart/thomas/abtest/EndpointSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.iheart.thomas.abtest | ||
|
||
import cats.effect.IO | ||
import cats.effect.testing.scalatest.AsyncIOSpec | ||
import com.iheart.thomas.abtest.TestUtils.withAlg | ||
import com.iheart.thomas.http4s.abtest.AbtestService | ||
import com.iheart.thomas.tracking.EventLogger | ||
import fs2._ | ||
import org.http4s.Status._ | ||
import org.http4s.{Method, Request} | ||
import org.scalatest.freespec.AsyncFreeSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import org.typelevel.log4cats.slf4j.Slf4jLogger | ||
import org.http4s.implicits.http4sLiteralsSyntax | ||
|
||
class EndpointSuite extends AsyncFreeSpec with AsyncIOSpec with Matchers { | ||
implicit val logger: EventLogger[IO] = EventLogger.catsLogger(Slf4jLogger.getLogger[IO]) | ||
|
||
"/users/groups/query endpoint should handle different request bodies appropriately" - { | ||
"good request body json should return OK" in { | ||
withAlg { alg => | ||
val data: String = """{"meta":{"country":"us"},"userId":"123"}""" | ||
val body: Stream[IO, Byte] = Stream.emit(data).through(text.utf8.encode) | ||
new AbtestService(alg).public.orNotFound.run( | ||
Request(method = Method.POST, uri = uri"/users/groups/query", body = body) | ||
) | ||
}.asserting { response => | ||
response.status shouldBe Ok | ||
} | ||
} | ||
|
||
"empty request body json should return BadRequest" in { | ||
withAlg { alg => | ||
new AbtestService(alg).public.orNotFound.run( | ||
Request(method = Method.POST, uri = uri"/users/groups/query") | ||
) | ||
}.asserting { response => | ||
response.status shouldBe BadRequest | ||
} | ||
} | ||
|
||
"bad request body json should return BadRequest" in { | ||
withAlg { alg => | ||
val data: String = """{"meta":{"country":"us", "deviceId": {}},"userId":"123"}""" | ||
val body: Stream[IO, Byte] = Stream.emit(data).through(text.utf8.encode) | ||
new AbtestService(alg).public.orNotFound.run( | ||
Request(method = Method.POST, uri = uri"/users/groups/query", body = body) | ||
) | ||
}.asserting { response => | ||
response.status shouldBe BadRequest | ||
} | ||
} | ||
} | ||
} |