From 9d0f0b03fce06a14296b88b3eb64e41a502d1b38 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 01:08:54 +0900 Subject: [PATCH] [FEAT] Group Test --- .../group/controller/GroupControllerTest.java | 4 +- .../group/repository/GroupRepositoryTest.java | 85 ++++++++++++++++++- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/backend/src/test/java/com/twtw/backend/domain/group/controller/GroupControllerTest.java b/backend/src/test/java/com/twtw/backend/domain/group/controller/GroupControllerTest.java index 32a6333e..5bd9c314 100644 --- a/backend/src/test/java/com/twtw/backend/domain/group/controller/GroupControllerTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/group/controller/GroupControllerTest.java @@ -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")); diff --git a/backend/src/test/java/com/twtw/backend/domain/group/repository/GroupRepositoryTest.java b/backend/src/test/java/com/twtw/backend/domain/group/repository/GroupRepositoryTest.java index ca265448..6e271ac4 100644 --- a/backend/src/test/java/com/twtw/backend/domain/group/repository/GroupRepositoryTest.java +++ b/backend/src/test/java/com/twtw/backend/domain/group/repository/GroupRepositoryTest.java @@ -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); + } }