From 1def8c2f0f167b52e812f5bfb331de5fc31f666b Mon Sep 17 00:00:00 2001 From: hong seokho Date: Thu, 6 Jun 2024 11:58:06 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixture/domain/GroupInviteFixture.java | 14 +++++ .../MemberGroupCommandServiceTest.java | 55 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupInviteFixture.java diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupInviteFixture.java b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupInviteFixture.java new file mode 100644 index 000000000..7b31b2300 --- /dev/null +++ b/backend/core/src/test/java/site/timecapsulearchive/core/common/fixture/domain/GroupInviteFixture.java @@ -0,0 +1,14 @@ +package site.timecapsulearchive.core.common.fixture.domain; + +import java.util.Optional; +import site.timecapsulearchive.core.domain.group.entity.Group; +import site.timecapsulearchive.core.domain.member.entity.Member; +import site.timecapsulearchive.core.domain.member_group.entity.GroupInvite; + +public class GroupInviteFixture { + + public static Optional groupInvite(Group group, Member groupOwner, + Member groupMember) { + return Optional.of(GroupInvite.createOf(group, groupOwner, groupMember)); + } +} diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java index 955a6eaf4..8e5b1ae15 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/service/MemberGroupCommandServiceTest.java @@ -19,6 +19,7 @@ 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.GroupInviteFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberFixture; import site.timecapsulearchive.core.common.fixture.domain.MemberGroupFixture; import site.timecapsulearchive.core.common.fixture.dto.GroupDtoFixture; @@ -30,6 +31,7 @@ import site.timecapsulearchive.core.domain.member_group.data.dto.GroupAcceptNotificationDto; import site.timecapsulearchive.core.domain.member_group.data.dto.GroupOwnerSummaryDto; import site.timecapsulearchive.core.domain.member_group.data.request.SendGroupRequest; +import site.timecapsulearchive.core.domain.member_group.entity.GroupInvite; import site.timecapsulearchive.core.domain.member_group.entity.MemberGroup; import site.timecapsulearchive.core.domain.member_group.exception.GroupInviteNotFoundException; import site.timecapsulearchive.core.domain.member_group.exception.GroupMemberCountLimitException; @@ -303,6 +305,59 @@ class MemberGroupCommandServiceTest { verify(memberGroupRepository, times(1)).delete(any(MemberGroup.class)); } + @Test + void 그룹장인_사람이_그룹_초대를_삭제하면_삭제된다() { + //given + Long groupOwnerId = 1L; + Long groupMemberId = 2L; + Long groupInviteId = 1L; + given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn( + GroupInviteFixture.groupInvite(GroupFixture.group(), + MemberFixture.memberWithMemberId(groupOwnerId), + MemberFixture.memberWithMemberId(groupMemberId)) + ); + + //when + groupMemberCommandService.deleteGroupInvite(groupOwnerId, groupInviteId); + + //then + verify(groupInviteRepository, times(1)).delete(any(GroupInvite.class)); + } + + @Test + void 그룹_초대가_존재하지_않는_경우_예외가_발생한다() { + //given + Long groupOwnerId = 1L; + Long groupInviteId = 1L; + given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn(Optional.empty()); + + //when + //then + assertThatThrownBy(() -> groupMemberCommandService.deleteGroupInvite(groupOwnerId, groupInviteId)) + .isInstanceOf(GroupInviteNotFoundException.class) + .hasMessageContaining(ErrorCode.GROUP_INVITATION_NOT_FOUND_ERROR.getMessage()); + } + + @Test + void 그룹장이_아닌_사람이_그룹_초대를_삭제하면_예외가_발생한다() { + //given + Long groupOwnerId = 1L; + Long groupMemberId = 2L; + Long groupInviteId = 1L; + given(groupInviteRepository.findGroupInviteById(anyLong())).willReturn( + GroupInviteFixture.groupInvite(GroupFixture.group(), + MemberFixture.memberWithMemberId(groupOwnerId), + MemberFixture.memberWithMemberId(groupMemberId)) + ); + + //when + //then + assertThatThrownBy( + () -> groupMemberCommandService.deleteGroupInvite(groupMemberId, groupInviteId)) + .isInstanceOf(NoGroupAuthorityException.class) + .hasMessageContaining(ErrorCode.NO_GROUP_AUTHORITY_ERROR.getMessage()); + } + @Test void 나_자신을_그룹에서_삭제하려하면_예외가_발생한다() { //given