|
| 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