Skip to content

Commit 291a2b1

Browse files
committed
test(VolunteerApplyRepository): 봉사 신청/조회, 모집 ID로 봉사자 ID 리스트/페이징 조회
1 parent 1b1bb3d commit 291a2b1

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.somemore.volunteerApply.repository;
2+
3+
import com.somemore.IntegrationTestSupport;
4+
import com.somemore.volunteerApply.domain.VolunteerApply;
5+
import com.somemore.volunteerApply.domain.ApplyStatus;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.DisplayName;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.data.domain.Page;
11+
import org.springframework.data.domain.PageRequest;
12+
import org.springframework.data.domain.Sort;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
import java.util.List;
16+
import java.util.Optional;
17+
import java.util.UUID;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
@Transactional
22+
class VolunteerApplyRepositoryImplTest extends IntegrationTestSupport {
23+
24+
@Autowired
25+
private VolunteerApplyRepositoryImpl volunteerApplyRepository;
26+
27+
@BeforeEach
28+
void setUp() {
29+
// Given
30+
for (int i = 1; i <= 15; i++) {
31+
VolunteerApply apply = VolunteerApply.builder()
32+
.volunteerId(UUID.randomUUID())
33+
.recruitBoardId(1L)
34+
.status(ApplyStatus.WAITING)
35+
.attended(false)
36+
.build();
37+
volunteerApplyRepository.save(apply);
38+
}
39+
40+
for (int i = 1; i <= 5; i++) {
41+
VolunteerApply apply = VolunteerApply.builder()
42+
.volunteerId(UUID.randomUUID())
43+
.recruitBoardId(2L)
44+
.status(ApplyStatus.APPROVED)
45+
.attended(true)
46+
.build();
47+
volunteerApplyRepository.save(apply);
48+
}
49+
}
50+
51+
@DisplayName("봉사 신청 저장 및 조회")
52+
@Test
53+
void saveAndFindById() {
54+
// Given
55+
VolunteerApply newApply = VolunteerApply.builder()
56+
.volunteerId(UUID.randomUUID())
57+
.recruitBoardId(1L)
58+
.status(ApplyStatus.APPROVED)
59+
.attended(false)
60+
.build();
61+
VolunteerApply savedApply = volunteerApplyRepository.save(newApply);
62+
63+
// When
64+
Optional<VolunteerApply> foundApply = volunteerApplyRepository.findById(savedApply.getId());
65+
66+
// Then
67+
assertThat(foundApply).isPresent();
68+
assertThat(foundApply.get().getId()).isEqualTo(savedApply.getId());
69+
assertThat(foundApply.get().getStatus()).isEqualTo(ApplyStatus.APPROVED);
70+
}
71+
72+
@DisplayName("모집글 ID 리스트로 봉사자 ID 리스트 조회")
73+
@Test
74+
void findVolunteerIdsByRecruitIds() {
75+
// When
76+
List<UUID> volunteerIds = volunteerApplyRepository.findVolunteerIdsByRecruitIds(List.of(1L, 2L));
77+
78+
// Then
79+
assertThat(volunteerIds).hasSize(20);
80+
}
81+
82+
@DisplayName("모집글 ID로 페이징된 봉사 신청 조회")
83+
@Test
84+
void findAllByRecruitId() {
85+
// Given
86+
PageRequest firstPage = PageRequest.of(0, 10, Sort.by(Sort.Order.asc("created_at")));
87+
PageRequest secondPage = PageRequest.of(1, 10, Sort.by(Sort.Order.asc("created_at")));
88+
89+
// When
90+
Page<VolunteerApply> firstPageResult = volunteerApplyRepository.findAllByRecruitId(1L, firstPage);
91+
Page<VolunteerApply> secondPageResult = volunteerApplyRepository.findAllByRecruitId(1L, secondPage);
92+
93+
// Then
94+
assertThat(firstPageResult.getContent()).hasSize(10);
95+
assertThat(firstPageResult.getTotalElements()).isEqualTo(15);
96+
assertThat(firstPageResult.getTotalPages()).isEqualTo(2);
97+
assertThat(firstPageResult.hasNext()).isTrue();
98+
assertThat(firstPageResult.hasPrevious()).isFalse();
99+
100+
assertThat(secondPageResult.getContent()).hasSize(5);
101+
assertThat(secondPageResult.hasNext()).isFalse();
102+
assertThat(secondPageResult.hasPrevious()).isTrue();
103+
}
104+
}

0 commit comments

Comments
 (0)