forked from codesquad-members-2023/second-hand-max
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8428311
commit 99ccc02
Showing
6 changed files
with
167 additions
and
0 deletions.
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
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/codesquard/app/api/membertown/response/MemberTownItemResponse.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,26 @@ | ||
package codesquard.app.api.membertown.response; | ||
|
||
import codesquard.app.domain.membertown.MemberTown; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MemberTownItemResponse { | ||
private Long addressId; | ||
private String fullAddressName; | ||
private String addressName; | ||
private Boolean isSelected; | ||
|
||
public static MemberTownItemResponse from(MemberTown memberTown) { | ||
return new MemberTownItemResponse( | ||
memberTown.getId(), | ||
memberTown.getRegion().getName(), | ||
memberTown.getRegion().getShortAddress(), | ||
memberTown.isSelected() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/codesquard/app/api/membertown/response/MemberTownListResponse.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,17 @@ | ||
package codesquard.app.api.membertown.response; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class MemberTownListResponse { | ||
private List<MemberTownItemResponse> addresses; | ||
|
||
public MemberTownListResponse(List<MemberTownItemResponse> addresses) { | ||
this.addresses = addresses; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
backend/src/test/java/codesquard/app/api/member/MemberControllerTest.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 codesquard.app.api.member; | ||
|
||
import static codesquard.app.MemberTestSupport.*; | ||
import static codesquard.app.MemberTownTestSupport.*; | ||
import static codesquard.app.RegionTestSupport.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentMatchers; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import codesquard.app.ControllerTestSupport; | ||
import codesquard.app.api.membertown.MemberTownService; | ||
import codesquard.app.api.membertown.response.MemberTownItemResponse; | ||
import codesquard.app.api.membertown.response.MemberTownListResponse; | ||
import codesquard.app.domain.member.Member; | ||
import codesquard.app.domain.membertown.MemberTown; | ||
import codesquard.app.domain.oauth.support.Principal; | ||
import codesquard.app.domain.region.Region; | ||
|
||
@WebMvcTest(controllers = MemberController.class) | ||
class MemberControllerTest extends ControllerTestSupport { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private MemberController memberController; | ||
|
||
@MockBean | ||
private MemberTownService memberTownService; | ||
|
||
@MockBean | ||
private MemberService memberService; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
mockMvc = MockMvcBuilders.standaloneSetup(memberController) | ||
.setControllerAdvice(globalExceptionHandler) | ||
.setCustomArgumentResolvers(authPrincipalArgumentResolver) | ||
.alwaysDo(print()) | ||
.build(); | ||
|
||
given(authPrincipalArgumentResolver.supportsParameter(any())).willReturn(true); | ||
|
||
Principal principal = new Principal(1L, "[email protected]", "23Yong", null, null); | ||
given(authPrincipalArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(principal); | ||
} | ||
|
||
@DisplayName("회원은 회원의 동네를 조회할 수 있다") | ||
@Test | ||
public void readALlMemberTowns() throws Exception { | ||
// given | ||
Member member = createMember("avatarUrl", "[email protected]", "23Yong"); | ||
Region region = createRegion("서울 송파구 가락동"); | ||
MemberTown memberTown = createMemberTown(member, region, true); | ||
List<MemberTownItemResponse> itemResponses = List.of(MemberTownItemResponse.from(memberTown)); | ||
MemberTownListResponse response = new MemberTownListResponse(itemResponses); | ||
given(memberTownService.readAll( | ||
ArgumentMatchers.any(Principal.class))) | ||
.willReturn(response); | ||
|
||
// when & then | ||
mockMvc.perform(get("/api/members/regions")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("statusCode").value(equalTo(200))) | ||
.andExpect(jsonPath("message").value(equalTo("회원 동네 목록 조회를 완료하였습니다."))) | ||
.andExpect(jsonPath("data.addresses[*].fullAddressName").value(containsInAnyOrder("서울 송파구 가락동"))) | ||
.andExpect(jsonPath("data.addresses[*].addressName").value(containsInAnyOrder("가락동"))) | ||
.andExpect(jsonPath("data.addresses[*].isSelected").value(containsInAnyOrder(true))); | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import codesquard.app.api.membertown.request.MemberTownAddRequest; | ||
import codesquard.app.api.membertown.request.MemberTownRemoveRequest; | ||
import codesquard.app.api.membertown.response.MemberAddRegionResponse; | ||
import codesquard.app.api.membertown.response.MemberTownListResponse; | ||
import codesquard.app.api.membertown.response.MemberTownRemoveResponse; | ||
import codesquard.app.api.region.request.RegionSelectionRequest; | ||
import codesquard.app.domain.member.Member; | ||
|
@@ -332,4 +333,19 @@ public void selectRegionWithNotRegisteredRegionId() throws JsonProcessingExcepti | |
.extracting("errorCode.message") | ||
.isEqualTo("회원이 등록한 동네만 선택할 수 있습니다."); | ||
} | ||
|
||
@DisplayName("회원은 자신의 회원 동네를 조회할 수 있다") | ||
@Test | ||
public void readAll() throws JsonProcessingException { | ||
// given | ||
Member member = memberRepository.save(createMember("avatarUrlValue", "[email protected]", "23Yong")); | ||
List<Region> regions = regionRepository.saveAll(List.of(createRegion("서울 송파구 가락동"))); | ||
memberTownRepository.saveAll(List.of(createMemberTown(member, regions.get(0), true))); | ||
|
||
// when | ||
MemberTownListResponse response = memberTownService.readAll(Principal.from(member)); | ||
|
||
// then | ||
assertThat(response.getAddresses().size()).isEqualTo(1); | ||
} | ||
} |