Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
testImplementation("io.mockk", "mockk", "1.13.16")
testImplementation("org.jetbrains.kotlinx", "kotlinx-coroutines-test", "1.7.3")
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.10.0")
testImplementation("io.ktor", "ktor-server-test-host", ktorVersion)
}

ktlint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ fun Application.connectDatabase() {
installationLogger.info { "DB connected." }
migrateDatabase(dbConfig)
} else {
// TODO verify handling, maybe exit the App?
installationLogger.error {
"It was not possible to connect to db database! " +
"The application will start but it won't work."
}
error("Unable to connect to the database")
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/kotlin/com/wire/apps/polls/setup/SetupTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.wire.apps.polls.setup

import com.wire.apps.polls.dao.DatabaseSetup
import io.ktor.server.testing.testApplication
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.unmockkObject
import kotlin.test.Test
import kotlin.test.assertFailsWith

class SetupTest {
@Test
fun `connectDatabase throws when connection failed`() =
testApplication {
// Arrange
mockkObject(DatabaseSetup)

every { DatabaseSetup.isConnected() } returns false

// Act & Assert
assertFailsWith<IllegalStateException> {
application.connectDatabase()
}

unmockkObject(DatabaseSetup)
}
}