-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: BadWords Checker 구현 * feat: VoteOption Content VO 구현 * refactor: 텍스트 필드에 욕설 검증 적용 * test: VoteOptionContent Test 추가 * test: MessageContentTest 추가 * test: Introduction Test 추가 * feat: 비속어 판별 API 추가 * test: validate test 추가 * test: ServiceTest 추가 * test: Pagination Test 보강 * test: Test 컴파일 에러 수정 * test: SpringBootTest 제거 * refactor: lastCursorId 추가 * refactor: Transactional 어노테이션 설정 변경 * test: Test 수정 * refactor: CreatedVote 수정 * test: Event Test 추가
- Loading branch information
Showing
83 changed files
with
1,635 additions
and
125 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
app/src/main/kotlin/com/wespot/common/ProfanityController.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,25 @@ | ||
package com.wespot.common | ||
|
||
import com.wespot.common.dto.CheckProfanityRequest | ||
import com.wespot.common.`in`.CheckProfanityUseCase | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/check-profanity") | ||
class ProfanityController( | ||
private val checkProfanityUseCase: CheckProfanityUseCase | ||
) { | ||
|
||
@PostMapping | ||
fun checkProfanity(@RequestBody message: CheckProfanityRequest): ResponseEntity<Unit> { | ||
checkProfanityUseCase.checkProfanity(message) | ||
|
||
return ResponseEntity.noContent() | ||
.build() | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
app/src/test/kotlin/com/wespot/common/domain/ProfanityCheckerTest.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,39 @@ | ||
package com.wespot.common.domain | ||
|
||
import com.wespot.common.ProfanityChecker | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
|
||
class ProfanityCheckerTest : BehaviorSpec({ | ||
|
||
given("사용자가 내용을 입력할 때") { | ||
val badWords = listOf( | ||
"ㅅ_ㅂ", | ||
"ㅅ________________ㅂ", | ||
"너는 ㅅ!ㅂ", | ||
"너는 f@uck" | ||
) | ||
`when`("욕설이 존재하면") { | ||
val allMatch = badWords.stream() | ||
.allMatch { ProfanityChecker.checkProfanity(it) } | ||
then("true를 반환한다.") { | ||
allMatch shouldBe true | ||
} | ||
} | ||
`when`("욕설이 존재하면") { | ||
val shouldThrow1 = shouldThrow<IllegalArgumentException> { ProfanityChecker.validateContent(badWords[0]) } | ||
val shouldThrow2 = shouldThrow<IllegalArgumentException> { ProfanityChecker.validateContent(badWords[1]) } | ||
val shouldThrow3 = shouldThrow<IllegalArgumentException> { ProfanityChecker.validateContent(badWords[2]) } | ||
val shouldThrow4 = shouldThrow<IllegalArgumentException> { ProfanityChecker.validateContent(badWords[3]) } | ||
then("에외를 발생시킨다.") { | ||
shouldThrow1 shouldHaveMessage "비속어가 포함되어 있습니다." | ||
shouldThrow2 shouldHaveMessage "비속어가 포함되어 있습니다." | ||
shouldThrow3 shouldHaveMessage "비속어가 포함되어 있습니다." | ||
shouldThrow4 shouldHaveMessage "비속어가 포함되어 있습니다." | ||
} | ||
} | ||
} | ||
|
||
}) |
38 changes: 38 additions & 0 deletions
38
app/src/test/kotlin/com/wespot/common/service/CheckProfanityServiceTest.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,38 @@ | ||
package com.wespot.common.service | ||
|
||
import com.wespot.common.dto.CheckProfanityRequest | ||
import io.kotest.assertions.throwables.shouldNotThrow | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class CheckProfanityServiceTest @Autowired constructor( | ||
private val checkProfanityService: CheckProfanityService | ||
) : ServiceTest() { | ||
|
||
@Test | ||
fun `욕설이 아닌 값이 입력되면 예외를 반환하지 않는다`() { | ||
// given | ||
val validWord = "안녕" | ||
val checkProfanityRequest = CheckProfanityRequest(validWord) | ||
|
||
// when then | ||
shouldNotThrow<IllegalArgumentException> { checkProfanityService.checkProfanity(checkProfanityRequest) } | ||
} | ||
|
||
@Test | ||
fun `욕설이 입력되면 예외를 반환한다`() { | ||
// given | ||
val badWord = "너는 ㅅ_____________112231ㅂ" | ||
val checkProfanityRequest = CheckProfanityRequest(badWord) | ||
|
||
// when | ||
val shouldThrow = | ||
shouldThrow<IllegalArgumentException> { checkProfanityService.checkProfanity(checkProfanityRequest) } | ||
|
||
// then | ||
shouldThrow shouldHaveMessage "비속어가 포함되어 있습니다." | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
app/src/test/kotlin/com/wespot/message/domain/MessageContentTest.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,35 @@ | ||
package com.wespot.message.domain | ||
|
||
import com.wespot.message.MessageContent | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.throwable.shouldHaveMessage | ||
|
||
class MessageContentTest : BehaviorSpec({ | ||
|
||
given("메시지 컨텐츠에") { | ||
val badWordsContent = "ㅂㅁㄴ이;라ㅓ 싮ㅂㅅㅂㅅㅂㅅㅂ시ㅂ 메시지" | ||
val emptyContent = "" | ||
val validContent = "헬로우" | ||
`when`("욕설이 포함되어 있는 경우") { | ||
val shouldThrow = shouldThrow<IllegalArgumentException> { MessageContent.from(badWordsContent) } | ||
then("예외가 발생한다.") { | ||
shouldThrow shouldHaveMessage "메시지의 내용에 비속어가 포함되어 있습니다." | ||
} | ||
} | ||
`when`("아무런 내용이 없는 경우") { | ||
val shouldThrow = shouldThrow<IllegalArgumentException> { MessageContent.from(emptyContent) } | ||
then("예외가 발생한다.") { | ||
shouldThrow shouldHaveMessage "메시지의 내용은 필수로 존재해야합니다." | ||
} | ||
} | ||
`when`("정상적인 값이 입력되는 경우") { | ||
val messageContent = MessageContent.from(validContent) | ||
then("예외가 발생하지 않는다.") { | ||
messageContent.content shouldBe validContent | ||
} | ||
} | ||
} | ||
|
||
}) |
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
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
Oops, something went wrong.