From 8e0155f5aaa57116a2525467d9309a711f0529c9 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Wed, 15 May 2024 12:16:29 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixture/domain/MemberGroupFixture.java | 2 +- .../common/fixture/dto/GroupDtoFixture.java | 2 +- .../GroupCapsuleQueryRepositoryTest.java | 2 +- .../MemberGroupQueryRepositoryTest.java | 4 +- ...Test.java => GroupCommandServiceTest.java} | 178 ++-------------- .../GroupMemberCommandServiceTest.java | 196 ++++++++++++++++++ 6 files changed, 215 insertions(+), 169 deletions(-) rename backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/{GroupWriteServiceTest.java => GroupCommandServiceTest.java} (52%) create mode 100644 backend/core/src/test/java/site/timecapsulearchive/core/domain/group_member/service/GroupMemberCommandServiceTest.java diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberGroupFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberGroupFixture.java index 0237e4212..68b03fbaf 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberGroupFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/MemberGroupFixture.java @@ -4,7 +4,7 @@ import java.lang.reflect.Field; import java.util.List; import site.timecapsulearchive.core.domain.group.entity.Group; -import site.timecapsulearchive.core.domain.group.entity.MemberGroup; +import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup; import site.timecapsulearchive.core.domain.member.entity.Member; public class MemberGroupFixture { diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/GroupDtoFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/GroupDtoFixture.java index ca4196785..ffe3c0252 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/GroupDtoFixture.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/dto/GroupDtoFixture.java @@ -2,7 +2,7 @@ import java.util.List; import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto; -import site.timecapsulearchive.core.domain.group.data.dto.GroupOwnerSummaryDto; +import site.timecapsulearchive.core.domain.group_member.data.GroupOwnerSummaryDto; public class GroupDtoFixture { diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java index 7965e63a6..0a9d98dfe 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/capsule/group_capsule/repository/GroupCapsuleQueryRepositoryTest.java @@ -33,7 +33,7 @@ import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin; import site.timecapsulearchive.core.domain.group.data.dto.GroupMemberSummaryDto; import site.timecapsulearchive.core.domain.group.entity.Group; -import site.timecapsulearchive.core.domain.group.entity.MemberGroup; +import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup; import site.timecapsulearchive.core.domain.member.entity.Member; @TestConstructor(autowireMode = AutowireMode.ALL) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepositoryTest.java index 08f0234d4..c09ecd314 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/repository/MemberGroupQueryRepositoryTest.java @@ -25,9 +25,7 @@ import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto; import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto; import site.timecapsulearchive.core.domain.group.entity.Group; -import site.timecapsulearchive.core.domain.group.entity.MemberGroup; -import site.timecapsulearchive.core.domain.group.repository.groupRepository.GroupQueryRepository; -import site.timecapsulearchive.core.domain.group.repository.groupRepository.GroupQueryRepositoryImpl; +import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup; import site.timecapsulearchive.core.domain.member.entity.Member; @TestConstructor(autowireMode = AutowireMode.ALL) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupCommandServiceTest.java similarity index 52% rename from backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java rename to backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupCommandServiceTest.java index ea715b5dd..f8246fc22 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupWriteServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group/service/GroupCommandServiceTest.java @@ -24,26 +24,21 @@ import site.timecapsulearchive.core.common.fixture.dto.GroupDtoFixture; import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository; import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto; -import site.timecapsulearchive.core.domain.group.data.dto.GroupOwnerSummaryDto; import site.timecapsulearchive.core.domain.group.entity.Group; -import site.timecapsulearchive.core.domain.group.entity.MemberGroup; import site.timecapsulearchive.core.domain.group.exception.GroupDeleteFailException; -import site.timecapsulearchive.core.domain.group.exception.GroupInviteNotFoundException; import site.timecapsulearchive.core.domain.group.exception.GroupNotFoundException; -import site.timecapsulearchive.core.domain.group.exception.GroupOwnerAuthenticateException; -import site.timecapsulearchive.core.domain.group.repository.groupInviteRepository.GroupInviteRepository; -import site.timecapsulearchive.core.domain.group.repository.groupRepository.GroupRepository; -import site.timecapsulearchive.core.domain.group.repository.memberGroupRepository.MemberGroupRepository; -import site.timecapsulearchive.core.domain.group.service.write.GroupWriteService; -import site.timecapsulearchive.core.domain.group.service.write.GroupWriteServiceImpl; -import site.timecapsulearchive.core.domain.member.entity.Member; +import site.timecapsulearchive.core.domain.group.repository.GroupRepository; +import site.timecapsulearchive.core.domain.group.service.command.GroupCommandService; +import site.timecapsulearchive.core.domain.group_member.entity.MemberGroup; +import site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository.GroupInviteRepository; +import site.timecapsulearchive.core.domain.group_member.repository.memberGroupRepository.MemberGroupRepository; import site.timecapsulearchive.core.domain.member.exception.MemberNotFoundException; import site.timecapsulearchive.core.domain.member.repository.MemberRepository; import site.timecapsulearchive.core.global.error.ErrorCode; import site.timecapsulearchive.core.infra.queue.manager.SocialNotificationManager; import site.timecapsulearchive.core.infra.s3.manager.S3ObjectManager; -class GroupWriteServiceTest { +class GroupCommandServiceTest { private final MemberRepository memberRepository = mock(MemberRepository.class); private final GroupRepository groupRepository = mock(GroupRepository.class); @@ -56,7 +51,7 @@ class GroupWriteServiceTest { GroupCapsuleQueryRepository.class); private final S3ObjectManager s3ObjectManager = mock(S3ObjectManager.class); - private final GroupWriteService groupWriteService = new GroupWriteServiceImpl( + private final GroupCommandService groupCommandService = new GroupCommandService( memberRepository, groupRepository, memberGroupRepository, @@ -77,7 +72,7 @@ class GroupWriteServiceTest { Optional.of(MemberFixture.member(1))); //when - groupWriteService.createGroup(memberId, dto); + groupCommandService.createGroup(memberId, dto); //then verify(socialNotificationManager, times(1)).sendGroupInviteMessage( @@ -94,155 +89,11 @@ class GroupWriteServiceTest { //when //then - assertThatThrownBy(() -> groupWriteService.createGroup(memberId, dto)) + assertThatThrownBy(() -> groupCommandService.createGroup(memberId, dto)) .isInstanceOf(MemberNotFoundException.class) .hasMessageContaining(ErrorCode.MEMBER_NOT_FOUND_ERROR.getMessage()); } - - @Test - void 그룹장이_그룹원에게_그룹초대를_하면_그룹초대_알림이_요청된다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - Member groupOwner = MemberFixture.member(1); - GroupOwnerSummaryDto groupOwnerSummaryDto = GroupDtoFixture.groupOwnerSummaryDto(true); - - given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); - given(memberRepository.findMemberById(targetId)).willReturn( - Optional.of(MemberFixture.member(2))); - given(groupRepository.findGroupById(groupId)).willReturn(Optional.of(GroupFixture.group())); - given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( - Optional.of(groupOwnerSummaryDto)); - - //when - groupWriteService.inviteGroup(memberId, groupId, targetId); - - //then - verify(socialNotificationManager, times(1)).sendGroupInviteMessage(anyString(), anyString(), - anyList()); - } - - @Test - void 그룹장이_그룹초대를_할_때_존재하지_않은_그룹_아이디_이면_예외가_발생한다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - Member groupOwner = MemberFixture.member(1); - - given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); - given(memberRepository.findMemberById(targetId)).willReturn( - Optional.of(MemberFixture.member(2))); - given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( - Optional.empty()); - - //when - //then - assertThatThrownBy(() -> groupWriteService.inviteGroup(memberId, groupId, targetId)) - .isInstanceOf(GroupNotFoundException.class) - .hasMessageContaining(ErrorCode.GROUP_NOT_FOUND_ERROR.getMessage()); - } - - @Test - void 그룹장이_아닌_사용자가_그룹원에게_그룹초대를_하면_예외가_발생한다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - Member groupOwner = MemberFixture.member(1); - GroupOwnerSummaryDto groupOwnerSummaryDto = GroupDtoFixture.groupOwnerSummaryDto(false); - - given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); - given(memberRepository.findMemberById(targetId)).willReturn( - Optional.of(MemberFixture.member(2))); - given(groupRepository.findGroupById(groupId)).willReturn(Optional.of(GroupFixture.group())); - given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( - Optional.of(groupOwnerSummaryDto)); - - //when - //then - assertThatThrownBy(() -> groupWriteService.inviteGroup(memberId, groupId, targetId)) - .isInstanceOf(GroupOwnerAuthenticateException.class) - .hasMessageContaining(ErrorCode.GROUP_OWNER_AUTHENTICATE_ERROR.getMessage()); - } - - @Test - void 그룹원은_그룹초대_삭제에서_1을_반환하면_거부할_수_있다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - - given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( - groupId, targetId, memberId)).willReturn(1); - - //when - // then - assertThatCode(() -> groupWriteService.rejectRequestGroup(memberId, groupId, targetId)) - .doesNotThrowAnyException(); - } - - @Test - void 그룹원은_그룹초대_삭제에서_0을_반환하면_거부가_실패_한다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - - given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( - groupId, targetId, memberId)).willReturn(0); - - //when - // then - assertThatThrownBy(() -> groupWriteService.rejectRequestGroup(memberId, groupId, targetId)) - .isInstanceOf(GroupInviteNotFoundException.class) - .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); - } - - @Test - void 그룹원은_그룹초대를_수락하면_그룹장에게_알림이_전송된다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - Member groupMember = MemberFixture.member(1); - - given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); - given(groupRepository.findGroupById(groupId)).willReturn( - Optional.of(GroupFixture.group())); - given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( - groupId, targetId, memberId)).willReturn(1); - - //when - groupWriteService.acceptGroupInvite(memberId, groupId, targetId); - - //then - verify(socialNotificationManager, times(1)).sendGroupAcceptMessage(anyString(), anyLong()); - } - - @Test - void 그룹원은_그룹초대를_수락할_때_그룹초대가_존재하지_않으면_예외가_발생한다() { - //given - Long memberId = 1L; - Long groupId = 1L; - Long targetId = 2L; - Member groupMember = MemberFixture.member(1); - - given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); - given(groupRepository.findGroupById(groupId)).willReturn( - Optional.of(GroupFixture.group())); - given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( - groupId, targetId, memberId)).willReturn(0); - - //when - //then - assertThatThrownBy(() -> groupWriteService.acceptGroupInvite(memberId, groupId, targetId)) - .isInstanceOf(GroupInviteNotFoundException.class) - .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); - } - @Test void 존재하지_않는_그룹_아이디로_삭제를_시도하면_예외가_발생한다() { //given @@ -253,7 +104,7 @@ class GroupWriteServiceTest { //when //then - assertThatThrownBy(() -> groupWriteService.deleteGroup(memberId, notExistGroupId)) + assertThatThrownBy(() -> groupCommandService.deleteGroup(memberId, notExistGroupId)) .isExactlyInstanceOf(GroupNotFoundException.class) .hasMessageContaining(ErrorCode.GROUP_NOT_FOUND_ERROR.getMessage()); } @@ -270,7 +121,7 @@ class GroupWriteServiceTest { //when //then - assertThatThrownBy(() -> groupWriteService.deleteGroup(groupMemberId, groupId)) + assertThatThrownBy(() -> groupCommandService.deleteGroup(groupMemberId, groupId)) .isExactlyInstanceOf(GroupDeleteFailException.class) .hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage()); } @@ -298,7 +149,7 @@ private List notOwnerGroupMember() { //when //then assertThatThrownBy( - () -> groupWriteService.deleteGroup(groupOwnerId, groupMemberExistGroupId)) + () -> groupCommandService.deleteGroup(groupOwnerId, groupMemberExistGroupId)) .isExactlyInstanceOf(GroupDeleteFailException.class) .hasMessageContaining(ErrorCode.GROUP_MEMBER_EXIST_ERROR.getMessage()); } @@ -339,7 +190,7 @@ private List groupMembers() { //when //then assertThatThrownBy( - () -> groupWriteService.deleteGroup(groupOwnerId, groupCapsuleExistGroupId)) + () -> groupCommandService.deleteGroup(groupOwnerId, groupCapsuleExistGroupId)) .isExactlyInstanceOf(GroupDeleteFailException.class) .hasMessageContaining(ErrorCode.GROUP_CAPSULE_EXIST_ERROR.getMessage()); } @@ -368,7 +219,8 @@ private List ownerGroupMember() { //when //then assertThatCode( - () -> groupWriteService.deleteGroup(groupOwnerId, groupId)).doesNotThrowAnyException(); + () -> groupCommandService.deleteGroup(groupOwnerId, + groupId)).doesNotThrowAnyException(); verify(groupRepository, times(1)).delete(any(Group.class)); } } diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/group_member/service/GroupMemberCommandServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group_member/service/GroupMemberCommandServiceTest.java new file mode 100644 index 000000000..ae8e1c6c1 --- /dev/null +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/group_member/service/GroupMemberCommandServiceTest.java @@ -0,0 +1,196 @@ +package site.timecapsulearchive.core.domain.group_member.service; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.springframework.transaction.support.TransactionTemplate; +import site.timecapsulearchive.core.common.dependency.TestTransactionTemplate; +import site.timecapsulearchive.core.common.fixture.domain.GroupFixture; +import site.timecapsulearchive.core.common.fixture.domain.MemberFixture; +import site.timecapsulearchive.core.common.fixture.dto.GroupDtoFixture; +import site.timecapsulearchive.core.domain.group.exception.GroupNotFoundException; +import site.timecapsulearchive.core.domain.group.repository.GroupRepository; +import site.timecapsulearchive.core.domain.group_member.data.GroupOwnerSummaryDto; +import site.timecapsulearchive.core.domain.group_member.exception.GroupInviteNotFoundException; +import site.timecapsulearchive.core.domain.group_member.exception.GroupOwnerAuthenticateException; +import site.timecapsulearchive.core.domain.group_member.repository.groupInviteRepository.GroupInviteRepository; +import site.timecapsulearchive.core.domain.group_member.repository.memberGroupRepository.MemberGroupRepository; +import site.timecapsulearchive.core.domain.member.entity.Member; +import site.timecapsulearchive.core.domain.member.repository.MemberRepository; +import site.timecapsulearchive.core.global.error.ErrorCode; +import site.timecapsulearchive.core.infra.queue.manager.SocialNotificationManager; + +public class GroupMemberCommandServiceTest { + + private final MemberRepository memberRepository = mock(MemberRepository.class); + private final GroupRepository groupRepository = mock(GroupRepository.class); + private final MemberGroupRepository memberGroupRepository = mock(MemberGroupRepository.class); + private final GroupInviteRepository groupInviteRepository = mock(GroupInviteRepository.class); + private final SocialNotificationManager socialNotificationManager = mock( + SocialNotificationManager.class); + private final TransactionTemplate transactionTemplate = TestTransactionTemplate.spied(); + + private final GroupMemberCommandService groupQueryService = new GroupMemberCommandService( + memberRepository, + groupRepository, + memberGroupRepository, + groupInviteRepository, + transactionTemplate, + socialNotificationManager + ); + + + @Test + void 그룹장이_그룹원에게_그룹초대를_하면_그룹초대_알림이_요청된다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + Member groupOwner = MemberFixture.member(1); + GroupOwnerSummaryDto groupOwnerSummaryDto = GroupDtoFixture.groupOwnerSummaryDto(true); + + given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); + given(memberRepository.findMemberById(targetId)).willReturn( + Optional.of(MemberFixture.member(2))); + given(groupRepository.findGroupById(groupId)).willReturn(Optional.of(GroupFixture.group())); + given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( + Optional.of(groupOwnerSummaryDto)); + + //when + groupQueryService.inviteGroup(memberId, groupId, targetId); + + //then + verify(socialNotificationManager, times(1)).sendGroupInviteMessage(anyString(), anyString(), + anyList()); + } + + @Test + void 그룹장이_그룹초대를_할_때_존재하지_않은_그룹_아이디_이면_예외가_발생한다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + Member groupOwner = MemberFixture.member(1); + + given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); + given(memberRepository.findMemberById(targetId)).willReturn( + Optional.of(MemberFixture.member(2))); + given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( + Optional.empty()); + + //when + //then + assertThatThrownBy(() -> groupQueryService.inviteGroup(memberId, groupId, targetId)) + .isInstanceOf(GroupNotFoundException.class) + .hasMessageContaining(ErrorCode.GROUP_NOT_FOUND_ERROR.getMessage()); + } + + @Test + void 그룹장이_아닌_사용자가_그룹원에게_그룹초대를_하면_예외가_발생한다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + Member groupOwner = MemberFixture.member(1); + GroupOwnerSummaryDto groupOwnerSummaryDto = GroupDtoFixture.groupOwnerSummaryDto(false); + + given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupOwner)); + given(memberRepository.findMemberById(targetId)).willReturn( + Optional.of(MemberFixture.member(2))); + given(groupRepository.findGroupById(groupId)).willReturn(Optional.of(GroupFixture.group())); + given(memberGroupRepository.findOwnerInMemberGroup(groupId, memberId)).willReturn( + Optional.of(groupOwnerSummaryDto)); + + //when + //then + assertThatThrownBy(() -> groupQueryService.inviteGroup(memberId, groupId, targetId)) + .isInstanceOf(GroupOwnerAuthenticateException.class) + .hasMessageContaining(ErrorCode.GROUP_OWNER_AUTHENTICATE_ERROR.getMessage()); + } + + @Test + void 그룹원은_그룹초대_삭제에서_1을_반환하면_거부할_수_있다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(1); + + //when + // then + assertThatCode(() -> groupQueryService.rejectRequestGroup(memberId, groupId, targetId)) + .doesNotThrowAnyException(); + } + + @Test + void 그룹원은_그룹초대_삭제에서_0을_반환하면_거부가_실패_한다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(0); + + //when + // then + assertThatThrownBy( + () -> groupQueryService.rejectRequestGroup(memberId, groupId, targetId)) + .isInstanceOf(GroupInviteNotFoundException.class) + .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); + } + + @Test + void 그룹원은_그룹초대를_수락하면_그룹장에게_알림이_전송된다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + Member groupMember = MemberFixture.member(1); + + given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); + given(groupRepository.findGroupById(groupId)).willReturn( + Optional.of(GroupFixture.group())); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(1); + + //when + groupQueryService.acceptGroupInvite(memberId, groupId, targetId); + + //then + verify(socialNotificationManager, times(1)).sendGroupAcceptMessage(anyString(), anyLong()); + } + + @Test + void 그룹원은_그룹초대를_수락할_때_그룹초대가_존재하지_않으면_예외가_발생한다() { + //given + Long memberId = 1L; + Long groupId = 1L; + Long targetId = 2L; + Member groupMember = MemberFixture.member(1); + + given(memberRepository.findMemberById(memberId)).willReturn(Optional.of(groupMember)); + given(groupRepository.findGroupById(groupId)).willReturn( + Optional.of(GroupFixture.group())); + given(groupInviteRepository.deleteGroupInviteByGroupIdAndGroupOwnerIdAndGroupMemberId( + groupId, targetId, memberId)).willReturn(0); + + //when + //then + assertThatThrownBy(() -> groupQueryService.acceptGroupInvite(memberId, groupId, targetId)) + .isInstanceOf(GroupInviteNotFoundException.class) + .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); + } + +}