Skip to content

Commit

Permalink
test(http): assert Content-Type explicitly in all endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Nov 26, 2023
1 parent badbbc7 commit 571217d
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ArchiveRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ArticleRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("articlesnotfound"))
}
}
Expand All @@ -101,6 +102,7 @@ class ArticleRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -77,6 +78,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -96,6 +98,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -116,6 +119,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -136,6 +140,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: avoid to return user not found message
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("not-exists-userisnotfound."))
}
Expand All @@ -149,6 +154,7 @@ class AuthRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AuthorRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("NotFound"))
}
}
Expand All @@ -95,6 +96,7 @@ class AuthorRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NoContent)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -40,6 +41,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -51,6 +53,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -62,6 +65,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -73,6 +77,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -84,6 +89,7 @@ class CacheRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NoContent)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -109,6 +110,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("contentnotfound"))
}
}
Expand All @@ -129,6 +131,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("contentnotfound"))
}
}
Expand All @@ -147,6 +150,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down Expand Up @@ -254,6 +258,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -265,6 +270,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -279,6 +285,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -298,6 +305,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -324,6 +332,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === BadRequest)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand All @@ -346,6 +355,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === BadRequest)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand Down Expand Up @@ -447,6 +457,7 @@ class ContentRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ContentTypeRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("NotFound"))
}
}
Expand All @@ -74,6 +75,7 @@ class ContentTypeRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FeedRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HomeRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get.charset.get === Charset.`UTF-8`)
assert(response.as[String].unsafeRunSync().contains("Not found"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SearchRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === UnprocessableEntity)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand All @@ -84,6 +85,7 @@ class SearchRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === UnprocessableEntity)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand All @@ -96,6 +98,7 @@ class SearchRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === UnprocessableEntity)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand All @@ -108,6 +111,7 @@ class SearchRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === UnprocessableEntity)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand All @@ -120,6 +124,7 @@ class SearchRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === UnprocessableEntity)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
// TODO: assert JSON
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class SeriesRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === NotFound)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("seriesnotfound"))
}
}
Expand All @@ -148,6 +149,7 @@ class SeriesRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down Expand Up @@ -215,6 +217,7 @@ class SeriesRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
IO {

assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -226,6 +229,7 @@ class SeriesRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -240,6 +244,7 @@ class SeriesRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === Unauthorized)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SitemapRouteSpec extends AnyWordSpec with BeforeAndAfterAll {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.effect.IO
import org.http4s.client.Client
import org.http4s.*
import org.http4s.dsl.io.*
import org.http4s.headers.`Content-Type`
import org.http4s.implicits.*
import org.scalatest.wordspec.AnyWordSpec
import net.yoshinorin.qualtet.fixture.Fixture
Expand Down Expand Up @@ -31,6 +32,7 @@ class SystemRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === MethodNotAllowed)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -43,6 +45,7 @@ class SystemRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Ok)
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand All @@ -56,6 +59,7 @@ class SystemRouteSpec extends AnyWordSpec {
.use { response =>
IO {
assert(response.status === Ok)
assert(response.contentType.get === `Content-Type`(MediaType.application.json))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("name"))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("version"))
assert(response.as[String].unsafeRunSync().replaceAll("\n", "").replaceAll(" ", "").contains("repository"))
Expand All @@ -79,6 +83,7 @@ class SystemRouteSpec extends AnyWordSpec {
IO {
assert(response.status === NotFound)
// TODO: consider to return JSON or not
assert(response.contentType.isEmpty)
}
}
.unsafeRunSync()
Expand Down
Loading

0 comments on commit 571217d

Please sign in to comment.