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

[Feature] TalkRoom Comment 등록 API 구현 #28

Merged
merged 2 commits into from
Mar 24, 2024

Conversation

AHNYUNKI
Copy link
Member

💡 연관된 이슈

close #24

📝 작업 내용

  • TalkRoom Comment 등록 API 구현
  • TalkRoom Comment 등록 API 테스트 코드 작성

💬 리뷰 요구 사항

이번 코드는 간단하게 등록 API만 작성한거라 리뷰 요구 사항은 없습니다!

@AHNYUNKI AHNYUNKI added the ✨ Feature 기능 개발 label Mar 24, 2024
@AHNYUNKI AHNYUNKI requested review from pdohyung and jwooo March 24, 2024 06:02
@AHNYUNKI AHNYUNKI self-assigned this Mar 24, 2024
@AHNYUNKI AHNYUNKI linked an issue Mar 24, 2024 that may be closed by this pull request
2 tasks
Copy link
Member

@pdohyung pdohyung 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 +20 to +51
@SpringBootTest
@AutoConfigureMockMvc
class CommentControllerTest {

@MockBean
CommentService commentService;

@Autowired
MockMvc mockMvc;

@Autowired
ObjectMapper objectMapper;

@Test
@DisplayName("유저가 토크방에 자신의 의견을 작성한다.")
void writeComment() throws Exception {
// given
CommentCreateRequest request = CommentCreateRequest.builder()
.content("의견을 작성하다")
.build();

// when // then
mockMvc.perform(post("/v1/talk-rooms/1/comments")
.content(objectMapper.writeValueAsString(request))
.contentType(APPLICATION_JSON)
)
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value("200"))
.andExpect(jsonPath("$.status").value("OK"))
.andExpect(jsonPath("$.message").value("OK"));
}
Copy link
Member

Choose a reason for hiding this comment

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

@Auth에 담겨있는 userId를 넘겨주는 부분을 테스트에서 잘 처리하셨네요.
@MockBean 덕분에 controller -> service의 구간을 쉽게 통과할 수 있나요 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

네네!
@MockBean을 사용하면 테스트 시에는 commentService가 직접 실행되는 것이 아니라 MockBean이 대신 실행되어, 해당 동작이 정상적으로 이루어졌다고 가정하고 테스트를 진행합니다!

Copy link
Member

@jwooo jwooo left a comment

Choose a reason for hiding this comment

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

확인했습니다. 잘 작성해주셔서 수정할 부분은 없는거 같습니다.

고생하셨습니다 👍

@AHNYUNKI AHNYUNKI merged commit 020fcd2 into develop Mar 24, 2024
1 check passed
@AHNYUNKI AHNYUNKI deleted the feature/24-talkroom-comment-create-api branch March 24, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] TalkRoom Comment 등록 API 구현
3 participants