-
Notifications
You must be signed in to change notification settings - Fork 7
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
[BE/TEST] 각종 테스트 #376
Merged
[BE/TEST] 각종 테스트 #376
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a6df9fc
test/#359: DeleteMember 통합 테스트
LJH098 c4347cc
test/#359: DeleteMember 통합 테스트 수정
LJH098 6d46346
Merge branch 'be' of https://github.com/JNU-econovation/Gaebaljip int…
LJH098 9a32755
test/#359: UpdateMember 통합 테스트
LJH098 7a56cdd
test/#359: UpdateMember Controller 테스트
LJH098 d7938a2
test/#359: LoggingFilter 수정
LJH098 44fc422
test/#359: EmitterControllerTest
LJH098 385db5f
test/#359: UpdateWeightController 테스트
LJH098 a4ff9e7
test/#359: UpdateWeight 통합 테스트
LJH098 296720b
test/#359: GetWeight 통합 테스트
LJH098 3a713d2
test/#359: DeleteMemberIntegrationTest 수정
LJH098 80c4da3
Merge branch 'be' of https://github.com/JNU-econovation/Gaebaljip int…
LJH098 8eeb5d6
conflict resolve
LJH098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
...d/src/test/java/com/gaebaljip/exceed/infrastructure/adapter/in/EmitterControllerTest.java
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.gaebaljip.exceed.infrastructure.adapter.in; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | ||
|
||
import com.gaebaljip.exceed.common.ControllerTest; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.infrastructure.sse.adapter.in.EmitterController; | ||
import com.gaebaljip.exceed.infrastructure.sse.application.port.in.ConnectEmitterUseCase; | ||
|
||
@WebMvcTest(EmitterController.class) | ||
public class EmitterControllerTest extends ControllerTest { | ||
|
||
@MockBean private ConnectEmitterUseCase connectEmitterUseCase; | ||
|
||
@Test | ||
@WithMockUser(memberId = 1L) | ||
void when_connect_expected_success() throws Exception { | ||
|
||
// given | ||
given(connectEmitterUseCase.execute(any(), any())).willReturn(new SseEmitter()); | ||
|
||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform(get("/api/emitter/connect").contentType("text/event-stream")); | ||
|
||
// then | ||
resultActions.andExpect(status().isOk()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
BE/exceed/src/test/java/com/gaebaljip/exceed/member/DeleteMemberIntegrationTest.java
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,55 @@ | ||
package com.gaebaljip.exceed.member; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.gaebaljip.exceed.common.IntegrationTest; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberRepository; | ||
|
||
public class DeleteMemberIntegrationTest extends IntegrationTest { | ||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@WithMockUser(memberId = 1L) | ||
@DisplayName("회원 탈퇴 성공") | ||
void deleteMember() throws Exception { | ||
|
||
// given | ||
long memberId = 1L; | ||
// when | ||
ResultActions resultActions = mockMvc.perform(delete("/v1/members")); | ||
|
||
// eye | ||
String responseBody = resultActions.andReturn().getResponse().getContentAsString(); | ||
|
||
// then | ||
resultActions.andExpect(status().isOk()); | ||
assertAll(() -> assertFalse(memberRepository.existsById(memberId))); | ||
} | ||
|
||
@Test | ||
@WithMockUser(memberId = 100000L) | ||
@DisplayName("회원 탈퇴 실패 : 회원이 존재하지 않음") | ||
void deleteMember_fail() throws Exception { | ||
|
||
// given | ||
|
||
// when | ||
ResultActions resultActions = mockMvc.perform(delete("/v1/members")); | ||
|
||
// eye | ||
String responseBody = resultActions.andReturn().getResponse().getContentAsString(); | ||
|
||
// then | ||
resultActions.andExpectAll(status().isBadRequest(), jsonPath("$.error.code").value("4448")); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
BE/exceed/src/test/java/com/gaebaljip/exceed/member/GetWeightIntegrationTest.java
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,40 @@ | ||
package com.gaebaljip.exceed.member; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.gaebaljip.exceed.common.IntegrationTest; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberEntity; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberRepository; | ||
|
||
public class GetWeightIntegrationTest extends IntegrationTest { | ||
|
||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@WithMockUser(memberId = 1L) | ||
@DisplayName("몸무게 조회 성공") | ||
void when_getWeight_expected_success() throws Exception { | ||
// given | ||
long memberId = 1L; | ||
|
||
// when | ||
ResultActions resultActions = mockMvc.perform(get("/v1/members/weight")); | ||
|
||
MemberEntity member = memberRepository.findById(memberId).get(); | ||
|
||
// then | ||
resultActions.andExpect(status().isOk()); | ||
assertAll( | ||
() -> assertEquals(member.getWeight(), 70.0), | ||
() -> assertEquals(member.getTargetWeight(), 68.0)); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
BE/exceed/src/test/java/com/gaebaljip/exceed/member/UpdateMemberIntegrationTest.java
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,85 @@ | ||
package com.gaebaljip.exceed.member; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.gaebaljip.exceed.common.IntegrationTest; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.dto.request.UpdateMemberRequest; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberEntity; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberRepository; | ||
import com.gaebaljip.exceed.member.exception.MemberError; | ||
|
||
public class UpdateMemberIntegrationTest extends IntegrationTest { | ||
|
||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@WithMockUser(memberId = 1L) | ||
@DisplayName("회원 수정 성공") | ||
void when_updateMember_expected_success() throws Exception { | ||
// given | ||
Long memberId = 1L; | ||
|
||
UpdateMemberRequest updateMemberRequest = | ||
UpdateMemberRequest.builder() | ||
.height(180.3) | ||
.activity("VERY_ACTIVE") | ||
.age(40) | ||
.gender("MALE") | ||
.etc("회원 수정") | ||
.build(); | ||
|
||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
put("/v1/members") | ||
.content(om.writeValueAsString(updateMemberRequest)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
MemberEntity member = memberRepository.findById(memberId).get(); | ||
// then | ||
resultActions.andExpectAll(status().isOk()); | ||
assertAll( | ||
() -> assertEquals(member.getHeight(), updateMemberRequest.height()), | ||
() -> assertEquals(member.getActivity().name(), updateMemberRequest.activity()), | ||
() -> assertEquals(member.getAge(), updateMemberRequest.age()), | ||
() -> assertEquals(member.getGender().name(), updateMemberRequest.gender()), | ||
() -> assertEquals(member.getEtc(), updateMemberRequest.etc())); | ||
} | ||
|
||
@Test | ||
@WithMockUser(memberId = 1000L) | ||
@DisplayName("회원 수정 실패 - 회원이 존재하지 않음") | ||
void when_updateMember_member_invalid_expected_exception() throws Exception { | ||
// given | ||
UpdateMemberRequest updateMemberRequest = | ||
UpdateMemberRequest.builder() | ||
.height(180.3) | ||
.activity("VERY_ACTIVE") | ||
.age(40) | ||
.gender("MALE") | ||
.etc("회원 수정") | ||
.build(); | ||
|
||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
put("/v1/members") | ||
.content(om.writeValueAsString(updateMemberRequest)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
|
||
// then | ||
resultActions.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.error.reason").value(MemberError.INVALID_MEMBER.getReason())); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
BE/exceed/src/test/java/com/gaebaljip/exceed/member/UpdateWeightIntegrationTest.java
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,46 @@ | ||
package com.gaebaljip.exceed.member; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.gaebaljip.exceed.common.IntegrationTest; | ||
import com.gaebaljip.exceed.common.WithMockUser; | ||
import com.gaebaljip.exceed.dto.request.UpdateWeightRequest; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberEntity; | ||
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberRepository; | ||
|
||
public class UpdateWeightIntegrationTest extends IntegrationTest { | ||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@DisplayName("몸무게 수정 성공") | ||
@WithMockUser(memberId = 1L) | ||
void when_updateWeight_expected_success() throws Exception { | ||
// given | ||
Long memberId = 1L; | ||
UpdateWeightRequest updateWeightRequest = | ||
UpdateWeightRequest.builder().weight(50.0).targetWeight(70.5).build(); | ||
|
||
// when | ||
ResultActions resultActions = | ||
mockMvc.perform( | ||
patch("/v1/members/weight") | ||
.content(om.writeValueAsString(updateWeightRequest)) | ||
.contentType(MediaType.APPLICATION_JSON)); | ||
MemberEntity member = memberRepository.findById(memberId).get(); | ||
|
||
// then | ||
resultActions.andExpectAll(status().isOk()); | ||
assertAll( | ||
() -> assertEquals(updateWeightRequest.weight(), member.getWeight()), | ||
() -> assertEquals(updateWeightRequest.targetWeight(), member.getTargetWeight())); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
그런데 굳이 이벤트까지 써가면서 결합도를 낮췄는데 테스트에서 결합도를 높일 필요가 있나 싶어요
Controller 테스트에서 이벤트가 잘 publish되는지 테스트도 하고 있어서 굳이 다른 데이터가 삭제 되었는지 확인 할필요 없지않나
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.
테스트의 목적이 해당 기능이 의도하는 데로 확인하는 거 아닌가요?
결합도가 올라간다고 통합 테스트시 해야갈 검증을 안 하는 거는 옳지 않다고 생각합니다.