-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
닉네임 유효성 검사 #117
닉네임 유효성 검사 #117
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TestConfig Class가 하는 일에 대해서 설명 부탁드립니다~ ( comment, slack, 또는 대면으로 하셔도 됩니다. ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://kotest.io/docs/extensions/junit_xml.html |
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" | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewModel을 테스트하는 거라면 viewModel 대신 sut라는 변수명을 사용하는 게 좋을 것 같아.
nicknameValidationUseCase도 원래는 sut라는 이름으로 지었지만, sut("닉네임")이라는 코드의 가독성이 떨어지는 것 같아서 usecase 이름을 그대로 사용했어