-
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.
Merge pull request #146 from farmingsoon/develop
배포를 위한 Main merge
- Loading branch information
Showing
7 changed files
with
90 additions
and
24 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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import com.api.farmingsoon.domain.IntegrationTest; | ||
import com.api.farmingsoon.domain.item.domain.Item; | ||
import com.api.farmingsoon.domain.item.domain.ItemStatus; | ||
import com.api.farmingsoon.domain.item.dto.ItemListResponse; | ||
import com.api.farmingsoon.domain.item.dto.LikeableItemListResponse; | ||
import com.api.farmingsoon.domain.item.service.ItemService; | ||
import com.api.farmingsoon.domain.like.service.LikeableItemService; | ||
|
@@ -75,14 +76,14 @@ static void beforeAll() throws IOException { | |
@BeforeEach | ||
void beforeEach(){ | ||
databaseCleanup.execute(); | ||
JoinRequest joinRequest = JoinRequest.builder() | ||
.email("[email protected]") | ||
.nickname("user1") | ||
.password("12345678") | ||
.profileImg(thumbnailImage).build(); | ||
|
||
memberService.join(joinRequest); | ||
|
||
for(int i = 1; i <= 2; i++){ | ||
JoinRequest joinRequest = JoinRequest.builder() | ||
.email("user" + i +"@naver.com") | ||
.nickname("user" + i) | ||
.password("12345678") | ||
.profileImg(thumbnailImage).build(); | ||
memberService.join(joinRequest); | ||
} | ||
Collection<? extends GrantedAuthority> authorities = List.of(new SimpleGrantedAuthority("ROLE_MEMBER")); | ||
|
||
UserDetails principal = new User("[email protected]", "", authorities); | ||
|
@@ -98,12 +99,11 @@ void beforeEach(){ | |
.viewCount(i) | ||
.expiredAt(TimeUtils.setExpireAt(i)).build(); | ||
|
||
|
||
List<String> imageUrl = new ArrayList<>(Arrays.asList("/subFile1/" + i, "/subFile2/" + i, "/subFile3/" + i)); | ||
imageUrl.add(0, "/thumnailImage/" + i); | ||
|
||
Long itemId = itemService.saveItemAndImage(item, imageUrl); | ||
if(itemId % 2 == 0) // 짝수 상품에만 좋아요 등록 | ||
likeableItemService.like(itemId); | ||
itemService.saveItemAndImage(item, imageUrl); | ||
} | ||
|
||
this.mockMvc = MockMvcBuilders.webAppContextSetup(ctx) | ||
|
@@ -118,7 +118,7 @@ void beforeEach(){ | |
* 조회 | ||
*/ | ||
@DisplayName("관심 상품 등록 성공") | ||
@WithUserDetails(value = "user1@naver.com", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@WithUserDetails(value = "user2@naver.com", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@Test | ||
void likeableItemCreateSuccess() throws Exception { | ||
// when | ||
|
@@ -136,12 +136,33 @@ void likeableItemCreateSuccess() throws Exception { | |
} | ||
); | ||
} | ||
@DisplayName("관심 상품 삭제 성공") | ||
@DisplayName("자신의 상품에는 좋아요 등록 불가") | ||
@WithUserDetails(value = "[email protected]", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@Test | ||
void likeableItemCreateFail() throws Exception { | ||
// when | ||
MvcResult mvcResult = mockMvc.perform(post("/api/likeable-items/" + 1)) | ||
.andDo(print()) | ||
.andExpect(status().isForbidden()) | ||
.andReturn(); | ||
//then | ||
transaction.invoke(() -> { | ||
Item item = itemService.getItemById(1L); | ||
Assertions.assertThat(item.getLikeableItemList().size()).isEqualTo(0); | ||
return item.getId(); | ||
} | ||
); | ||
} | ||
|
||
@DisplayName("관심 상품 삭제 성공") | ||
@WithUserDetails(value = "[email protected]", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@Test | ||
void likeableItemDeleteSuccess() throws Exception { | ||
// when | ||
MvcResult mvcResult = mockMvc.perform(delete("/api/likeable-items/" + 2)) | ||
likeableItemService.like((long) 1); | ||
|
||
|
||
MvcResult mvcResult = mockMvc.perform(delete("/api/likeable-items/" + 1)) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
.andReturn(); | ||
|
@@ -155,11 +176,18 @@ void likeableItemDeleteSuccess() throws Exception { | |
} | ||
); | ||
} | ||
|
||
|
||
@DisplayName("관심 상품 조회 성공") | ||
@WithUserDetails(value = "user1@naver.com", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@WithUserDetails(value = "user2@naver.com", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@Test | ||
void getLikeableItemSuccess() throws Exception { | ||
// when | ||
for(int itemId = 1; itemId <= 20; itemId++) { | ||
if (itemId % 2 == 0) // 짝수 상품에만 좋아요 등록 | ||
likeableItemService.like((long) itemId); | ||
} | ||
|
||
MvcResult mvcResult = mockMvc.perform(get("/api/likeable-items/me")) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
|
@@ -170,4 +198,26 @@ void getLikeableItemSuccess() throws Exception { | |
|
||
Assertions.assertThat(likeableItemListResponse.getItems().size()).isEqualTo(10); | ||
} | ||
|
||
@DisplayName("상품 조회시 관심상품 likeStatus는 true") | ||
@WithUserDetails(value = "[email protected]", setupBefore = TestExecutionEvent.TEST_EXECUTION) | ||
@Test | ||
void checkItemLikeStatus() throws Exception { | ||
// when | ||
for(int itemId = 1; itemId <= 20; itemId++) { | ||
if (itemId % 2 == 0) // 짝수 상품에만 좋아요 등록 | ||
likeableItemService.like((long) itemId); | ||
} | ||
|
||
MvcResult mvcResult = mockMvc.perform(get("/api/items")) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
.andReturn(); | ||
//then | ||
String result = objectMapper.readTree(mvcResult.getResponse().getContentAsString()).get("result").toString(); | ||
ItemListResponse itemListResponse = objectMapper.readValue(result, ItemListResponse.class); | ||
|
||
Assertions.assertThat(itemListResponse.getItems().get(0).getLikeStatus()).isEqualTo(true); | ||
Assertions.assertThat(itemListResponse.getItems().get(1).getLikeStatus()).isEqualTo(false); | ||
} | ||
} |