From 9a62a9f65378ceb209ab2d243b014519afbc3243 Mon Sep 17 00:00:00 2001 From: algosketch <algosketch@gmail.com> Date: Sun, 19 Nov 2023 23:12:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?chore=20:=20kotest=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=B0=8F=20CI=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/android-pull-request-ci.yml | 2 +- android/build.gradle.kts | 9 +++++++++ android/core/domain/build.gradle.kts | 10 +++++++++- .../catchytape/core/domain/signup/TestConfig.kt | 16 ++++++++++++++++ android/gradle/libs.versions.toml | 4 ++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/TestConfig.kt diff --git a/.github/workflows/android-pull-request-ci.yml b/.github/workflows/android-pull-request-ci.yml index 11f050a..82f5461 100644 --- a/.github/workflows/android-pull-request-ci.yml +++ b/.github/workflows/android-pull-request-ci.yml @@ -35,7 +35,7 @@ jobs: DEBUG_KEYSTORE: ${{ secrets.DEBUG_KEYSTORE }} KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }} run: | - echo "$DEBUG_KEYSTORE" | base64 -d > keystore.properties + echo "$DEBUG_KEYSTORE" | base64 -d > debug.keystore echo "$KEYSTORE_PROPERTIES" > keystore.properties ./gradlew testDebugUnitTest --stacktrace diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 874891b..5cfdda4 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -8,4 +8,13 @@ plugins { alias(libs.plugins.hilt) apply false alias(libs.plugins.kotlinx.serialization) apply false } + +tasks.register<Test>("test") { + useJUnitPlatform() + reports { + junitXml.required.set(false) + } + systemProperty("gradle.build.dir", project.buildDir) +} + true // Needed to make the Suppress annotation work for the plugins block \ No newline at end of file diff --git a/android/core/domain/build.gradle.kts b/android/core/domain/build.gradle.kts index dc48cd3..a67a4e6 100644 --- a/android/core/domain/build.gradle.kts +++ b/android/core/domain/build.gradle.kts @@ -3,6 +3,14 @@ plugins { alias(libs.plugins.org.jetbrains.kotlin.jvm) } -dependencies { +tasks.withType<Test>().configureEach { + useJUnitPlatform() +} +dependencies { + testImplementation(libs.junit) + testImplementation(libs.kotest.runner) + testImplementation (libs.kotest.property) + testImplementation (libs.kotest.extentions.junitxml) + implementation("javax.inject:javax.inject:1") } diff --git a/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/TestConfig.kt b/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/TestConfig.kt new file mode 100644 index 0000000..2a00dbe --- /dev/null +++ b/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/TestConfig.kt @@ -0,0 +1,16 @@ +package com.ohdodok.catchytape.core.domain.signup + +import io.kotest.core.config.AbstractProjectConfig +import io.kotest.core.extensions.Extension +import io.kotest.extensions.junitxml.JunitXmlReporter + +class TestConfig : AbstractProjectConfig() { + + override fun extensions(): List<Extension> = listOf( + JunitXmlReporter( + includeContainers = false, // don't write out status for all tests + useTestPathAsName = true, // use the full test path (ie, includes parent test names) + outputDir = "test-results/excludeContainers" + ) + ) +} \ No newline at end of file diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index cfbb623..6525c6e 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -12,6 +12,7 @@ hilt = "2.48" gms = "20.7.0" junit = "4.13.2" +kotest = "5.8.0" retrofit = "2.9.0" okhttp = "4.11.0" @@ -35,6 +36,9 @@ hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.r google-play-services = { group = "com.google.android.gms", name = "play-services-auth", version.ref = "gms" } +kotest-runner = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest"} +kotest-property = { group = "io.kotest", name = "kotest-property", version.ref = "kotest"} +kotest-extentions-junitxml = { group = "io.kotest", name = "kotest-extensions-junitxml", version.ref = "kotest"} junit = { group = "junit", name = "junit", version.ref = "junit" } retrofit = { module = "com.squareup.retrofit2:retrofit", name = "retrofit", version.ref = "retrofit" } From 599315d4a5fc2014471b7cec5a4ad7de17c9659d Mon Sep 17 00:00:00 2001 From: algosketch <algosketch@gmail.com> Date: Sun, 19 Nov 2023 23:23:10 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test=20:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../signup/NicknameValidationUseCase.kt | 17 +++++++ .../signup/NicknameValidationUseCaseTest.kt | 48 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt create mode 100644 android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCaseTest.kt diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt new file mode 100644 index 0000000..1b9c1c0 --- /dev/null +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt @@ -0,0 +1,17 @@ +package com.ohdodok.catchytape.core.domain.signup + +import javax.inject.Inject + +enum class NicknameValidationResult { + VALID, + EMPTY, + INVALID_LENGTH, + INVALID_CHARACTER, +} + +class NicknameValidationUseCase @Inject constructor() { + operator fun invoke(nickname: String): NicknameValidationResult { + return NicknameValidationResult.EMPTY +// TODO("닉네임 유효성 검사 구현") + } +} \ No newline at end of file diff --git a/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCaseTest.kt b/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCaseTest.kt new file mode 100644 index 0000000..5d834ca --- /dev/null +++ b/android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCaseTest.kt @@ -0,0 +1,48 @@ +package com.ohdodok.catchytape.core.domain.signup + +import io.kotest.core.spec.style.BehaviorSpec +import io.kotest.matchers.shouldBe + +class NicknameValidationUseCaseTest : BehaviorSpec() { + private val nicknameValidationUseCase = NicknameValidationUseCase() + + init { + given("유효한 닉네임이 주어지고") { + `when`("유효성을 검사하면") { + then("Valid를 반환한다") { + listOf("아이유", "iu", "20", "가a1_.", "특수문자_.").forEach { + nicknameValidationUseCase(nickname = it) shouldBe NicknameValidationResult.VALID + } + } + } + } + + given("비어 있는 닉네임이 주어지고") { + `when`("유효성을 검사하면") { + then("Empty를 반환한다") { + nicknameValidationUseCase(nickname = "") shouldBe NicknameValidationResult.EMPTY + } + } + } + + given("짧거나 긴 닉네임이 주어지고") { + `when`("유효성을 검사하면") { + then("Invalid length를 반환한다") { + listOf("한", "닉네임을이렇게길게지으면어떡해", "a").forEach { + nicknameValidationUseCase(nickname = it) shouldBe NicknameValidationResult.INVALID_LENGTH + } + } + } + } + + given("사용할 수 없는 문자가 포함된 닉네임이 주어지고") { + `when`("유효성을 검사하면") { + then("Invalid length를 반환한다") { + listOf("안 돼", "특수문자^", "특수문자*").forEach { + nicknameValidationUseCase(nickname = it) shouldBe NicknameValidationResult.INVALID_CHARACTER + } + } + } + } + } +} \ No newline at end of file From ab8b62a5ab3c4ad0becabfbafcc91ca58037eb6e Mon Sep 17 00:00:00 2001 From: algosketch <algosketch@gmail.com> Date: Sun, 19 Nov 2023 23:31:37 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20UseCase=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/domain/signup/NicknameValidationUseCase.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt index 1b9c1c0..1072498 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt @@ -11,7 +11,13 @@ enum class NicknameValidationResult { class NicknameValidationUseCase @Inject constructor() { operator fun invoke(nickname: String): NicknameValidationResult { - return NicknameValidationResult.EMPTY -// TODO("닉네임 유효성 검사 구현") + val regex = "(^[ㄱ-ㅎ가-힣\\w_.]{2,10}$)".toRegex() + + return when { + regex.matches(nickname) -> NicknameValidationResult.VALID + nickname.isBlank() -> NicknameValidationResult.EMPTY + nickname.length !in 2..10 -> NicknameValidationResult.INVALID_LENGTH + else -> NicknameValidationResult.INVALID_CHARACTER + } } } \ No newline at end of file