Skip to content

Commit b7f7519

Browse files
authored
Merge pull request #6 from stslex/codex/fix-typo-in-codebase
Fix errors and improve tests
2 parents c6bcb9e + 6c1ca00 commit b7f7519

File tree

7 files changed

+88
-80
lines changed

7 files changed

+88
-80
lines changed

app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ application {
2323
val isDevelopment: Boolean = project.ext.has("development")
2424
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
2525
}
26+
27+
tasks.test {
28+
useJUnit()
29+
exclude("**/*$*.class")
30+
}

app/src/main/kotlin/com/stslex/plugins/auth/model/UnauthorizedError.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ enum class UnauthorizedError(
99
) : ApiError {
1010
TOKEN(
1111
messageCode = 1,
12-
message = "Token is Invalid or has been expired"
12+
message = "Token is invalid or has expired"
1313
),
1414
API_KEY(
1515
messageCode = 2,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.stslex
2+
3+
import com.typesafe.config.ConfigFactory
4+
import io.ktor.server.config.ApplicationConfigurationException
5+
import io.ktor.server.config.HoconApplicationConfig
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
import org.junit.runners.Parameterized
9+
import kotlin.test.assertTrue
10+
11+
@RunWith(Parameterized::class)
12+
class AppConfigTest(private val path: String) {
13+
14+
private val config = HoconApplicationConfig(ConfigFactory.load("application.conf"))
15+
16+
@Test
17+
fun propertyExists() {
18+
val result = if (path == "ktor.application.modules") {
19+
getPropertyList(path).isNotEmpty()
20+
} else {
21+
getPropertyString(path).isNotBlank()
22+
}
23+
assertTrue(result, "$path should be present")
24+
}
25+
26+
private fun getPropertyString(path: String): String = try {
27+
config.property(path).getString()
28+
} catch (exception: ApplicationConfigurationException) {
29+
""
30+
}
31+
32+
private fun getPropertyList(path: String): List<String> = try {
33+
config.property(path).getList()
34+
} catch (exception: ApplicationConfigurationException) {
35+
emptyList()
36+
}
37+
38+
private companion object {
39+
@JvmStatic
40+
@Parameterized.Parameters(name = "{0}")
41+
fun data(): Collection<Array<String>> = listOf(
42+
arrayOf("ktor.deployment.port"),
43+
arrayOf("ktor.deployment.host"),
44+
arrayOf("ktor.application.modules"),
45+
arrayOf("postgres.url"),
46+
arrayOf("postgres.user"),
47+
arrayOf("postgres.password"),
48+
arrayOf("apiKey"),
49+
arrayOf("jwt.auth.secret"),
50+
arrayOf("jwt.unAuth.secret")
51+
)
52+
}
53+
}

app/src/test/kotlin/com/stslex/TestAppConfig.kt

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ktor {
2+
deployment {
3+
port = 8080
4+
host = "0.0.0.0"
5+
}
6+
application {
7+
modules = [ com.stslex.ApplicationKt.module ]
8+
}
9+
}
10+
11+
postgres {
12+
url = "jdbc:h2:mem:test"
13+
user = "user"
14+
password = "password"
15+
}
16+
17+
apiKey = "test-key"
18+
19+
jwt {
20+
auth {
21+
secret = "auth-secret"
22+
}
23+
unAuth {
24+
secret = "refresh-secret"
25+
}
26+
}

documentation/documentation.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ paths:
99
- Test
1010
summary: Gets hello test string
1111
description: >
12+
Returns a greeting message for test purposes.
1213
responses:
1314
'200':
14-
description: OK
15+
description: OK

feature/auth/src/main/kotlin/com/stslex/feature/auth/data/AuthRepositoryImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AuthRepositoryImpl(
3030
override suspend fun getUser(
3131
login: String
3232
): AuthUserDataModel? = userDataSource
33-
.getUserByUsername(login)
33+
.getUserByLogin(login)
3434
?.toData()
3535
}
3636

0 commit comments

Comments
 (0)