-
Notifications
You must be signed in to change notification settings - Fork 0
#21 Answer 패키지 테스트 리팩토링 #28
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
Conversation
LeeJaeYun7
commented
Sep 21, 2023
- Answer 패키지의 테스트를 리팩토링하였습니다.
JwtUtil -> JwtService 리팩토링
AnswerDTOTest -> AnswerRequestTest 수정 AnswerServiceTest 클래스 read, update, delete 메소드 추가
f-lab-moony
left a comment
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.
고생 많으셨습니다 ~
코멘트를 좀 남겨 뒀는데, 확인 후 리뷰 재요청 부탁드려요 ~
| this.version = version; | ||
| } | ||
|
|
||
| public void setContent(String content){ |
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.
내용 수정 시 사용되는 메서드 같은데, updateContent로 이름을 바꾸는 건 어떨까요 ?
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.
넵 updateContent로 하는 편이 좋을 것 같네요
수정하겠습니다
|
|
||
| Optional<Member> member = memberRepository.findById(memberId); | ||
| Optional<Question> question = questionRepository.findById(answerRequest.getQuestionId()); | ||
| Member answerMember = memberRepository.findById(memberId).orElse(null); |
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.
Answer의 member와 question이 null이어도 되는건가요 ?
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.
orElseThrow로 값이 없을 시 Exception을 리턴하도록 하는 편이 맞을 것 같습니다
수정했습니다
|
|
||
| Optional<Answer> answer = answerRepository.findById(id); | ||
|
|
||
| if(answer.isEmpty()){ |
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.
이부분 orElseThrow로 합칠 수 있을 것 같아요 ~
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.
넵 그렇게 하는 편이 가독성 측면에서 나을 것 같습니다
| public void emailChangeConfirm(@RequestBody MemberRequest memberRequest) throws Exception { | ||
| logger.info("post emailConfirm"); | ||
| Long memberId = JwtUtil.getMemberId(); | ||
| Long memberId = jwtService.getMemberId(); |
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.
이건 어디에 쓰이고 있나요 ?
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.
memberId 변수가 따로 쓰이는 곳은 없어서, 저 변수는 불필요한 것 같습니다.
jwtService.getMemberId는 해당 메소드(이 경우 emailChangeConfirm)를
멤버가 로그인한 상태에서만 사용할 수 있도록 제한하는 역할을 합니다.
| CustomAuthenticationEntryPoint customAuthenticationEntryPoint; | ||
|
|
||
| @MockBean | ||
| JwtUtil jwtUtil; |
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.
이거 사라지지 않았나요 ?
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.
넵 피드백 반영했습니다
| AnswerService answerService; | ||
|
|
||
| @MockBean | ||
| CustomOAuth2UserService customOAuth2UserService; |
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.
다른 서비스들은 안쓰이는 거 아닌가요 ?
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.
이거 안 넣어주면 에러가 나더라고요
아마 Spring Security 적용한 부분과 관련이 있는 것 같습니다
| .andDo(print()) | ||
| .andExpect(status().isCreated()); | ||
|
|
||
| verify(answerService).createAnswer(any(AnswerRequest.class)); |
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.
이런 경우에는 any보다는 실제 요청이 잘 반환되었는지 파라미터 값도 검증하는게 좋을 것 같아요~
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.
해당 요청을 AnswerService 테스트 클래스에서 검증해서 여기서는 따로 필요 없을 것 같습니다!
verify문 자체를 삭제하는쪽으로 생각했습니다
| @BeforeEach | ||
| void setUp() throws Exception { | ||
|
|
||
| AnswerRequest validAnswerRequest = AnswerRequest.builder() |
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.
valid랑 invalid랑 차이가 뭐에요 ?
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.
valid는 유효한 경우, invalid는 유효하지 않은 경우인데,
AnswerRequest DTO에서 Objects.requireNonNull로 검사한다고 해서
invalidRequest에 대한 테스트는 작성하지 않았습니다.
이건 빼도 괜찮을 것 같습니다
| .content("답안입니다.") | ||
| .build(); | ||
|
|
||
| assertThat(answerRequest.getContent()).isEqualTo("답안입니다."); |
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.
content만 확인하는 이유가 있을까요 ?
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.
questionId도 검증하도록 추가했습니다
AnswerRequest 클래스 수정
AnswerRequest 클래스 수정2
AnswerReadWebControllerTest, AnswerServiceTest 수정
#28 QuestionController getAllQuestions 메소드 추가