-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from boostcampwm2023/android/feature/signup
닉네임 유효성 검사
- Loading branch information
Showing
7 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...main/src/main/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/test/java/com/ohdodok/catchytape/core/domain/signup/NicknameValidationUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
android/core/domain/src/test/java/com/ohdodok/catchytape/core/domain/signup/TestConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters