Skip to content

Commit

Permalink
[FEAT] Group Test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjoo-lab committed Nov 26, 2023
1 parent c1ec0b8 commit 9d0f0b0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ void makeGroup() throws Exception {
toRequestBody(
new MakeGroupRequest(
"HDJ",
"GROUP-IMAGE",
UUID.fromString(
"550e8400-e29b-41d4-a716-446655440000"))))
"GROUP-IMAGE")))
.header(
"Authorization",
"Bearer wefa3fsdczf32.gaoiuergf92.gb5hsa2jgh"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,97 @@
package com.twtw.backend.domain.group.repository;

import com.twtw.backend.domain.group.entity.Group;
import com.twtw.backend.domain.group.entity.GroupMember;
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.repository.MemberRepository;
import com.twtw.backend.domain.place.entity.Place;
import com.twtw.backend.domain.plan.entity.Plan;
import com.twtw.backend.fixture.group.GroupEntityFixture;
import com.twtw.backend.fixture.group.GroupMemberEntityFixture;
import com.twtw.backend.fixture.member.MemberEntityFixture;
import com.twtw.backend.fixture.place.PlaceEntityFixture;
import com.twtw.backend.support.repository.RepositoryTest;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.assertj.core.api.Assertions.assertThat;

@DisplayName("GroupRepository의")
class GroupRepositoryTest extends RepositoryTest {

@Autowired private GroupRepository groupRepository;

@Autowired private MemberRepository memberRepository;

@Autowired private GroupMemberRepository groupMemberRepository;
@Test
@DisplayName("Group이 정상적으로 저장되는가")
void makeGroup() {
// given
Member member1 = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());
Member member2 = memberRepository.save(MemberEntityFixture.SECOND_MEMBER.toEntity());

Group group = GroupEntityFixture.BTS_GROUP.toEntity();

GroupMember groupMember1 = new GroupMember(group,member1);
GroupMember groupMember2 = new GroupMember(group,member2);

Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

Plan plan = new Plan(member1,place,group);
plan.addMember(member2);

// when
final Group saveGroup = groupRepository.save(group);

// then
assertThat(saveGroup.getGroupMembers().size()).isEqualTo(2);
}

@Test
@DisplayName("GroupMember가 조회되는가")
void getGroupById(){
// given
Member member1 = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());
Member member2 = memberRepository.save(MemberEntityFixture.SECOND_MEMBER.toEntity());

Group group = GroupEntityFixture.BTS_GROUP.toEntity();

GroupMember groupMember1 = new GroupMember(group,member1);
GroupMember groupMember2 = new GroupMember(group,member2);

final Group saveGroup = groupRepository.save(group);
// when
GroupMember result = groupMemberRepository.findByGroupIdAndMemberId(saveGroup.getId()
,member1.getId()).orElseThrow();

// then
assertThat(result.getGroup().getId()).isEqualTo(saveGroup.getId());
}

@Test
void saveGroup() {}
@DisplayName("Group에서 Plan 정보가 추출되는가")
void getPlan(){
// given
Member member1 = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity());
Member member2 = memberRepository.save(MemberEntityFixture.SECOND_MEMBER.toEntity());

Group group = GroupEntityFixture.BTS_GROUP.toEntity();

GroupMember groupMember1 = new GroupMember(group,member1);
GroupMember groupMember2 = new GroupMember(group,member2);

Place place = PlaceEntityFixture.FIRST_PLACE.toEntity();

Plan plan = new Plan(member1,place,group);
plan.addMember(member2);

// when
final Group saveGroup = groupRepository.save(group);

// then
assertThat(group.getGroupPlans().size()).isEqualTo(1);
}
}

0 comments on commit 9d0f0b0

Please sign in to comment.