Skip to content

Commit

Permalink
test: CertificationsSearchRepository 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
Shin-Jae-Yoon committed Nov 12, 2023
1 parent 874bcb0 commit 188d965
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.moabam.api.domain.repository;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.moabam.api.domain.entity.Certification;
import com.moabam.api.domain.entity.DailyMemberCertification;
import com.moabam.api.domain.entity.DailyRoomCertification;
import com.moabam.api.domain.entity.Participant;
import com.moabam.api.domain.entity.Room;
import com.moabam.api.domain.entity.Routine;
import com.moabam.support.annotation.QuerydslRepositoryTest;
import com.moabam.support.fixture.RoomFixture;

@QuerydslRepositoryTest
class CertificationsSearchRepositoryTest {

@Autowired
private CertificationsSearchRepository certificationsSearchRepository;

@Autowired
private CertificationRepository certificationRepository;

@Autowired
private DailyMemberCertificationRepository dailyMemberCertificationRepository;

@Autowired
private DailyRoomCertificationRepository dailyRoomCertificationRepository;

@Autowired
private RoomRepository roomRepository;

@Autowired
private RoutineRepository routineRepository;

@Autowired
private ParticipantRepository participantRepository;

@DisplayName("방에서 당일 유저들의 인증 조회")
@Test
void find_certifications_test() {
// given
Room room = RoomFixture.room();
List<Routine> routines = RoomFixture.routines(room);
Certification certification1 = RoomFixture.certification(routines.get(0));
Certification certification2 = RoomFixture.certification(routines.get(1));

Room savedRoom = roomRepository.save(room);
routineRepository.save(routines.get(0));
routineRepository.save(routines.get(1));
certificationRepository.save(certification1);
certificationRepository.save(certification2);

// when
List<Certification> actual = certificationsSearchRepository.findCertifications(savedRoom.getId(),
LocalDate.now());

//then
assertThat(actual).hasSize(2)
.containsExactly(certification1, certification2);
}

@DisplayName("당일 유저가 특정 방에서 인증 여부 조회")
@Test
void find_daily_member_certification() {
// given
Room room = roomRepository.save(RoomFixture.room());
Participant participant = participantRepository.save(RoomFixture.participant(room, 1L));

DailyMemberCertification dailyMemberCertification = RoomFixture.dailyMemberCertification(1L,
room.getId(), participant);
dailyMemberCertificationRepository.save(dailyMemberCertification);

// when
Optional<DailyMemberCertification> actual = certificationsSearchRepository.findDailyMemberCertification(1L,
room.getId(), LocalDate.now());

// then
assertThat(actual)
.isPresent()
.contains(dailyMemberCertification);
}

@DisplayName("당일 방의 인증 여부 조회")
@Test
void find_daily_room_certification() {
// given
Room room = roomRepository.save(RoomFixture.room());
DailyRoomCertification dailyRoomCertification = RoomFixture.dailyRoomCertification(room.getId(),
LocalDate.now());
dailyRoomCertificationRepository.save(dailyRoomCertification);

// when
Optional<DailyRoomCertification> actual = certificationsSearchRepository.findDailyRoomCertification(
room.getId(), LocalDate.now());

// then
assertThat(actual)
.isPresent()
.contains(dailyRoomCertification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import com.moabam.api.domain.repository.CertificationsSearchRepository;
import com.moabam.api.domain.repository.InventorySearchRepository;
import com.moabam.api.domain.repository.ItemSearchRepository;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down Expand Up @@ -32,4 +33,9 @@ public ItemSearchRepository itemSearchRepository() {
public InventorySearchRepository inventorySearchRepository() {
return new InventorySearchRepository(jpaQueryFactory());
}

@Bean
public CertificationsSearchRepository certificationsSearchRepository() {
return new CertificationsSearchRepository(jpaQueryFactory());
}
}
9 changes: 9 additions & 0 deletions src/test/java/com/moabam/support/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.springframework.mock.web.MockMultipartFile;

import com.moabam.api.domain.entity.Certification;
import com.moabam.api.domain.entity.DailyMemberCertification;
import com.moabam.api.domain.entity.DailyRoomCertification;
import com.moabam.api.domain.entity.Participant;
Expand Down Expand Up @@ -61,6 +62,14 @@ public static List<Routine> routines(Room room) {
return routines;
}

public static Certification certification(Routine routine) {
return Certification.builder()
.routine(routine)
.memberId(1L)
.image("test1")
.build();
}

public static DailyMemberCertification dailyMemberCertification(Long memberId, Long roomId,
Participant participant) {
return DailyMemberCertification.builder()
Expand Down

0 comments on commit 188d965

Please sign in to comment.