From c0a38806bad984486c916e55411d2c58bc501045 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Wed, 5 Jun 2024 21:24:22 +0900 Subject: [PATCH] =?UTF-8?q?test=20:=20=EC=8A=AC=EB=9D=BC=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupInviteQueryRepositoryTest.java | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 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 d9d51aeae..753f7c901 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 @@ -32,13 +32,14 @@ class GroupInviteQueryRepositoryTest extends RepositoryTest { private static final int MAX_GROUP_COUNT = 2; + private static final int MAX_GROUP_INVITE_COUNT = 10; private final GroupInviteQueryRepository groupInviteRepository; private Long groupId; private Long groupOwnerId; private Long groupMemberId; - private Long firstGroupInviteStartId; + private Long firstGroupInviteStartId = null; GroupInviteQueryRepositoryTest( JdbcTemplate jdbcTemplate, @@ -56,10 +57,12 @@ void setUp(@Autowired EntityManager entityManager) { groupOwners.forEach(entityManager::persist); groupOwnerId = groupOwners.get(0).getId(); - //그룹 초대 올 그룹원 - Member groupMember = MemberFixture.member(2); - entityManager.persist(groupMember); - groupMemberId = groupMember.getId(); + //그룹 초대 올 그룹원들 + List groupMembers = MemberFixture.members(2, MAX_GROUP_INVITE_COUNT); + for (Member groupMember : groupMembers) { + entityManager.persist(groupMember); + } + groupMemberId = groupMembers.get(0).getId(); // 그룹들 List groups = GroupFixture.groups(0, MAX_GROUP_COUNT); @@ -68,12 +71,14 @@ void setUp(@Autowired EntityManager entityManager) { // 그룹원에게 초대온 그룹 초대들 for (int i = 0; i < MAX_GROUP_COUNT; i++) { - GroupInvite groupInvite = GroupInvite.createOf(groups.get(i), groupOwners.get(i), - groupMember); - entityManager.persist(groupInvite); - - if (i == 0) { - firstGroupInviteStartId = groupInvite.getId(); + for (Member groupMember : groupMembers) { + GroupInvite groupInvite = GroupInvite.createOf(groups.get(i), groupOwners.get(i), + groupMember); + entityManager.persist(groupInvite); + + if (firstGroupInviteStartId == null) { + firstGroupInviteStartId = groupInvite.getId(); + } } } } @@ -140,13 +145,16 @@ void setUp(@Autowired EntityManager entityManager) { ); //when - Slice groupSendingInvites = groupInviteRepository.findGroupSendingInvites(requestDto); + Slice groupSendingInvites = groupInviteRepository.findGroupSendingInvites( + requestDto); //then SoftAssertions.assertSoftly(softly -> { softly.assertThat(groupSendingInvites.hasContent()).isTrue(); - softly.assertThat(groupSendingInvites.getContent()).allMatch(dto -> dto.groupInviteId() != null); - softly.assertThat(groupSendingInvites.getContent()).allMatch(dto -> dto.memberId() != null); + softly.assertThat(groupSendingInvites.getContent()) + .allMatch(dto -> dto.groupInviteId() != null); + softly.assertThat(groupSendingInvites.getContent()) + .allMatch(dto -> dto.memberId() != null); softly.assertThat(groupSendingInvites.getContent()) .allMatch(dto -> dto.nickname() != null && !dto.nickname().isBlank()); softly.assertThat(groupSendingInvites.getContent()) @@ -171,4 +179,24 @@ void setUp(@Autowired EntityManager entityManager) { //then assertThat(groupSendingInvites.isEmpty()).isTrue(); } + + @Test + void 사용자는_그룹_초대_보낸_목록_첫_페이지를_조회_후_다음_페이지에서_그룹_초대_보낸_목록을_조회_할_수_있다() { + //given + GroupSendingInvitesSliceRequestDto dto = GroupSendingInvitesSliceRequestDto.create( + groupOwnerId, groupId, null, MAX_GROUP_INVITE_COUNT / 2); + Slice firstSlice = groupInviteRepository.findGroupSendingInvites( + dto); + + //when + GroupSendingInviteMemberDto lastGroupInvite = firstSlice.getContent() + .get(firstSlice.getNumberOfElements() - 1); + Slice nextSlice = groupInviteRepository.findGroupSendingInvites( + GroupSendingInvitesSliceRequestDto.create(groupOwnerId, groupId, + lastGroupInvite.groupInviteId(), 20) + ); + + //then + assertThat(nextSlice.getContent()).isNotEmpty(); + } }