Skip to content

Commit

Permalink
refactor(test): refactor mongodb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Mar 1, 2023
1 parent 3d84e6b commit f0793f6
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/test/kotlin/infrastructure/database/TestMongo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,33 @@ import io.kotest.matchers.shouldNotBe

class TestMongo : StringSpec({

"Test user operations on mongo db" {
withMongo {
val mockUser = User("1234", "MockPassword!")

val mongoClient = MongoClient("mongodb://localhost:27017")
val mockUser = User("1234", "MockPassword!")

"Test user creation on mongo db" {
withMongo {
val mongoClient = MongoClient("mongodb://localhost:27017").also {
it.getDatabase("user_management").drop()
}
mongoClient.createUser(mockUser) shouldNotBe null
}
}

"Test user deletion on mongo db" {
withMongo {
val mongoClient = MongoClient("mongodb://localhost:27017").also {
it.getDatabase("user_management").drop()
}
mongoClient.createUser(mockUser)
mongoClient.deleteUser(mockUser.userId) shouldBe true
}
}

mongoClient.createUser(mockUser) shouldNotBe null
"Test user retrieve on mongo db" {
withMongo {
val mongoClient = MongoClient("mongodb://localhost:27017").also {
it.getDatabase("user_management").drop()
}
mongoClient.createUser(mockUser)
mongoClient.getUser(mockUser.userId).also {
it shouldNotBe null
it?.userId shouldBe mockUser.userId
Expand Down

0 comments on commit f0793f6

Please sign in to comment.