-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from GrigoriiBerezin/zio_http_test_with_payload
feat: add zio http test with payload
- Loading branch information
Showing
5 changed files
with
61 additions
and
12 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
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
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
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 |
---|---|---|
@@ -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") |
43 changes: 43 additions & 0 deletions
43
zio-quickstart-restful-webservice/src/test/scala/dev/zio/quickstart/UserRouteSpec.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,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) |