Skip to content

Commit 777e6ba

Browse files
test(database): add some mongo tests
1 parent da22b98 commit 777e6ba

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ ktor-content-negotiation = { module = "io.ktor:ktor-server-content-negotiation",
2020
ktor-serialization = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
2121
ktor-test = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor" }
2222
logback = { module = "ch.qos.logback:logback-classic", version = "1.4.5" }
23+
testcontainer = { module = "io.kotest.extensions:kotest-extensions-testcontainers", version = "1.3.4" }
2324

2425
[bundles]
25-
kotlin-testing = ["archunit", "kotest-junit5", "kotest-assertions-core", "kotest-assertions-core-jvm", "ktor-test"]
26+
kotlin-testing = ["archunit", "testcontainer", "kotest-junit5", "kotest-assertions-core", "kotest-assertions-core-jvm", "ktor-test"]
2627

2728
[plugins]
2829
dokka = { id ="org.jetbrains.dokka", version = "1.7.20" }
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package infrastructure.database
10+
11+
import entity.healthprofessional.HealthProfessionalData
12+
import entity.user.User
13+
import io.kotest.core.extensions.install
14+
import io.kotest.core.spec.style.StringSpec
15+
import io.kotest.extensions.testcontainers.TestContainerExtension
16+
import io.kotest.matchers.shouldBe
17+
import io.kotest.matchers.shouldNotBe
18+
19+
class TestMongo : StringSpec({
20+
21+
val mockUser = User("00000000", "MockPassword!")
22+
val mockHealthProfessional = HealthProfessionalData.HealthProfessional(
23+
"surgeonID",
24+
"Jack",
25+
"Fritz",
26+
HealthProfessionalData.Gender.MALE,
27+
"1999-20-03",
28+
"jackfritz@gmail.com",
29+
"+39 3328455753",
30+
HealthProfessionalData.HealthProfessionalRole.ANESTHETIST
31+
)
32+
val mongoClient = MongoClient("mongodb://localhost:27017")
33+
34+
install(TestContainerExtension("mongo:latest")) {
35+
withExposedPorts(27017)
36+
}.start()
37+
38+
beforeAny {
39+
mongoClient.getDatabase("user_management").drop()
40+
}
41+
42+
"test the creation of a user in the database" {
43+
mongoClient.createUser(mockUser) shouldNotBe null
44+
}
45+
46+
"test the creation of a health professional in the database" {
47+
mongoClient.createHealthProfessional(mockHealthProfessional) shouldNotBe null
48+
}
49+
50+
"test the retrieve of a user in the database" {
51+
mongoClient.createUser(mockUser)
52+
mongoClient.getUser(mockUser.userId) shouldNotBe null
53+
}
54+
55+
"test the retrieve of a health professional in the database" {
56+
mongoClient.createHealthProfessional(mockHealthProfessional)
57+
mongoClient.getHealthProfessional(mockHealthProfessional.healthProfessionalId) shouldNotBe null
58+
}
59+
60+
"test the delete of a user in the database" {
61+
mongoClient.createUser(mockUser)
62+
mongoClient.getUser(mockUser.userId) shouldNotBe null
63+
mongoClient.deleteUser(mockUser.userId)
64+
mongoClient.getUser(mockUser.userId) shouldBe null
65+
}
66+
67+
"test the delete of a health professional in the database" {
68+
mongoClient.createHealthProfessional(mockHealthProfessional)
69+
mongoClient.getHealthProfessional(mockHealthProfessional.healthProfessionalId) shouldNotBe null
70+
mongoClient.deleteHealthProfessional(mockHealthProfessional.healthProfessionalId)
71+
mongoClient.getHealthProfessional(mockHealthProfessional.healthProfessionalId) shouldBe null
72+
}
73+
})

0 commit comments

Comments
 (0)