From 474efe2cdcafec3349d9daf7123d39715b13cb8b Mon Sep 17 00:00:00 2001 From: hong seokho Date: Wed, 8 May 2024 21:14:56 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/fixture/domain/MemberFixture.java | 15 +++++ .../group/service/GroupServiceTest.java | 58 +++++++++---------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberFixture.java index 070acd5bc..275977da0 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberFixture.java @@ -100,4 +100,19 @@ public static List getPhoneBytesList(int start, int count) { return result; } + + /** + * 테스트 픽스처 - 리스트의 {@code Member}의 {@code id}가 주어진 {@code memberId}로 설정된 멤버 엔티티 리스트를 생성한다. + * @param startDataPrefix 시작 id + * @param count 크기 + * @return 리스트의 각 {@code Member}의 {@code id}가 {@code memberId}로 설정된 {@code List} 테스트 픽스처 + */ + public static List membersWithMemberId(int startDataPrefix, int count) { + List result = new ArrayList<>(); + for (int index = startDataPrefix; index < startDataPrefix + count; index++) { + result.add(memberWithMemberId(index)); + } + + return result; + } } \ No newline at end of file diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupServiceTest.java index 510d10964..ee3f2afdf 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupServiceTest.java @@ -32,8 +32,8 @@ *
  • 모든 분기 테스트
  • *
      *
    • 그룹이 없는 경우
    • - *
    • 그룹원이 있는 경우
    • *
    • 그룹장이 아닌 경우
    • + *
    • 그룹원이 있는 경우
    • *
    • 그룹 캡슐이 존재하는 경우
    • *
    • 그룹을 삭제할 수 있는 모든 조건(그룹 존재, 그룹에 속한 그룹원 없음, 요청한 사용자가 그룹장, 그룹 캡슐 없음)을 만족한 경우
    • *
    @@ -76,6 +76,32 @@ class GroupServiceTest { .hasMessageContaining(ErrorCode.GROUP_NOT_FOUND_ERROR.getMessage()); } + @Test + void 그룹장이_아닌_사용자가_그룹_아이디로_삭제를_시도하면_예외가_발생한다() { + //given + Long groupMemberId = 1L; + Long groupId = 1L; + + given(groupRepository.findGroupById(anyLong())).willReturn(group()); + given(memberGroupRepository.findMemberGroupsByGroupId(groupId)).willReturn(notOwnerGroupMember()); + + //when + //then + assertThatThrownBy(() -> groupService.deleteGroup(groupMemberId, groupId)) + .isExactlyInstanceOf(GroupDeleteFailException.class) + .hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage()); + } + + private List notOwnerGroupMember() { + return List.of( + MemberGroupFixture.memberGroup( + MemberFixture.memberWithMemberId(1), + GroupFixture.group(), + false + ) + ); + } + @Test void 그룹원이_존재하는_그룹_아이디로_삭제를_시도하면_예외가_발생한다() { //given @@ -101,10 +127,10 @@ private Optional group() { private List groupMembers() { Group group = GroupFixture.group(); - MemberGroup groupOwner = MemberGroupFixture.groupOwner(MemberFixture.member(1), group); + MemberGroup groupOwner = MemberGroupFixture.groupOwner(MemberFixture.memberWithMemberId(1L), group); List memberGroups = MemberGroupFixture.memberGroups( - MemberFixture.members(2, 4), + MemberFixture.membersWithMemberId(2, 2), group ); @@ -113,32 +139,6 @@ private List groupMembers() { return result; } - @Test - void 그룹장이_아닌_사용자가_그룹_아이디로_삭제를_시도하면_예외가_발생한다() { - //given - Long groupMemberId = 1L; - Long groupId = 1L; - - given(groupRepository.findGroupById(anyLong())).willReturn(group()); - given(memberGroupRepository.findMemberGroupsByGroupId(groupId)).willReturn(notOwnerGroupMember()); - - //when - //then - assertThatThrownBy(() -> groupService.deleteGroup(groupMemberId, groupId)) - .isExactlyInstanceOf(GroupDeleteFailException.class) - .hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage()); - } - - private List notOwnerGroupMember() { - return List.of( - MemberGroupFixture.memberGroup( - MemberFixture.memberWithMemberId(1), - GroupFixture.group(), - false - ) - ); - } - @Test void 그룹_캡슐이_존재하는_그룹_아이디로_삭제를_시도하면_예외가_발생한다() { //given