-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] : 마이페이지 구매내역, 판매내역 API (#121)
* [fix] : Message 빌더 수정 * [fix] : 이미지 파일 리스트 전송 API @nOAuth추가 * [rename] : AuctionStatus 네이밍 * [feat] : NotificationResponse 에 NotificationId 추가 * [feat] : 구매내역, 판매내역 API 추가 * [style] : BiddingRepository 코드 정리 * [fix] : samesite 에러로 cookie 응답값 변경 * [fix] : 구매내역, 판매내역 메서드 네이밍 변경 * [feat] : AuctionFixture, BiddingFixture 에 id 생성자 생성 * [feat] : UserApiController 구매내역, 판매내역 api 개선 * [fix] : BiddingRepository 구매내역, 판매내역 조회 메서드 개선과 레포테스트 추가 * [test] : 구매내역, 판매내역 통합테스트 추가 (각각 전체, 입찰 중 조회)
- Loading branch information
1 parent
bdacbe4
commit b6ff5c3
Showing
16 changed files
with
309 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
package dev.handsup.user.controller; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.springframework.http.HttpHeaders.*; | ||
import static org.springframework.http.MediaType.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | ||
|
||
import dev.handsup.auction.domain.Auction; | ||
import dev.handsup.auction.domain.auction_field.AuctionStatus; | ||
import dev.handsup.auction.domain.product.product_category.PreferredProductCategory; | ||
import dev.handsup.auction.domain.product.product_category.ProductCategory; | ||
import dev.handsup.auction.domain.product.product_category.ProductCategoryValue; | ||
import dev.handsup.auction.repository.auction.AuctionRepository; | ||
import dev.handsup.auction.repository.product.PreferredProductCategoryRepository; | ||
import dev.handsup.auction.repository.product.ProductCategoryRepository; | ||
import dev.handsup.bidding.domain.Bidding; | ||
import dev.handsup.bidding.repository.BiddingRepository; | ||
import dev.handsup.common.support.ApiTestSupport; | ||
import dev.handsup.fixture.AuctionFixture; | ||
import dev.handsup.fixture.BiddingFixture; | ||
import dev.handsup.fixture.ReviewFixture; | ||
import dev.handsup.fixture.UserFixture; | ||
import dev.handsup.review.domain.Review; | ||
|
@@ -38,16 +46,6 @@ | |
@DisplayName("[User 통합 테스트]") | ||
class UserApiControllerTest extends ApiTestSupport { | ||
|
||
private final JoinUserRequest request = JoinUserRequest.of( | ||
"[email protected]", | ||
user.getPassword(), | ||
user.getNickname(), | ||
user.getAddress().getSi(), | ||
user.getAddress().getGu(), | ||
user.getAddress().getDong(), | ||
user.getProfileImageUrl(), | ||
List.of(1L) | ||
); | ||
@Autowired | ||
private UserReviewLabelRepository userReviewLabelRepository; | ||
@Autowired | ||
|
@@ -62,15 +60,27 @@ class UserApiControllerTest extends ApiTestSupport { | |
private PreferredProductCategoryRepository preferredProductCategoryRepository; | ||
@Autowired | ||
private ProductCategoryRepository productCategoryRepository; | ||
@Autowired | ||
private BiddingRepository biddingRepository; | ||
|
||
@Test | ||
@DisplayName("[[회원가입 API] 회원이 등록되고 회원 ID를 응답한다]") | ||
void joinUserTest() throws Exception { | ||
JoinUserRequest joinUserRequest = JoinUserRequest.of( | ||
"[email protected]", | ||
user.getPassword(), | ||
user.getNickname(), | ||
user.getAddress().getSi(), | ||
user.getAddress().getGu(), | ||
user.getAddress().getDong(), | ||
user.getProfileImageUrl(), | ||
List.of(1L) | ||
); | ||
// when | ||
ResultActions actions = mockMvc.perform( | ||
post("/api/users") | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(request)) | ||
.content(toJson(joinUserRequest)) | ||
); | ||
|
||
// then | ||
|
@@ -172,7 +182,7 @@ void getUserReviewsTest() throws Exception { | |
} | ||
|
||
@Test | ||
@DisplayName("[사용자의 프로필이 반환된다]") | ||
@DisplayName("[[사용자 프로필 조회 API]사용자의 프로필이 반환된다]") | ||
void getUserProfile() throws Exception { | ||
// given | ||
ProductCategory productCategory1 = ProductCategory.from(ProductCategoryValue.BEAUTY_COSMETICS.toString()); | ||
|
@@ -204,4 +214,103 @@ void getUserProfile() throws Exception { | |
.value(ProductCategoryValue.BOOKS.toString())) | ||
.andExpect(jsonPath("$.score").value(user.getScore())); | ||
} | ||
|
||
@Test | ||
@DisplayName("[사용자 구매 내역 조회 API] 사용자 구매 내역을 " | ||
+ "전체/입찰 중/거래 중/완료 별로 경매의 최신 등록 순으로 조회한다") | ||
void getUserBuyHistory_All() throws Exception { | ||
// given | ||
LocalDateTime now = LocalDateTime.now(); | ||
Auction auction1 = AuctionFixture.auction(UserFixture.user(2L, "[email protected]")); | ||
Auction auction2 = AuctionFixture.auction(UserFixture.user(3L, "[email protected]")); | ||
Auction auction3 = AuctionFixture.auction(UserFixture.user(4L, "[email protected]")); | ||
ReflectionTestUtils.setField(auction1, "createdAt", now.minusMinutes(1)); | ||
ReflectionTestUtils.setField(auction2, "createdAt", now); | ||
ReflectionTestUtils.setField(auction3, "createdAt", now.plusMinutes(1)); | ||
productCategoryRepository.saveAll(List.of( | ||
auction1.getProduct().getProductCategory(), | ||
auction2.getProduct().getProductCategory(), | ||
auction3.getProduct().getProductCategory() | ||
)); | ||
auctionRepository.saveAll(List.of(auction1, auction2, auction3)); | ||
Bidding bidding1 = BiddingFixture.bidding(1L, auction1, user); | ||
Bidding bidding2 = BiddingFixture.bidding(2L, auction2, user); | ||
Bidding bidding3 = BiddingFixture.bidding(3L, auction3, user); | ||
biddingRepository.saveAll(List.of(bidding1, bidding2, bidding3)); | ||
|
||
PageRequest pageRequest = PageRequest.of(0, 5); | ||
|
||
// when, then | ||
mockMvc.perform(get("/api/users/buys") | ||
.header(AUTHORIZATION, "Bearer " + accessToken) | ||
.param("auctionStatus", (String)null) | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(pageRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.content.size()").value(3)) | ||
.andExpect(jsonPath("$.content[0].auctionId").value(auction3.getId())) | ||
.andExpect(jsonPath("$.content[1].auctionId").value(auction2.getId())) | ||
.andExpect(jsonPath("$.content[2].auctionId").value(auction1.getId())); | ||
|
||
mockMvc.perform(get("/api/users/buys") | ||
.header(AUTHORIZATION, "Bearer " + accessToken) | ||
.param("auctionStatus", String.valueOf(AuctionStatus.BIDDING)) | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(pageRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.content.size()").value(3)) | ||
.andExpect(jsonPath("$.content[0].auctionId").value(auction3.getId())) | ||
.andExpect(jsonPath("$.content[1].auctionId").value(auction2.getId())) | ||
.andExpect(jsonPath("$.content[2].auctionId").value(auction1.getId())); | ||
} | ||
|
||
@Test | ||
@DisplayName("[사용자 판매 내역 조회 API] 사용자 판매 내역을 " | ||
+ "전체/입찰 중/거래 중/완료 별로 경매의 최신 등록 순으로 조회한다") | ||
void getUserSaleHistory() throws Exception { | ||
// given | ||
LocalDateTime now = LocalDateTime.now(); | ||
Auction auction1 = AuctionFixture.auction(1L, user); | ||
Auction auction2 = AuctionFixture.auction(2L, user); | ||
Auction auction3 = AuctionFixture.auction(3L, user); | ||
ReflectionTestUtils.setField(auction1, "createdAt", now.minusMinutes(1)); | ||
ReflectionTestUtils.setField(auction2, "createdAt", now); | ||
ReflectionTestUtils.setField(auction3, "createdAt", now.plusMinutes(1)); | ||
productCategoryRepository.saveAll(List.of( | ||
auction1.getProduct().getProductCategory(), | ||
auction2.getProduct().getProductCategory(), | ||
auction3.getProduct().getProductCategory() | ||
)); | ||
auctionRepository.saveAll(List.of(auction1, auction2, auction3)); | ||
Bidding bidding1 = BiddingFixture.bidding(1L, auction1, user); | ||
Bidding bidding2 = BiddingFixture.bidding(2L, auction2, user); | ||
Bidding bidding3 = BiddingFixture.bidding(3L, auction3, user); | ||
biddingRepository.saveAll(List.of(bidding1, bidding2, bidding3)); | ||
|
||
PageRequest pageRequest = PageRequest.of(0, 5); | ||
|
||
// when, then | ||
mockMvc.perform(get("/api/users/{userId}/sales", user.getId()) | ||
.header(AUTHORIZATION, "Bearer " + accessToken) | ||
.param("auctionStatus", (String)null) | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(pageRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.content.size()").value(3)) | ||
.andExpect(jsonPath("$.content[0].auctionId").value(auction3.getId())) | ||
.andExpect(jsonPath("$.content[1].auctionId").value(auction2.getId())) | ||
.andExpect(jsonPath("$.content[2].auctionId").value(auction1.getId())); | ||
|
||
mockMvc.perform(get("/api/users/{userId}/sales", user.getId()) | ||
.header(AUTHORIZATION, "Bearer " + accessToken) | ||
.param("auctionStatus", String.valueOf(AuctionStatus.BIDDING)) | ||
.contentType(APPLICATION_JSON) | ||
.content(toJson(pageRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.content.size()").value(3)) | ||
.andExpect(jsonPath("$.content[0].auctionId").value(auction3.getId())) | ||
.andExpect(jsonPath("$.content[1].auctionId").value(auction2.getId())) | ||
.andExpect(jsonPath("$.content[2].auctionId").value(auction1.getId())); | ||
} | ||
|
||
} |
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
1 change: 1 addition & 0 deletions
1
core/src/main/java/dev/handsup/auction/dto/response/AuctionSimpleResponse.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
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
Oops, something went wrong.