diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bee8595..0ae9536 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -23,3 +23,8 @@ application { val isDevelopment: Boolean = project.ext.has("development") applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") } + +tasks.test { + useJUnit() + exclude("**/*$*.class") +} diff --git a/app/src/main/kotlin/com/stslex/plugins/auth/model/UnauthorizedError.kt b/app/src/main/kotlin/com/stslex/plugins/auth/model/UnauthorizedError.kt index ce65d9d..75c608c 100644 --- a/app/src/main/kotlin/com/stslex/plugins/auth/model/UnauthorizedError.kt +++ b/app/src/main/kotlin/com/stslex/plugins/auth/model/UnauthorizedError.kt @@ -9,7 +9,7 @@ enum class UnauthorizedError( ) : ApiError { TOKEN( messageCode = 1, - message = "Token is Invalid or has been expired" + message = "Token is invalid or has expired" ), API_KEY( messageCode = 2, diff --git a/app/src/test/kotlin/com/stslex/AppConfigTest.kt b/app/src/test/kotlin/com/stslex/AppConfigTest.kt new file mode 100644 index 0000000..2230618 --- /dev/null +++ b/app/src/test/kotlin/com/stslex/AppConfigTest.kt @@ -0,0 +1,53 @@ +package com.stslex + +import com.typesafe.config.ConfigFactory +import io.ktor.server.config.ApplicationConfigurationException +import io.ktor.server.config.HoconApplicationConfig +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import kotlin.test.assertTrue + +@RunWith(Parameterized::class) +class AppConfigTest(private val path: String) { + + private val config = HoconApplicationConfig(ConfigFactory.load("application.conf")) + + @Test + fun propertyExists() { + val result = if (path == "ktor.application.modules") { + getPropertyList(path).isNotEmpty() + } else { + getPropertyString(path).isNotBlank() + } + assertTrue(result, "$path should be present") + } + + private fun getPropertyString(path: String): String = try { + config.property(path).getString() + } catch (exception: ApplicationConfigurationException) { + "" + } + + private fun getPropertyList(path: String): List = try { + config.property(path).getList() + } catch (exception: ApplicationConfigurationException) { + emptyList() + } + + private companion object { + @JvmStatic + @Parameterized.Parameters(name = "{0}") + fun data(): Collection> = listOf( + arrayOf("ktor.deployment.port"), + arrayOf("ktor.deployment.host"), + arrayOf("ktor.application.modules"), + arrayOf("postgres.url"), + arrayOf("postgres.user"), + arrayOf("postgres.password"), + arrayOf("apiKey"), + arrayOf("jwt.auth.secret"), + arrayOf("jwt.unAuth.secret") + ) + } +} diff --git a/app/src/test/kotlin/com/stslex/TestAppConfig.kt b/app/src/test/kotlin/com/stslex/TestAppConfig.kt deleted file mode 100644 index 756a0a2..0000000 --- a/app/src/test/kotlin/com/stslex/TestAppConfig.kt +++ /dev/null @@ -1,77 +0,0 @@ -package com.stslex - -import com.typesafe.config.ConfigFactory -import io.ktor.server.config.* -import org.junit.Test -import kotlin.test.assertTrue - -class TestAppConfig { - - private val config = HoconApplicationConfig(ConfigFactory.load()) - - @Test - fun ktorDeploymentPort() { - val property = getPropertyString("ktor.deployment.port") - assertTrue(property.isNotBlank()) - } - - @Test - fun ktorDeploymentHost() { - val property = getPropertyString("ktor.deployment.host") - assertTrue(property.isNotBlank()) - } - - @Test - fun ktorApplicationModules() { - val property = getPropertyList("ktor.application.modules") - assertTrue(property.isNotEmpty()) - } - - @Test - fun postgresUrl() { - val property = getPropertyString("postgres.url") - assertTrue(property.isNotBlank()) - } - - @Test - fun postgresUser() { - val property = getPropertyString("postgres.user") - assertTrue(property.isNotBlank()) - } - - @Test - fun postgresPassword() { - val property = getPropertyString("postgres.password") - assertTrue(property.isNotBlank()) - } - - @Test - fun apiKey() { - val property = getPropertyString("apiKey") - assertTrue(property.isNotBlank()) - } - - @Test - fun jwtAuthSecret() { - val property = getPropertyString("jwt.auth.secret") - assertTrue(property.isNotBlank()) - } - - @Test - fun jwtUnAuthSecret() { - val property = getPropertyString("jwt.unAuth.secret") - assertTrue(property.isNotBlank()) - } - - private fun getPropertyString(path: String): String = try { - config.property(path).getString() - } catch (exception: ApplicationConfigurationException) { - "" - } - - private fun getPropertyList(path: String): List = try { - config.property(path).getList() - } catch (exception: ApplicationConfigurationException) { - emptyList() - } -} \ No newline at end of file diff --git a/app/src/test/resources/application.conf b/app/src/test/resources/application.conf new file mode 100644 index 0000000..84aa69b --- /dev/null +++ b/app/src/test/resources/application.conf @@ -0,0 +1,26 @@ +ktor { + deployment { + port = 8080 + host = "0.0.0.0" + } + application { + modules = [ com.stslex.ApplicationKt.module ] + } +} + +postgres { + url = "jdbc:h2:mem:test" + user = "user" + password = "password" +} + +apiKey = "test-key" + +jwt { + auth { + secret = "auth-secret" + } + unAuth { + secret = "refresh-secret" + } +} diff --git a/documentation/documentation.yaml b/documentation/documentation.yaml index f4b6fd5..b0a81e1 100644 --- a/documentation/documentation.yaml +++ b/documentation/documentation.yaml @@ -9,6 +9,7 @@ paths: - Test summary: Gets hello test string description: > + Returns a greeting message for test purposes. responses: '200': - description: OK \ No newline at end of file + description: OK diff --git a/feature/auth/src/main/kotlin/com/stslex/feature/auth/data/AuthRepositoryImpl.kt b/feature/auth/src/main/kotlin/com/stslex/feature/auth/data/AuthRepositoryImpl.kt index 2b021de..a75b7f4 100644 --- a/feature/auth/src/main/kotlin/com/stslex/feature/auth/data/AuthRepositoryImpl.kt +++ b/feature/auth/src/main/kotlin/com/stslex/feature/auth/data/AuthRepositoryImpl.kt @@ -30,7 +30,7 @@ class AuthRepositoryImpl( override suspend fun getUser( login: String ): AuthUserDataModel? = userDataSource - .getUserByUsername(login) + .getUserByLogin(login) ?.toData() }