Skip to content

Commit

Permalink
test : 기존 API, 그룹 목록 조회 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 committed Jun 1, 2024
1 parent e0a3ee0 commit 4f6a860
Showing 1 changed file with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -47,14 +52,17 @@ void setUp(@Autowired EntityManager entityManager) {
// 그룹 초대 할 그룹장들
List<Member> 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<Group> 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++) {
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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<GroupInviteSummaryDto> firstSlice = groupInviteRepository.findGroupRecetpionInvitesSlice(
memberId, size, now);

//when
GroupInviteSummaryDto dto = firstSlice.getContent().get(0);
Slice<GroupInviteSummaryDto> groupInvitesSummary = groupInviteRepository.findGroupRecetpionInvitesSlice(
memberId, size, createAt);
memberId, size, dto.groupReceptionInviteTime());

//then
assertThat(groupInvitesSummary.getContent()).isNotEmpty();
}

@Test
void 그룹장은_자신이_보낸_그룹_초대_목록을_조회하면_그룹_초대목록이_나온다() {
//given
//when
List<GroupSendingInviteMemberDto> 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<GroupSendingInviteMemberDto> groupSendingInvites = groupInviteRepository.findGroupSendingInvites(
groupMemberId, groupId);

//then
assertThat(groupSendingInvites).isEmpty();
}
}

0 comments on commit 4f6a860

Please sign in to comment.