Skip to content

Commit

Permalink
[FEAT] Group Service Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjoo-lab committed Nov 27, 2023
1 parent 42263ee commit 0a2ea16
Showing 1 changed file with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
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;
import com.twtw.backend.domain.group.repository.GroupMemberRepository;
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;
Expand All @@ -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();
}
}

0 comments on commit 0a2ea16

Please sign in to comment.