Skip to content

Commit 322aba5

Browse files
committed
test(volunteer-apply): 봉사자 조회 기능 변경에 따른 봉사 지원 조회 기능 리팩토링 테스트
1 parent b918663 commit 322aba5

File tree

2 files changed

+63
-75
lines changed

2 files changed

+63
-75
lines changed

src/test/java/com/somemore/domains/volunteerapply/repository/VolunteerApplyRepositoryImplTest.java

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import java.util.Optional;
1919
import java.util.UUID;
2020

21-
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED;
22-
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.REJECTED;
21+
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.*;
2322
import static org.assertj.core.api.Assertions.assertThat;
2423

2524
@Transactional
@@ -30,12 +29,11 @@ class VolunteerApplyRepositoryImplTest extends IntegrationTestSupport {
3029

3130
@BeforeEach
3231
void setUp() {
33-
// Given
3432
for (int i = 1; i <= 15; i++) {
3533
VolunteerApply apply = VolunteerApply.builder()
3634
.volunteerId(UUID.randomUUID())
3735
.recruitBoardId(1L)
38-
.status(ApplyStatus.WAITING)
36+
.status(WAITING)
3937
.attended(false)
4038
.build();
4139
volunteerApplyRepository.save(apply);
@@ -55,44 +53,41 @@ void setUp() {
5553
@DisplayName("봉사 신청 저장 및 조회")
5654
@Test
5755
void saveAndFindById() {
58-
// Given
56+
// given
5957
VolunteerApply newApply = createApply(UUID.randomUUID(), 1L);
60-
VolunteerApply savedApply = volunteerApplyRepository.save(newApply);
58+
volunteerApplyRepository.save(newApply);
6159

62-
// When
63-
Optional<VolunteerApply> foundApply = volunteerApplyRepository.findById(savedApply.getId());
60+
// when
61+
Optional<VolunteerApply> foundApply = volunteerApplyRepository.findById(newApply.getId());
6462

65-
// Then
63+
// then
6664
assertThat(foundApply).isPresent();
67-
assertThat(foundApply.get().getId()).isEqualTo(savedApply.getId());
65+
assertThat(foundApply.get().getId()).isEqualTo(newApply.getId());
6866
assertThat(foundApply.get().getStatus()).isEqualTo(APPROVED);
6967
}
7068

7169
@DisplayName("모집글 ID 리스트로 봉사자 ID 리스트 조회")
7270
@Test
7371
void findVolunteerIdsByRecruitIds() {
74-
// When
75-
List<UUID> volunteerIds = volunteerApplyRepository.findVolunteerIdsByRecruitIds(
76-
List.of(1L, 2L));
72+
// when
73+
List<UUID> volunteerIds = volunteerApplyRepository.findVolunteerIdsByRecruitIds(List.of(1L, 2L));
7774

78-
// Then
75+
// then
7976
assertThat(volunteerIds).hasSize(20);
8077
}
8178

8279
@DisplayName("모집글 ID로 페이징된 봉사 신청 조회")
8380
@Test
8481
void findAllByRecruitId() {
85-
// Given
82+
// given
8683
PageRequest firstPage = PageRequest.of(0, 10, Sort.by(Sort.Order.asc("created_at")));
8784
PageRequest secondPage = PageRequest.of(1, 10, Sort.by(Sort.Order.asc("created_at")));
8885

89-
// When
90-
Page<VolunteerApply> firstPageResult = volunteerApplyRepository.findAllByRecruitId(1L,
91-
firstPage);
92-
Page<VolunteerApply> secondPageResult = volunteerApplyRepository.findAllByRecruitId(1L,
93-
secondPage);
86+
// when
87+
Page<VolunteerApply> firstPageResult = volunteerApplyRepository.findAllByRecruitId(1L, firstPage);
88+
Page<VolunteerApply> secondPageResult = volunteerApplyRepository.findAllByRecruitId(1L, secondPage);
9489

95-
// Then
90+
// then
9691
assertThat(firstPageResult.getContent()).hasSize(10);
9792
assertThat(firstPageResult.getTotalElements()).isEqualTo(15);
9893
assertThat(firstPageResult.getTotalPages()).isEqualTo(2);
@@ -115,8 +110,7 @@ void findByRecruitIdAndVolunteerId() {
115110
volunteerApplyRepository.save(newApply);
116111

117112
// when
118-
Optional<VolunteerApply> findApply = volunteerApplyRepository.findByRecruitIdAndVolunteerId(
119-
recruitId, volunteerId);
113+
Optional<VolunteerApply> findApply = volunteerApplyRepository.findByRecruitIdAndVolunteerId(recruitId, volunteerId);
120114

121115
// then
122116
assertThat(findApply).isPresent();
@@ -133,8 +127,7 @@ void existsByRecruitIdAndVolunteerId() {
133127
volunteerApplyRepository.save(newApply);
134128

135129
// when
136-
boolean result = volunteerApplyRepository.existsByRecruitIdAndVolunteerId(recruitId,
137-
volunteerId);
130+
boolean result = volunteerApplyRepository.existsByRecruitIdAndVolunteerId(recruitId, volunteerId);
138131

139132
// then
140133
assertThat(result).isTrue();
@@ -173,28 +166,27 @@ void findAllByRecruitIdWithCondition() {
173166
.build();
174167

175168
// when
176-
Page<VolunteerApply> applies = volunteerApplyRepository.findAllByRecruitId(recruitBoardId,
177-
condition);
169+
Page<VolunteerApply> applies = volunteerApplyRepository.findAllByRecruitId(recruitBoardId, condition);
178170

179171
// then
180172
assertThat(applies.getTotalElements()).isEqualTo(3);
181173
assertThat(applies.getContent())
182-
.allMatch(apply -> apply.getStatus() == APPROVED && !apply.getAttended());
174+
.allMatch(apply -> apply.getStatus() == status && apply.getAttended() == attended);
183175

184176
}
185177

186178
@DisplayName("봉사자 아이디와 조건 - 지원 상태, 참석 여부로 페이징 조회할 수 있다.")
187179
@Test
188180
void findAllByVolunteerId() {
189181
// given
190-
UUID centerId = UUID.randomUUID();
182+
UUID volunteerId = UUID.randomUUID();
191183
ApplyStatus status = APPROVED;
192184
Boolean attended = false;
193185

194-
volunteerApplyRepository.save(createApply(centerId, status, attended));
195-
volunteerApplyRepository.save(createApply(centerId, status, attended));
196-
volunteerApplyRepository.save(createApply(centerId, status, attended));
197-
volunteerApplyRepository.save(createApply(centerId, REJECTED, !attended));
186+
volunteerApplyRepository.save(createApply(volunteerId, status, attended));
187+
volunteerApplyRepository.save(createApply(volunteerId, status, attended));
188+
volunteerApplyRepository.save(createApply(volunteerId, status, attended));
189+
volunteerApplyRepository.save(createApply(volunteerId, REJECTED, !attended));
198190

199191
VolunteerApplySearchCondition condition = VolunteerApplySearchCondition.builder()
200192
.status(status)
@@ -203,13 +195,12 @@ void findAllByVolunteerId() {
203195
.build();
204196

205197
// when
206-
Page<VolunteerApply> applies = volunteerApplyRepository.findAllByVolunteerId(centerId,
207-
condition);
198+
Page<VolunteerApply> applies = volunteerApplyRepository.findAllByVolunteerId(volunteerId, condition);
208199

209200
// then
210201
assertThat(applies.getTotalElements()).isEqualTo(3);
211202
assertThat(applies.getContent())
212-
.allMatch(apply -> apply.getStatus() == APPROVED && !apply.getAttended());
203+
.allMatch(apply -> apply.getStatus() == status && apply.getAttended() == attended);
213204

214205
}
215206

@@ -250,8 +241,7 @@ private static VolunteerApply createApply(UUID volunteerId, Long recruitId) {
250241
.build();
251242
}
252243

253-
private static VolunteerApply createApply(Long recruitId, ApplyStatus status,
254-
Boolean attended) {
244+
private static VolunteerApply createApply(Long recruitId, ApplyStatus status, Boolean attended) {
255245
return VolunteerApply.builder()
256246
.volunteerId(UUID.randomUUID())
257247
.recruitBoardId(recruitId)
@@ -260,10 +250,9 @@ private static VolunteerApply createApply(Long recruitId, ApplyStatus status,
260250
.build();
261251
}
262252

263-
private static VolunteerApply createApply(UUID centerId, ApplyStatus status,
264-
Boolean attended) {
253+
private static VolunteerApply createApply(UUID volunteerId, ApplyStatus status, Boolean attended) {
265254
return VolunteerApply.builder()
266-
.volunteerId(centerId)
255+
.volunteerId(volunteerId)
267256
.recruitBoardId(101L)
268257
.status(status)
269258
.attended(attended)

src/test/java/com/somemore/domains/volunteerapply/service/VolunteerApplyQueryFacadeServiceTest.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
import com.somemore.support.IntegrationTestSupport;
2424
import java.util.List;
2525
import java.util.UUID;
26+
27+
import com.somemore.user.domain.UserCommonAttribute;
28+
import com.somemore.user.domain.UserRole;
29+
import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository;
30+
import com.somemore.volunteer.domain.NEWVolunteer;
31+
import com.somemore.volunteer.repository.NEWVolunteerRepository;
2632
import org.junit.jupiter.api.DisplayName;
2733
import org.junit.jupiter.api.Test;
2834
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,9 +45,9 @@ class VolunteerApplyQueryFacadeServiceTest extends IntegrationTestSupport {
3945
@Autowired
4046
private RecruitBoardRepository recruitBoardRepository;
4147
@Autowired
42-
private VolunteerRepository volunteerRepository;
48+
private NEWVolunteerRepository volunteerRepository;
4349
@Autowired
44-
private VolunteerDetailRepository volunteerDetailRepository;
50+
private UserCommonAttributeRepository userCommonAttributeRepository;
4551
@Autowired
4652
private VolunteerApplyRepository volunteerApplyRepository;
4753
@Autowired
@@ -60,8 +66,8 @@ void getVolunteerApplyByRecruitIdAndVolunteerId() {
6066
reviewRepository.save(review);
6167

6268
// when
63-
VolunteerApplyWithReviewStatusResponseDto dto = volunteerApplyQueryFacadeService.getVolunteerApplyByRecruitIdAndVolunteerId(
64-
recruitBoardId, volunteerId);
69+
VolunteerApplyWithReviewStatusResponseDto dto =
70+
volunteerApplyQueryFacadeService.getVolunteerApplyByRecruitIdAndVolunteerId(recruitBoardId, volunteerId);
6571

6672
// then
6773
assertThat(dto.recruitBoardId()).isEqualTo(recruitBoardId);
@@ -77,28 +83,30 @@ void getVolunteerAppliesByRecruitIdAndCenterId() {
7783
RecruitBoard board = createRecruitBoard(centerId);
7884
recruitBoardRepository.save(board);
7985

80-
Volunteer volunteer1 = Volunteer.createDefault(NAVER, "naver");
81-
Volunteer volunteer2 = Volunteer.createDefault(NAVER, "naver");
82-
volunteerRepository.save(volunteer1);
83-
volunteerRepository.save(volunteer2);
86+
UUID userIdOne = UUID.randomUUID();
87+
UUID userIdTwo = UUID.randomUUID();
88+
89+
UserCommonAttribute userOne = createUserCommonAttribute(userIdOne);
90+
UserCommonAttribute userTwo = createUserCommonAttribute(userIdTwo);
91+
userCommonAttributeRepository.save(userOne);
92+
userCommonAttributeRepository.save(userTwo);
8493

85-
VolunteerDetail volunteerDetail1 = createVolunteerDetail(volunteer1.getId());
86-
VolunteerDetail volunteerDetail2 = createVolunteerDetail(volunteer2.getId());
87-
volunteerDetailRepository.save(volunteerDetail1);
88-
volunteerDetailRepository.save(volunteerDetail2);
94+
NEWVolunteer volunteerOne = createVolunteer(userIdOne);
95+
NEWVolunteer volunteerTwo = createVolunteer(userIdTwo);
96+
volunteerRepository.save(volunteerOne);
97+
volunteerRepository.save(volunteerTwo);
8998

90-
VolunteerApply apply1 = createApply(volunteer1.getId(), board.getId());
91-
VolunteerApply apply2 = createApply(volunteer2.getId(), board.getId());
99+
VolunteerApply apply1 = createApply(volunteerOne.getId(), board.getId());
100+
VolunteerApply apply2 = createApply(volunteerTwo.getId(), board.getId());
92101
volunteerApplyRepository.saveAll(List.of(apply1, apply2));
93102

94103
VolunteerApplySearchCondition condition = VolunteerApplySearchCondition.builder()
95104
.pageable(getPageable())
96105
.build();
97106

98107
// when
99-
Page<VolunteerApplyVolunteerInfoResponseDto> result = volunteerApplyQueryFacadeService.getVolunteerAppliesByRecruitIdAndCenterId(
100-
board.getId(),
101-
centerId, condition);
108+
Page<VolunteerApplyVolunteerInfoResponseDto> result =
109+
volunteerApplyQueryFacadeService.getVolunteerAppliesByRecruitIdAndCenterId(board.getId(), centerId, condition);
102110

103111
// then
104112
assertThat(result).hasSize(2);
@@ -142,23 +150,6 @@ private static Review createReview(Long volunteerApplyId, UUID volunteerId) {
142150
.build();
143151
}
144152

145-
private static VolunteerDetail createVolunteerDetail(UUID volunteerId) {
146-
147-
VolunteerRegisterRequestDto volunteerRegisterRequestDto =
148-
new VolunteerRegisterRequestDto(
149-
NAVER,
150-
"example-oauth-id",
151-
"making",
152-
153-
"male",
154-
"06-08",
155-
"1998",
156-
"010-1234-5678"
157-
);
158-
159-
return VolunteerDetail.of(volunteerRegisterRequestDto, volunteerId);
160-
}
161-
162153
private static VolunteerApply createApply(UUID volunteerId, Long recruitId) {
163154
return VolunteerApply.builder()
164155
.volunteerId(volunteerId)
@@ -168,6 +159,14 @@ private static VolunteerApply createApply(UUID volunteerId, Long recruitId) {
168159
.build();
169160
}
170161

162+
private static NEWVolunteer createVolunteer(UUID userIdOne) {
163+
return NEWVolunteer.createDefault(userIdOne);
164+
}
165+
166+
private static UserCommonAttribute createUserCommonAttribute(UUID userIdOne) {
167+
return UserCommonAttribute.createDefault(userIdOne, UserRole.VOLUNTEER);
168+
}
169+
171170
private Pageable getPageable() {
172171
return PageRequest.of(0, 4);
173172
}

0 commit comments

Comments
 (0)