Skip to content

Commit f0793f6

Browse files
refactor(test): refactor mongodb tests
1 parent 3d84e6b commit f0793f6

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/test/kotlin/infrastructure/database/TestMongo.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,33 @@ import io.kotest.matchers.shouldNotBe
1515

1616
class TestMongo : StringSpec({
1717

18-
"Test user operations on mongo db" {
19-
withMongo {
20-
val mockUser = User("1234", "MockPassword!")
21-
22-
val mongoClient = MongoClient("mongodb://localhost:27017")
18+
val mockUser = User("1234", "MockPassword!")
2319

20+
"Test user creation on mongo db" {
21+
withMongo {
22+
val mongoClient = MongoClient("mongodb://localhost:27017").also {
23+
it.getDatabase("user_management").drop()
24+
}
2425
mongoClient.createUser(mockUser) shouldNotBe null
26+
}
27+
}
2528

29+
"Test user deletion on mongo db" {
30+
withMongo {
31+
val mongoClient = MongoClient("mongodb://localhost:27017").also {
32+
it.getDatabase("user_management").drop()
33+
}
34+
mongoClient.createUser(mockUser)
2635
mongoClient.deleteUser(mockUser.userId) shouldBe true
36+
}
37+
}
2738

28-
mongoClient.createUser(mockUser) shouldNotBe null
39+
"Test user retrieve on mongo db" {
40+
withMongo {
41+
val mongoClient = MongoClient("mongodb://localhost:27017").also {
42+
it.getDatabase("user_management").drop()
43+
}
44+
mongoClient.createUser(mockUser)
2945
mongoClient.getUser(mockUser.userId).also {
3046
it shouldNotBe null
3147
it?.userId shouldBe mockUser.userId

0 commit comments

Comments
 (0)