Skip to content
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

[Refactor/#329] 테스트 코드 보강 및 개선 #330

Merged
merged 8 commits into from
Aug 11, 2024

Conversation

belljun3395
Copy link
Collaborator

🎫 연관 이슈

resolved: #329

💁‍♂️ PR 내용

  • 테스트 코드 보강 및 개선

🙏 작업

  • mockMvc로 컨트롤러 테스트 변경
  • 테스트 형식 통일되도록 수정

🙈 PR 참고 사항

📸 스크린샷

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@belljun3395 belljun3395 requested a review from hun-ca as a code owner August 8, 2024 14:23
@github-actions github-actions bot added the refactor 기존 기능에 대해 개선할 때 사용됩니다. label Aug 8, 2024
@belljun3395 belljun3395 force-pushed the refactor/#329_belljun3395 branch from 104f00c to d069f02 Compare August 8, 2024 14:23
Copy link
Member

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -75 to 60
this.webTestClient.post()
.uri(uri)
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(body)
.exchange().expectStatus().is2xxSuccessful()
.expectBody().consumeWith(
WebTestClientRestDocumentation.document(
mockMvc.perform(
post(uri)
.content(body)
.contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk)
.andDo(
document(
api.toIdentifier(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 벌써?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저에겐 코파일럿이 있으니까요.!ㅎㅎㅎ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코파일럿이 이런것도 바꿔줘요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해주는건 아니고 복붙하기 쉽게 도와준다..?

Copy link
Member

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙆🏼‍♂️🙆🏼‍♂️

@belljun3395 belljun3395 force-pushed the refactor/#329_belljun3395 branch 3 times, most recently from 64c136e to 8d4cf9b Compare August 9, 2024 10:21
Comment on lines +47 to +50
given("로그인 여부와 상관없이 아티클 조회 요청이 온 상황에서") {
val articleId = 1L
val memberId = 1L
val useCaseIn = ReadArticleUseCaseIn(articleId, memberId)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given을 기준으로 useCaseIn을 선언하였습니다.

val memberId = 1L
val useCaseIn = ReadArticleUseCaseIn(articleId, memberId)

`when`("요청한 아티클과 작가가 존재할 경우") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따로 UC에 분기가 없는 경우 존재를 확인합니다.

Comment on lines +87 to +100
then("아티클과 연관된 정보를 조회한다") {
val useCaseOut = useCase.execute(useCaseIn)
useCaseOut.id shouldBe articleId
useCaseOut.writer.id shouldBe writerId
useCaseOut.writer.name shouldBe writerName
useCaseOut.writer.url shouldBe mainImageURL
useCaseOut.writer.imageUrl shouldBe writerProfileImageURL
useCaseOut.mainImageUrl shouldBe mainImageURL
useCaseOut.title shouldBe title
useCaseOut.content shouldBe content
useCaseOut.problemIds shouldBe problemIds
useCaseOut.category shouldBe CategoryType.ECONOMY.displayName
useCaseOut.views shouldBe views
useCaseOut.workbooks shouldBe emptyList()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then에서 uscaseOut도 검증합니다.

Comment on lines +145 to +149
verify(exactly = 1) { articleDao.selectArticleRecord(any()) }
verify(exactly = 1) { readArticleWriterRecordService.execute(any()) }
verify(exactly = 0) { browseArticleProblemsService.execute(any()) }
verify(exactly = 0) { articleViewCountHandler.browseArticleViewCount(any()) }
verify(exactly = 0) { articleViewHisAsyncHandler.addArticleViewHis(any(), any(), any()) }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given 단위로 동일한 동작 수행을 검증합니다.

@@ -27,69 +29,99 @@ class SaveMemberUseCaseTest : BehaviorSpec({
}

given("회원가입/로그인 요청이 온 상황에서") {
val email = "[email protected]"
val useCaseIn = SaveMemberUseCaseIn(email = email)

`when`("요청의 이메일이 가입 이력이 없는 경우") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

분기가 있는 경우 분기를 기준으로 when을 설정합니다.

@belljun3395 belljun3395 force-pushed the refactor/#329_belljun3395 branch from 8d4cf9b to 2937be3 Compare August 11, 2024 12:27
@belljun3395 belljun3395 requested a review from hun-ca August 11, 2024 12:43
Copy link
Member

@hun-ca hun-ca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 코드 확인했습니다~

@belljun3395 belljun3395 merged commit 3245017 into dev Aug 11, 2024
8 checks passed
belljun3395 added a commit that referenced this pull request Aug 11, 2024
* [Refactor/#329] 테스트 코드 보강 및 개선 (#330)

* [Fix/#338] 구독 학습지 마지막 아티클을 받고 progess를 증가하는 문제해결 (#339)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 기존 기능에 대해 개선할 때 사용됩니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

테스트 코드 보강 및 개선
2 participants