From 37401a7e1f53ad316a0f4a0a27361a4e3203ae01 Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Fri, 10 Jan 2025 19:30:16 +0900 Subject: [PATCH] =?UTF-8?q?=20test:=20=EC=BD=9C=EB=9D=BC=EB=B3=B4=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94=20(#336)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/domain/list/ListEntity.java | 9 +--- .../list/application/service/ListService.java | 2 +- .../acceptance/list/ListAcceptanceTest.java | 44 +------------------ .../list/ListAcceptanceTestHelper.java | 2 +- .../application/domain/CollaboratorsTest.java | 2 + .../domain/list/ListEntityTest.java | 24 ++++++---- 6 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/listywave/list/application/domain/list/ListEntity.java b/src/main/java/com/listywave/list/application/domain/list/ListEntity.java index 7264101b..967836b9 100644 --- a/src/main/java/com/listywave/list/application/domain/list/ListEntity.java +++ b/src/main/java/com/listywave/list/application/domain/list/ListEntity.java @@ -9,7 +9,6 @@ import static jakarta.persistence.TemporalType.TIMESTAMP; import static lombok.AccessLevel.PROTECTED; -import com.listywave.collaborator.application.domain.Collaborators; import com.listywave.common.exception.CustomException; import com.listywave.list.application.domain.category.CategoryType; import com.listywave.list.application.domain.item.Item; @@ -247,16 +246,10 @@ public void validateOwnerIsNotDeleted() { } } - public void validateUpdateAuthority(User loginUser, Collaborators beforeCollaborators) { + public void validateUpdateAuthority(User loginUser) { if (this.user.equals(loginUser)) { return; } - if (beforeCollaborators.isEmpty()) { - return; - } - if (beforeCollaborators.contains(loginUser)) { - return; - } throw new CustomException(INVALID_ACCESS); } diff --git a/src/main/java/com/listywave/list/application/service/ListService.java b/src/main/java/com/listywave/list/application/service/ListService.java index 5f633f2e..dd40c94a 100644 --- a/src/main/java/com/listywave/list/application/service/ListService.java +++ b/src/main/java/com/listywave/list/application/service/ListService.java @@ -242,7 +242,7 @@ public void update(Long listId, Long loginUserId, ListUpdateRequest request) { ListEntity list = listRepository.getById(listId); Collaborators beforeCollaborators = collaboratorService.findAllByList(list); - list.validateUpdateAuthority(loginUser, beforeCollaborators); + list.validateUpdateAuthority(loginUser); Collaborators newCollaborators = collaboratorService.createCollaborators(request.collaboratorIds(), list); collaboratorService.updateCollaborators(beforeCollaborators, newCollaborators); diff --git a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java index 1f0711c5..7e122cc8 100644 --- a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java +++ b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTest.java @@ -18,9 +18,7 @@ import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_리스트_상세_조회_API_호출; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_피드_리스트_조회_API_호출; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원_히스토리_조회_API_호출; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_카테고리_콜라보레이터_필터링_요청; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_카테고리_필터링_요청; -import static com.listywave.acceptance.list.ListAcceptanceTestHelper.비회원이_피드_리스트_조회_콜라보레이터_필터링_요청; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.아이템_순위와_라벨을_바꾼_좋아하는_견종_TOP3_요청_데이터; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.정렬기준을_포함한_검색_API_호출; import static com.listywave.acceptance.list.ListAcceptanceTestHelper.좋아하는_라면_TOP3_생성_요청_데이터; @@ -380,6 +378,7 @@ class 리스트_수정 { } @Test + @Disabled void 리스트의_작성자와_콜라보레이터만_수정할_수_있다() { // given var 동호 = 회원을_저장한다(동호()); @@ -583,47 +582,6 @@ class 피드_리스트_조회 { .ignoringFields("id") .isEqualTo(기대값); } - - @Test - @Disabled - void 콜라보레이터로_필터링한다() { - // given - var 동호 = 회원을_저장한다(동호()); - var 정수 = 회원을_저장한다(정수()); - var 동호_액세스_토큰 = 액세스_토큰을_발급한다(동호); - var 정수_액세스_토큰 = 액세스_토큰을_발급한다(정수); - var 리스트_1_ID = 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of(정수.getId())), 동호_액세스_토큰) - .as(ListCreateResponse.class) - .listId(); - var 리스트_2_ID = 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of(동호.getId())), 정수_액세스_토큰) - .as(ListCreateResponse.class) - .listId(); - - // when - var 결과 = 비회원이_피드_리스트_조회_콜라보레이터_필터링_요청(동호).as(FindFeedListResponse.class); - - // then - assertThat(결과.feedLists()).hasSize(2); - assertThat(결과.feedLists().get(0).id()).isEqualTo(리스트_2_ID); - assertThat(결과.feedLists().get(1).id()).isEqualTo(리스트_1_ID); - } - - @Test - void 콜라보레이터와_카테고리로_필터링한다() { - // given - var 동호 = 회원을_저장한다(동호()); - var 정수 = 회원을_저장한다(정수()); - var 동호_액세스_토큰 = 액세스_토큰을_발급한다(동호); - 리스트_저장_API_호출(가장_좋아하는_견종_TOP3_생성_요청_데이터(List.of()), 동호_액세스_토큰).as(ListCreateResponse.class); - var 동호_리스트_2 = 리스트_저장_API_호출(좋아하는_라면_TOP3_생성_요청_데이터(List.of(정수.getId())), 동호_액세스_토큰).as(ListCreateResponse.class); - - // when - var 결과 = 비회원이_피드_리스트_조회_카테고리_콜라보레이터_필터링_요청(동호, "etc").as(FindFeedListResponse.class); - - // then - assertThat(결과.feedLists()).hasSize(1); - assertThat(결과.feedLists().get(0).id()).isEqualTo(동호_리스트_2.listId()); - } } @Nested diff --git a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java index b52ce9fe..eaba9ed2 100644 --- a/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java +++ b/src/test/java/com/listywave/acceptance/list/ListAcceptanceTestHelper.java @@ -174,7 +174,7 @@ public abstract class ListAcceptanceTestHelper { .extract(); } - public static ExtractableResponse 비회원이_피드_리스트_조회_카테고리_콜라보레이터_필터링_요청(User targetUser, String category) { + public static ExtractableResponse 비회원이_사용자_피드에서_콜라보리스트를_카테고리로_필터링하여_요청한다(User targetUser, String category) { return given() .when().get("/users/{userId}/lists?type=collabo&category={category}", targetUser.getId(), category) .then().log().all() diff --git a/src/test/java/com/listywave/collaborator/application/domain/CollaboratorsTest.java b/src/test/java/com/listywave/collaborator/application/domain/CollaboratorsTest.java index 4e8629db..478b9f9b 100644 --- a/src/test/java/com/listywave/collaborator/application/domain/CollaboratorsTest.java +++ b/src/test/java/com/listywave/collaborator/application/domain/CollaboratorsTest.java @@ -24,10 +24,12 @@ import java.util.List; import java.util.stream.LongStream; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +@Disabled @DisplayName("Collaboratros는 ") class CollaboratorsTest { diff --git a/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java b/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java index 9eb5cf3e..6de7f193 100644 --- a/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java +++ b/src/test/java/com/listywave/list/application/domain/list/ListEntityTest.java @@ -11,11 +11,10 @@ import static com.listywave.user.fixture.UserFixture.정수; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.listywave.collaborator.application.domain.Collaborator; -import com.listywave.collaborator.application.domain.Collaborators; import com.listywave.common.exception.CustomException; import com.listywave.list.application.domain.category.CategoryType; import com.listywave.list.application.domain.item.Item; @@ -29,6 +28,7 @@ import com.listywave.list.application.domain.label.Labels; import com.listywave.user.application.domain.User; import java.util.List; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -225,23 +225,31 @@ class ListEntityTest { } @Test + @Disabled void 리스트는_작성자_또는_콜라보레이터에_포함된_유저만이_수정할_수_있다() { // given User collaboratorUser = 정수(); - Collaborator collaborator = Collaborator.init(collaboratorUser, list); User notCollaborator = 유진(); - Collaborators collaborators = new Collaborators(List.of(collaborator)); - // when // then assertAll( - () -> assertThatNoException().isThrownBy(() -> list.validateUpdateAuthority(user, collaborators)), - () -> assertThatNoException().isThrownBy(() -> list.validateUpdateAuthority(collaboratorUser, collaborators)), + () -> assertThatNoException().isThrownBy(() -> list.validateUpdateAuthority(user)), + () -> assertThatNoException().isThrownBy(() -> list.validateUpdateAuthority(collaboratorUser)), () -> { - CustomException exception = assertThrows(CustomException.class, () -> list.validateUpdateAuthority(notCollaborator, collaborators)); + CustomException exception = assertThrows(CustomException.class, () -> list.validateUpdateAuthority(notCollaborator)); assertThat(exception.getErrorCode()).isEqualTo(INVALID_ACCESS); } ); } + + @Test + void 리스트는_작성자만이_수정할_수_있다() { + // given + User otherUser = 정수(); + + // expect + assertThatThrownBy(() -> list.validateUpdateAuthority(otherUser)); + assertThatNoException().isThrownBy(() -> list.validateUpdateAuthority(user)); + } }