Skip to content

Commit

Permalink
feat: Add test code for findLatestPost in PostRepositoryCustomImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwon770 committed May 7, 2024
1 parent d9767a7 commit c2e7ff5
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.oing.domain.Post;
import com.oing.domain.PostType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
Expand Down Expand Up @@ -112,6 +113,51 @@ void setup() {
.containsExactly("2", "4");
}

@Nested
class findLatestPost {
@Test
void 정상_조회_테스트() {
// given
String familyId = testMember1.getFamilyId();
LocalDateTime inclusiveStart = LocalDate.of(2023, 11, 1).atStartOfDay();
LocalDateTime exclusiveEnd = LocalDate.of(2023, 11, 2).atStartOfDay();

// when
Post post = postRepositoryCustomImpl.findLatestPost(inclusiveStart, exclusiveEnd, familyId);

// then
assertThat(post.getId()).isEqualTo("2");
}

@Test
void 시작날짜는_포함하고_종료날짜는_포함하지_않는다() {
// given
String familyId = testMember1.getFamilyId();
LocalDateTime inclusiveStart = LocalDate.of(2023, 11, 1).atStartOfDay();
LocalDateTime exclusiveEnd = LocalDate.of(2023, 11, 1).atStartOfDay();

// when
Post post = postRepositoryCustomImpl.findLatestPost(inclusiveStart, exclusiveEnd, familyId);

// then
assertThat(post).isNull();
}

@Test
void 해당_날짜에_게시글이_없는_경우_null을_반환한다() {
// given
String familyId = testMember1.getFamilyId();
LocalDateTime inclusiveStart = LocalDate.of(9999, 11, 3).atStartOfDay();
LocalDateTime exclusiveEnd = LocalDate.of(9999, 11, 4).atStartOfDay();

// when
Post post = postRepositoryCustomImpl.findLatestPost(inclusiveStart, exclusiveEnd, familyId);

// then
assertThat(post).isNull();
}
}

@Test
void 특정_날짜에_게시글이_존재하는지_확인한다() {
// given
Expand Down

0 comments on commit c2e7ff5

Please sign in to comment.