Skip to content

Commit

Permalink
Merge pull request #55 from GrigoriiBerezin/zio_http_test_with_payload
Browse files Browse the repository at this point in the history
feat: add zio http test with payload
  • Loading branch information
khajavi authored Aug 16, 2024
2 parents e09c3fc + ff70b38 commit 275a39e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ jobs:
fail-fast: false
matrix:
java:
- '8'
- '17'
scala-project:
- ++2.13.8 zio-quickstart-encode-decode-json
- ++2.13.13 zio-quickstart-sql
- ++2.13.13 zio-quickstart-prelude
- ++3.3.1 zio-quickstart-restful-webservice
steps:
- name: Install libuv
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
Expand Down
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ align.preset = "more"
runner.dialect = scala213

fileOverride {
"glob:**/zio-quickstart-restful-webservice/src/main/scala/**" {
runner.dialect = scala3
"glob:**/zio-quickstart-restful-webservice/src/**/scala/**" {
runner.dialect = scala3
}
}
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ inThisBuild(
ciReleaseJobs := Seq.empty,
ciPostReleaseJobs := Seq.empty,
ciCheckWebsiteBuildProcess := Seq.empty,
scalaVersion := "2.13.8",
scalaVersion := scala213.value,
ciTargetScalaVersions := makeTargetScalaMap(
`zio-quickstart-encode-decode-json`,
`zio-quickstart-sql`,
`zio-quickstart-prelude`
`zio-quickstart-prelude`,
`zio-quickstart-restful-webservice`
).value,
ciDefaultTargetJavaVersions := Seq("8"),
ciDefaultTargetJavaVersions := Seq("17"),
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
Expand Down
16 changes: 10 additions & 6 deletions zio-quickstart-restful-webservice/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
scalaVersion := "3.3.1"
Test / fork := true

libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "2.0.22",
"dev.zio" %% "zio-json" % "0.6.2",
"dev.zio" %% "zio-http" % "3.0.0-RC6+36-d283e073-SNAPSHOT",
"io.getquill" %% "quill-zio" % "4.7.0",
"io.getquill" %% "quill-jdbc-zio" % "4.7.0",
"com.h2database" % "h2" % "2.2.224"
"dev.zio" %% "zio" % "2.1.1",
"dev.zio" %% "zio-json" % "0.6.2",
"dev.zio" %% "zio-http" % "3.0.0-RC8",
"io.getquill" %% "quill-zio" % "4.7.0",
"io.getquill" %% "quill-jdbc-zio" % "4.7.0",
"com.h2database" % "h2" % "2.2.224",
"dev.zio" %% "zio-test" % "2.1.0" % Test,
"dev.zio" %% "zio-http-testkit" % "3.0.0-RC8" % Test,
"dev.zio" %% "zio-test-sbt" % "2.1.1" % Test
)

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.zio.quickstart

import dev.zio.quickstart.users.*
import zio.*
import zio.http.*
import zio.http.netty.NettyConfig
import zio.http.netty.server.NettyDriver
import zio.schema.codec.JsonCodec.schemaBasedBinaryCodec
import zio.test.*

import java.util.UUID

object UserRouteSpec extends ZIOSpecDefault:
override def spec: Spec[Any, Any] = suite("UserRoutes")(
test("create and get user by id") {
for {
client <- ZIO.service[Client]
_ <- TestServer.addRoutes(UserRoutes())
port <- ZIO.serviceWith[Server](_.port)
url = URL.root.port(port)
testUser = User("Adam", 28)
createResponse <- client(
Request.post(url / "users", Body.from[User](testUser))
)
userId <- createResponse.body.asString(Charsets.Utf8)
getResponse <- client(Request.get(url / "users" / userId))
result <- getResponse.body.to[User]
} yield assertTrue(result == testUser)
}.provideSome[Client with Driver with UserRepo](
TestServer.layer,
Scope.default,
InmemoryUserRepo.layer
)
).provide(
ZLayer.succeed(Server.Config.default.onAnyOpenPort),
Client.default,
NettyDriver.customized,
ZLayer.succeed(NettyConfig.defaultWithFastShutdown),
InmemoryUserRepo.layer
)

override def aspects: Chunk[TestAspectPoly] =
Chunk(TestAspect.timeout(60.seconds), TestAspect.timed)

0 comments on commit 275a39e

Please sign in to comment.