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
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ application {
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

tasks.test {
useJUnit()
exclude("**/*$*.class")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions app/src/test/kotlin/com/stslex/AppConfigTest.kt
Original file line number Diff line number Diff line change
@@ -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<String> = try {
config.property(path).getList()
} catch (exception: ApplicationConfigurationException) {
emptyList()
}

private companion object {
@JvmStatic
@Parameterized.Parameters(name = "{0}")
fun data(): Collection<Array<String>> = 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")
)
}
}
77 changes: 0 additions & 77 deletions app/src/test/kotlin/com/stslex/TestAppConfig.kt

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 2 additions & 1 deletion documentation/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ paths:
- Test
summary: Gets hello test string
description: >
Returns a greeting message for test purposes.
responses:
'200':
description: OK
description: OK
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuthRepositoryImpl(
override suspend fun getUser(
login: String
): AuthUserDataModel? = userDataSource
.getUserByUsername(login)
.getUserByLogin(login)
?.toData()
}

Loading