From 4f6a860695e612d716d62cae54380e664bcc23c7 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 1 Jun 2024 18:04:28 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20=EA=B8=B0=EC=A1=B4=20API,=20?= =?UTF-8?q?=EA=B7=B8=EB=A3=B9=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupInviteQueryRepositoryTest.java | 78 ++++++++++++++----- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/repository/GroupInviteQueryRepositoryTest.java b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/repository/GroupInviteQueryRepositoryTest.java index d2fec9d12..1aad3c7de 100644 --- a/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/repository/GroupInviteQueryRepositoryTest.java +++ b/backend/core/src/test/java/site/timecapsulearchive/core/domain/member_group/repository/GroupInviteQueryRepositoryTest.java @@ -1,12 +1,12 @@ package site.timecapsulearchive.core.domain.member_group.repository; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.List; -import org.assertj.core.api.Assertions; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,16 +22,21 @@ import site.timecapsulearchive.core.domain.group.entity.Group; import site.timecapsulearchive.core.domain.member.entity.Member; import site.timecapsulearchive.core.domain.member_group.data.dto.GroupInviteSummaryDto; +import site.timecapsulearchive.core.domain.member_group.data.dto.GroupSendingInviteMemberDto; import site.timecapsulearchive.core.domain.member_group.entity.GroupInvite; -import site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository.GroupInviteQueryRepository; -import site.timecapsulearchive.core.domain.member_group.repository.groupInviteRepository.GroupInviteQueryRepositoryImpl; +import site.timecapsulearchive.core.domain.member_group.repository.group_invite_repository.GroupInviteQueryRepository; +import site.timecapsulearchive.core.domain.member_group.repository.group_invite_repository.GroupInviteQueryRepositoryImpl; @TestConstructor(autowireMode = AutowireMode.ALL) class GroupInviteQueryRepositoryTest extends RepositoryTest { private static final int MAX_GROUP_COUNT = 2; + private final GroupInviteQueryRepository groupInviteRepository; - private Member groupMember; + + private Long groupId; + private Long groupOwnerId; + private Long groupMemberId; GroupInviteQueryRepositoryTest( JdbcTemplate jdbcTemplate, @@ -47,14 +52,17 @@ void setUp(@Autowired EntityManager entityManager) { // 그룹 초대 할 그룹장들 List groupOwners = MemberFixture.members(0, MAX_GROUP_COUNT); groupOwners.forEach(entityManager::persist); + groupOwnerId = groupOwners.get(0).getId(); //그룹 초대 올 그룹원 - groupMember = MemberFixture.member(2); + Member groupMember = MemberFixture.member(2); entityManager.persist(groupMember); + groupMemberId = groupMember.getId(); // 그룹들 List groups = GroupFixture.groups(0, MAX_GROUP_COUNT); groups.forEach(entityManager::persist); + groupId = groups.get(0).getId(); // 그룹원에게 초대온 그룹 초대들 for (int i = 0; i < MAX_GROUP_COUNT; i++) { @@ -65,9 +73,9 @@ void setUp(@Autowired EntityManager entityManager) { } @Test - void 사용자는_자신에게_온_그룹_초대_목록을_조회할_수_있다() { + void 사용자는_자신에게_온_그룹_초대_목록을_조회하면_그룹_초대목록이_나온다() { //given - Long memberId = groupMember.getId(); + Long memberId = groupMemberId; int size = 1; ZonedDateTime createAt = ZonedDateTime.now().plusDays(1); @@ -76,13 +84,13 @@ void setUp(@Autowired EntityManager entityManager) { memberId, size, createAt); //then - assertThat(groupInvitesSummary.getContent()).isNotNull(); + assertThat(groupInvitesSummary.getContent()).isNotEmpty(); } @Test void 사용자는_자신에게_온_그룹_초대_목록에서_그룹_정보와_그룹장을_알_수_있다() { //given - Long memberId = groupMember.getId(); + Long memberId = groupMemberId; int size = 1; ZonedDateTime createAt = ZonedDateTime.now().plusDays(1); @@ -92,28 +100,60 @@ void setUp(@Autowired EntityManager entityManager) { //then SoftAssertions.assertSoftly(softly -> { - Assertions.assertThat(groupInvitesSummary).allMatch(g -> !g.groupName().isEmpty()); - Assertions.assertThat(groupInvitesSummary) + assertThat(groupInvitesSummary).allMatch(g -> !g.groupName().isEmpty()); + assertThat(groupInvitesSummary) .allMatch(g -> !g.groupProfileUrl().isEmpty()); - Assertions.assertThat(groupInvitesSummary).allMatch(g -> !g.description().isEmpty()); - Assertions.assertThat(groupInvitesSummary).allMatch(g -> !g.groupOwnerName().isEmpty()); + assertThat(groupInvitesSummary).allMatch(g -> !g.description().isEmpty()); + assertThat(groupInvitesSummary).allMatch(g -> !g.groupOwnerName().isEmpty()); }); } @Test - void 사용자는_조회한_그룹_초대_목록_후_그룹_초대_존재_여부를_확인_할_수_있다() { + void 사용자는_그룹_초대_받은_목록_첫_페이지를_조회_후_다음_페이지에서_그룹_초대_받은_목록을_조회_할_수_있다() { //given - Long memberId = groupMember.getId(); + Long memberId = groupMemberId; int size = 1; - ZonedDateTime createAt = ZonedDateTime.now().plusDays(1); + ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).plusDays(3); + Slice firstSlice = groupInviteRepository.findGroupRecetpionInvitesSlice( + memberId, size, now); //when + GroupInviteSummaryDto dto = firstSlice.getContent().get(0); Slice groupInvitesSummary = groupInviteRepository.findGroupRecetpionInvitesSlice( - memberId, size, createAt); + memberId, size, dto.groupReceptionInviteTime()); + + //then + assertThat(groupInvitesSummary.getContent()).isNotEmpty(); + } + + @Test + void 그룹장은_자신이_보낸_그룹_초대_목록을_조회하면_그룹_초대목록이_나온다() { + //given + //when + List groupSendingInvites = groupInviteRepository.findGroupSendingInvites( + groupOwnerId, groupId); //then - assertThat(groupInvitesSummary.hasNext()).isTrue(); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(groupSendingInvites).isNotEmpty(); + softly.assertThat(groupSendingInvites).allMatch(dto -> dto.id() != null); + softly.assertThat(groupSendingInvites) + .allMatch(dto -> dto.nickname() != null && !dto.nickname().isBlank()); + softly.assertThat(groupSendingInvites) + .allMatch(dto -> dto.profileUrl() != null && !dto.profileUrl().isBlank()); + softly.assertThat(groupSendingInvites) + .allMatch(dto -> dto.sendingInvitesCreatedAt() != null); + }); } + @Test + void 그룹원은_자신이_보낸_그룹_초대_목록을_조회하면_빈_리스트가_나온다() { + //given + //when + List groupSendingInvites = groupInviteRepository.findGroupSendingInvites( + groupMemberId, groupId); + //then + assertThat(groupSendingInvites).isEmpty(); + } }