Skip to content

Commit

Permalink
Merge pull request #117 from boostcampwm2023/android/feature/signup
Browse files Browse the repository at this point in the history
닉네임 유효성 검사
  • Loading branch information
HamBP authored Nov 20, 2023
2 parents 69eb865 + fd1d24f commit 180e882
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/android-pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }}
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: |
echo "$DEBUG_KEYSTORE" | base64 -d > keystore.properties
echo "$DEBUG_KEYSTORE" | base64 -d > debug.keystore
echo "$KEYSTORE_PROPERTIES" > keystore.properties
echo "$LOCAL_PROPERTIES" > local.properties
./gradlew testDebugUnitTest --stacktrace
Expand Down
9 changes: 9 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ plugins {
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.navigation.safe.args) 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
8 changes: 8 additions & 0 deletions android/core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ plugins {
alias(libs.plugins.org.jetbrains.kotlin.jvm)
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

dependencies {
testImplementation(libs.junit)
testImplementation(libs.kotest.runner)
testImplementation (libs.kotest.property)
testImplementation (libs.kotest.extentions.junitxml)
api(libs.coroutines)
implementation(libs.inject)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 {
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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
)
)
}
4 changes: 4 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ javaInject = "1"
gms = "20.7.0"

junit = "4.13.2"
kotest = "5.8.0"

retrofit = "2.9.0"
okhttp = "4.11.0"
Expand Down Expand Up @@ -41,6 +42,9 @@ inject = { group = "javax.inject", name = "javax.inject", version.ref = "javaInj

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" }
Expand Down

0 comments on commit 180e882

Please sign in to comment.