Skip to content

Commit

Permalink
chore: add ktor testing utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGiulianelli committed May 21, 2023
1 parent d47d72b commit 52614b9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/kotlin/infrastructure/api/KtorTestingUtility.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023. Smart Operating Block
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package infrastructure.api

import infrastructure.database.SurgeryReportDatabase
import infrastructure.database.withMongo
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.install
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.testing.ApplicationTestBuilder
import io.ktor.server.testing.testApplication

object KtorTestingUtility {
fun apiTestApplication(tests: suspend ApplicationTestBuilder.() -> Unit) {
val apiPath = "/api/v1"
val port = 3000
val surgeryReportRepository = SurgeryReportDatabase("mongodb://localhost:27017")
withMongo {
testApplication {
application {
install(ContentNegotiation) {
json()
}
surgeryReportAPI(apiPath, port, surgeryReportRepository)
}
tests()
}
}
}
}

0 comments on commit 52614b9

Please sign in to comment.