@@ -2,7 +2,6 @@ package org.ivovk.connect_rpc_scala
2
2
3
3
import cats .effect .*
4
4
import cats .effect .unsafe .implicits .global
5
- import cats .syntax .all .*
6
5
import org .http4s .client .Client
7
6
import org .http4s .dsl .io .Root
8
7
import org .http4s .headers .`Content-Type`
@@ -46,12 +45,11 @@ class HttpTest extends AnyFunSuite, Matchers {
46
45
)
47
46
}
48
47
.use { response =>
49
- for {
48
+ for
50
49
body <- response.as[String ]
51
- status <- response.status.pure[IO ]
52
- } yield {
50
+ yield {
53
51
assert(body == """ {"sum":3}""" )
54
- assert(status == Status .Ok )
52
+ assert(response. status == Status .Ok )
55
53
assert(response.headers.get[`Content-Type`].map(_.mediaType).contains(MediaTypes .`application/json`))
56
54
}
57
55
}
@@ -78,12 +76,11 @@ class HttpTest extends AnyFunSuite, Matchers {
78
76
)
79
77
}
80
78
.use { response =>
81
- for {
79
+ for
82
80
body <- response.as[String ]
83
- status <- response.status.pure[IO ]
84
- } yield {
81
+ yield {
85
82
assert(body == """ {"value":"Key is: 123"}""" )
86
- assert(status == Status .Ok )
83
+ assert(response. status == Status .Ok )
87
84
assert(response.headers.get[`Content-Type`].map(_.mediaType).contains(MediaTypes .`application/json`))
88
85
}
89
86
}
@@ -104,13 +101,36 @@ class HttpTest extends AnyFunSuite, Matchers {
104
101
.withEntity(""" { "a": 1, "b": 2} """ )
105
102
)
106
103
}
104
+ .use { response =>
105
+ for
106
+ body <- response.as[String ]
107
+ yield {
108
+ assert(body == """ {"sum":3}""" )
109
+ assert(response.status == Status .Ok )
110
+ }
111
+ }
112
+ .unsafeRunSync()
113
+ }
114
+
115
+ test(" return 404 on unknown prefix" ) {
116
+ val service = TestService .bindService(TestServiceImpl , ExecutionContext .global)
117
+
118
+ ConnectRouteBuilder .forService[IO ](service)
119
+ .withPathPrefix(Root / " connect" )
120
+ .build
121
+ .flatMap { app =>
122
+ val client = Client .fromHttpApp(app)
123
+
124
+ client.run(
125
+ Request [IO ](Method .POST , uri " /api/org.ivovk.connect_rpc_scala.test.TestService/Add " )
126
+ .withEntity(""" { "a": 1, "b": 2} """ )
127
+ )
128
+ }
107
129
.use { response =>
108
130
for {
109
131
body <- response.as[String ]
110
- status <- response.status.pure[IO ]
111
132
} yield {
112
- assert(body == """ {"sum":3}""" )
113
- assert(status == Status .Ok )
133
+ assert(response.status == Status .NotFound )
114
134
}
115
135
}
116
136
.unsafeRunSync()
0 commit comments