Skip to content

Commit c45bb27

Browse files
committed
migrate routing & testApplication no longer auto loads application.conf
1 parent ab6934b commit c45bb27

File tree

1 file changed

+21
-12
lines changed
  • servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor

1 file changed

+21
-12
lines changed

servers/graphql-kotlin-ktor-server/src/test/kotlin/com/expediagroup/graphql/server/ktor/GraphQLPluginTest.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ import io.ktor.http.contentType
3636
import io.ktor.serialization.jackson.jackson
3737
import io.ktor.server.application.Application
3838
import io.ktor.server.application.install
39+
import io.ktor.server.config.*
3940
import io.ktor.server.plugins.statuspages.StatusPages
40-
import io.ktor.server.routing.Routing
41+
import io.ktor.server.routing.*
4142
import io.ktor.server.testing.testApplication
4243
import io.ktor.websocket.Frame
4344
import io.ktor.websocket.readText
@@ -104,7 +105,7 @@ class GraphQLPluginTest {
104105
flow: Int!
105106
}
106107
""".trimIndent()
107-
testApplication {
108+
testModule {
108109
val response = client.get("/sdl")
109110
assertEquals(HttpStatusCode.OK, response.status)
110111
assertEquals(expectedSchema, response.bodyAsText().trim())
@@ -113,7 +114,7 @@ class GraphQLPluginTest {
113114

114115
@Test
115116
fun `server should handle valid GET requests`() {
116-
testApplication {
117+
testModule {
117118
val response = client.get("/graphql") {
118119
parameter("query", "query HelloQuery(\$name: String){ hello(name: \$name) }")
119120
parameter("operationName", "HelloQuery")
@@ -126,7 +127,7 @@ class GraphQLPluginTest {
126127

127128
@Test
128129
fun `server should return Method Not Allowed for Mutation GET requests`() {
129-
testApplication {
130+
testModule {
130131
val response = client.get("/graphql") {
131132
parameter("query", "mutation { foo }")
132133
}
@@ -136,15 +137,15 @@ class GraphQLPluginTest {
136137

137138
@Test
138139
fun `server should return Bad Request for invalid GET requests`() {
139-
testApplication {
140+
testModule {
140141
val response = client.get("/graphql")
141142
assertEquals(HttpStatusCode.BadRequest, response.status)
142143
}
143144
}
144145

145146
@Test
146147
fun `server should handle valid POST requests`() {
147-
testApplication {
148+
testModule {
148149
val client = createClient {
149150
install(ContentNegotiation) {
150151
jackson()
@@ -161,7 +162,7 @@ class GraphQLPluginTest {
161162

162163
@Test
163164
fun `server should handle valid POST batch requests`() {
164-
testApplication {
165+
testModule {
165166
val client = createClient {
166167
install(ContentNegotiation) {
167168
jackson()
@@ -185,7 +186,7 @@ class GraphQLPluginTest {
185186

186187
@Test
187188
fun `server should return Bad Request for invalid POST requests with correct content type`() {
188-
testApplication {
189+
testModule {
189190
val response = client.post("/graphql") {
190191
contentType(ContentType.Application.Json)
191192
}
@@ -195,15 +196,15 @@ class GraphQLPluginTest {
195196

196197
@Test
197198
fun `server should return Unsupported Media Type for POST requests with invalid content type`() {
198-
testApplication {
199+
testModule {
199200
val response = client.post("/graphql")
200201
assertEquals(HttpStatusCode.UnsupportedMediaType, response.status)
201202
}
202203
}
203204

204205
@Test
205206
fun `server should handle subscription requests`() {
206-
testApplication {
207+
testModule {
207208
val client = createClient {
208209
install(ContentNegotiation) {
209210
jackson()
@@ -233,7 +234,7 @@ class GraphQLPluginTest {
233234

234235
@Test
235236
fun `server should provide GraphiQL endpoint`() {
236-
testApplication {
237+
testModule {
237238
val response = client.get("/graphiql")
238239
assertEquals(HttpStatusCode.OK, response.status)
239240

@@ -260,11 +261,19 @@ fun Application.testGraphQLModule() {
260261
}
261262
}
262263
install(io.ktor.server.websocket.WebSockets)
263-
install(Routing) {
264+
routing {
264265
graphQLGetRoute()
265266
graphQLPostRoute()
266267
graphQLSubscriptionsRoute()
267268
graphQLSDLRoute()
268269
graphiQLRoute()
269270
}
270271
}
272+
273+
private fun testModule(block: suspend io.ktor.server.testing.ApplicationTestBuilder.() -> kotlin.Unit) = testApplication {
274+
environment {
275+
config = ApplicationConfig(("application.conf"))
276+
}
277+
block()
278+
}
279+

0 commit comments

Comments
 (0)