From 73fbe8138f74b6d0476574605321505a71157969 Mon Sep 17 00:00:00 2001 From: DH CHOI Date: Fri, 3 Nov 2023 14:24:42 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EA=B7=B8=EB=A3=B9=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/query/GroupDaoQuerydslImplTest.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/test/java/daybyquest/group/query/GroupDaoQuerydslImplTest.java diff --git a/src/test/java/daybyquest/group/query/GroupDaoQuerydslImplTest.java b/src/test/java/daybyquest/group/query/GroupDaoQuerydslImplTest.java new file mode 100644 index 0000000..54a710e --- /dev/null +++ b/src/test/java/daybyquest/group/query/GroupDaoQuerydslImplTest.java @@ -0,0 +1,97 @@ +package daybyquest.group.query; + +import static daybyquest.support.fixture.GroupFixtures.GROUP_1; +import static daybyquest.support.fixture.UserFixtures.ALICE; +import static daybyquest.support.fixture.UserFixtures.BOB; +import static daybyquest.support.fixture.UserFixtures.CHARLIE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import daybyquest.global.error.exception.NotExistGroupException; +import daybyquest.group.domain.Group; +import daybyquest.group.domain.GroupUser; +import daybyquest.support.test.QuerydslTest; +import daybyquest.user.domain.User; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; + +@Import(GroupDaoQuerydslImpl.class) +public class GroupDaoQuerydslImplTest extends QuerydslTest { + + @Autowired + private GroupDaoQuerydslImpl groupDao; + + @PersistenceContext + private EntityManager entityManager; + + @Test + void 그룹_ID로_데이터를_조회한다() { + // given + final User user = entityManager.merge(BOB.생성()); + final Group group = entityManager.merge(GROUP_1.생성()); + + // when + final GroupData groupData = groupDao.getById(user.getId(), group.getId()); + + // then + assertAll(() -> { + assertThat(groupData.getInterest()).isEqualTo(GROUP_1.interest); + assertThat(groupData.getName()).isEqualTo(GROUP_1.name); + assertThat(groupData.getDescription()).isEqualTo(GROUP_1.description); + assertThat(groupData.getImageIdentifier()).isEqualTo(GROUP_1.imageIdentifier); + assertThat(groupData.getUserCount()).isZero(); + assertThat(groupData.isGroupManager()).isFalse(); + }); + } + + @Test + void 그룹_인원_수가_함께_조회된다() { + // given + final User bob = entityManager.merge(BOB.생성()); + final User alice = entityManager.merge(ALICE.생성()); + final User charlie = entityManager.merge(CHARLIE.생성()); + final Group group = entityManager.merge(GROUP_1.생성()); + + entityManager.merge(GroupUser.createGroupMember(bob.getId(), group)); + entityManager.merge(GroupUser.createGroupMember(alice.getId(), group)); + entityManager.merge(GroupUser.createGroupManager(charlie.getId(), group)); + + // when + final GroupData groupData = groupDao.getById(bob.getId(), group.getId()); + + // then + assertThat(groupData.getUserCount()).isEqualTo(3); + } + + @Test + void 그룹_관리자_여부가_함께_조회된다() { + // given + final User bob = entityManager.merge(BOB.생성()); + final User alice = entityManager.merge(ALICE.생성()); + final Group group = entityManager.merge(GROUP_1.생성()); + + entityManager.merge(GroupUser.createGroupMember(bob.getId(), group)); + entityManager.merge(GroupUser.createGroupManager(alice.getId(), group)); + + // when + final GroupData bobActual = groupDao.getById(bob.getId(), group.getId()); + final GroupData aliceAtual = groupDao.getById(alice.getId(), group.getId()); + + // then + assertAll(() -> { + assertThat(bobActual.isGroupManager()).isFalse(); + assertThat(aliceAtual.isGroupManager()).isTrue(); + }); + } + + @Test + void 그룹ID가_없다면_예외를_던진다() { + // given & when & then + assertThatThrownBy(() -> groupDao.getById(1L, 2L)) + .isInstanceOf(NotExistGroupException.class); + } +}