From 0a2ea1650ae7363caddfb76022c07998f9328167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:18:48 +0900 Subject: [PATCH] [FEAT] Group Service Test --- .../group/service/GroupServiceTest.java | 101 +++++++++++++++++- 1 file changed, 96 insertions(+), 5 deletions(-) diff --git a/backend/src/test/java/com/twtw/backend/domain/group/service/GroupServiceTest.java b/backend/src/test/java/com/twtw/backend/domain/group/service/GroupServiceTest.java index f73cb101..761dcfdb 100644 --- a/backend/src/test/java/com/twtw/backend/domain/group/service/GroupServiceTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/group/service/GroupServiceTest.java @@ -1,8 +1,10 @@ package com.twtw.backend.domain.group.service; +import com.twtw.backend.domain.group.dto.request.InviteGroupRequest; import com.twtw.backend.domain.group.dto.request.JoinGroupRequest; import com.twtw.backend.domain.group.dto.request.MakeGroupRequest; import com.twtw.backend.domain.group.dto.response.GroupInfoResponse; +import com.twtw.backend.domain.group.dto.response.ShareInfoResponse; import com.twtw.backend.domain.group.dto.response.SimpleGroupInfoResponse; import com.twtw.backend.domain.group.entity.Group; import com.twtw.backend.domain.group.entity.GroupMember; @@ -10,10 +12,11 @@ import com.twtw.backend.domain.group.repository.GroupRepository; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.repository.MemberRepository; -import com.twtw.backend.fixture.group.GroupEntityFixture; +import com.twtw.backend.domain.member.service.AuthService; + import com.twtw.backend.fixture.member.MemberEntityFixture; import com.twtw.backend.support.service.LoginTest; -import jakarta.persistence.EntityManager; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -24,30 +27,118 @@ public class GroupServiceTest extends LoginTest { @Autowired private GroupService groupService; + @Autowired private AuthService authService; + @Autowired private GroupRepository groupRepository; @Autowired private MemberRepository memberRepository; @Autowired private GroupMemberRepository groupMemberRepository; - @Autowired private EntityManager em; @Test @DisplayName("makeGroup이 성공적으로 수행되는가") void makeGroup(){ // given - MakeGroupRequest request = new MakeGroupRequest("JINJOOONEKING","JIN_GROUP_IMAGE"); + final String expected = "JINJOOONEKING"; + + MakeGroupRequest request = new MakeGroupRequest(expected,"JIN_GROUP_IMAGE"); // when GroupInfoResponse response = groupService.makeGroup(request); // then - assertThat(response.getName()).isEqualTo("JINJOOONEKING"); + assertThat(response.getName()).isEqualTo(expected); } @Test @DisplayName("Group에 Join할 수 있는가") void joinGroup(){ + // given + Member member = memberRepository.save(authService.getMemberByJwt()); + + Member leader = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); + + Group group = new Group("BABY_MONSTER","YG_OFFICIAL_IMAGE",leader.getId()); + GroupMember groupMember1 = new GroupMember(group,leader); + + GroupMember groupMember2 = new GroupMember(group,member); + + Group saveGroup = groupRepository.save(group); + // when + JoinGroupRequest request = new JoinGroupRequest(saveGroup.getId()); + + SimpleGroupInfoResponse response = groupService.joinGroup(request); + + // then + assertThat(response.getGroupId()).isEqualTo(saveGroup.getId()); + } + + @Test + @DisplayName("Group에 초대할 수 있는가") + void inviteGroup(){ + // given + Member member = memberRepository.save(authService.getMemberByJwt()); + + Member leader = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); + + Group group = new Group("BABY_MONSTER","YG_OFFICIAL_IMAGE",leader.getId()); + + GroupMember groupMember1 = new GroupMember(group,leader); + + Group saveGroup = groupRepository.save(group); + + InviteGroupRequest request = new InviteGroupRequest(member.getId(),saveGroup.getId()); + // when + GroupInfoResponse response = groupService.inviteGroup(request); + + // then + assertThat(response.getGroupId()).isEqualTo(saveGroup.getId()); + } + + @Test + @DisplayName("위치 공유 정보가 반환되는가") + void getShare(){ + // given + Member member = memberRepository.save(authService.getMemberByJwt()); + + Member leader = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); + + Group group = new Group("BABY_MONSTER","YG_OFFICIAL_IMAGE",leader.getId()); + + GroupMember groupMember1 = new GroupMember(group,leader); + GroupMember groupMember2 = new GroupMember(group,member); + + Group saveGroup = groupRepository.save(group); + + // when + ShareInfoResponse response = groupService.getShare(saveGroup.getId()); + + // then + assertThat(response.getShare()).isTrue(); + } + + @Test + @DisplayName("위치 공유를 공개 -> 비공개 변경이 가능한가") + void changeShare(){ + // given + Member member = memberRepository.save(authService.getMemberByJwt()); + + Member leader = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); + + Group group = new Group("BABY_MONSTER","YG_OFFICIAL_IMAGE",leader.getId()); + + GroupMember groupMember1 = new GroupMember(group,leader); + GroupMember groupMember2 = new GroupMember(group,member); + + Group saveGroup = groupRepository.save(group); + + // when + groupService.changeShare(saveGroup.getId()); + GroupMember result = groupMemberRepository.findByGroupIdAndMemberId(saveGroup.getId(),member.getId()).orElseThrow(); + + // then + assertThat(result.getShare()).isFalse(); } }