Skip to content

Commit 8a0012b

Browse files
committed
test(volunteer): 리뷰 조회에 필요한 기능 추가 테스트
1 parent 3bb940f commit 8a0012b

File tree

3 files changed

+122
-21
lines changed

3 files changed

+122
-21
lines changed

src/test/java/com/somemore/common/fixture/RecruitBoardFixture.java

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.somemore.common.fixture;
22

3+
import static com.somemore.common.fixture.LocalDateTimeFixture.createStartDateTime;
4+
import static com.somemore.recruitboard.domain.VolunteerType.OTHER;
5+
36
import com.somemore.recruitboard.domain.RecruitBoard;
47
import com.somemore.recruitboard.domain.RecruitStatus;
58
import com.somemore.recruitboard.domain.RecruitmentInfo;
69
import com.somemore.recruitboard.domain.VolunteerType;
7-
810
import java.lang.reflect.Field;
911
import java.time.LocalDateTime;
1012
import java.util.UUID;
1113

12-
import static com.somemore.common.fixture.LocalDateTimeFixture.createStartDateTime;
13-
import static com.somemore.recruitboard.domain.VolunteerType.OTHER;
14-
1514
public class RecruitBoardFixture {
1615

1716
public static final String REGION = "경기";
@@ -284,6 +283,55 @@ public static RecruitBoard createCompletedRecruitBoard() {
284283
return recruitBoard;
285284
}
286285

286+
public static RecruitBoard createCompletedRecruitBoard(UUID centerId, VolunteerType type) {
287+
RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder()
288+
.region(REGION)
289+
.recruitmentCount(RECRUITMENT_COUNT)
290+
.volunteerStartDateTime(START_DATE_TIME)
291+
.volunteerEndDateTime(END_DATE_TIME)
292+
.volunteerType(type)
293+
.admitted(ADMITTED)
294+
.build();
295+
296+
RecruitBoard recruitBoard = RecruitBoard.builder()
297+
.centerId(centerId)
298+
.locationId(LOCATION_ID)
299+
.title(TITLE)
300+
.content(CONTENT)
301+
.imgUrl(IMG_URL)
302+
.recruitmentInfo(recruitmentInfo)
303+
.build();
304+
305+
setRecruitStatusCompleted(recruitBoard);
306+
307+
return recruitBoard;
308+
}
309+
310+
public static RecruitBoard createCompletedRecruitBoard(VolunteerType type) {
311+
312+
RecruitmentInfo recruitmentInfo = RecruitmentInfo.builder()
313+
.region(REGION)
314+
.recruitmentCount(RECRUITMENT_COUNT)
315+
.volunteerStartDateTime(START_DATE_TIME)
316+
.volunteerEndDateTime(END_DATE_TIME)
317+
.volunteerType(type)
318+
.admitted(ADMITTED)
319+
.build();
320+
321+
RecruitBoard recruitBoard = RecruitBoard.builder()
322+
.centerId(UUID.randomUUID())
323+
.locationId(LOCATION_ID)
324+
.title(TITLE)
325+
.content(CONTENT)
326+
.imgUrl(IMG_URL)
327+
.recruitmentInfo(recruitmentInfo)
328+
.build();
329+
330+
setRecruitStatusCompleted(recruitBoard);
331+
332+
return recruitBoard;
333+
}
334+
287335
private static void setRecruitStatusCompleted(RecruitBoard recruitBoard) {
288336
try {
289337
Field recruitStatusField = RecruitBoard.class.getDeclaredField("recruitStatus");

src/test/java/com/somemore/volunteer/repository/VolunteerRepositoryTest.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.somemore.volunteer.repository;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import com.somemore.IntegrationTestSupport;
46
import com.somemore.auth.oauth.OAuthProvider;
57
import com.somemore.volunteer.domain.Volunteer;
8+
import java.util.List;
9+
import java.util.Optional;
10+
import java.util.UUID;
611
import org.junit.jupiter.api.BeforeEach;
712
import org.junit.jupiter.api.DisplayName;
813
import org.junit.jupiter.api.Test;
914
import org.springframework.beans.factory.annotation.Autowired;
1015
import org.springframework.transaction.annotation.Transactional;
1116

12-
import java.util.Optional;
13-
import java.util.UUID;
14-
15-
import static org.assertj.core.api.Assertions.assertThat;
16-
1717
@Transactional
1818
class VolunteerRepositoryTest extends IntegrationTestSupport {
1919

@@ -22,7 +22,7 @@ class VolunteerRepositoryTest extends IntegrationTestSupport {
2222

2323
String oAuthId;
2424
Volunteer volunteer;
25-
25+
2626
@BeforeEach
2727
void setup() {
2828
oAuthId = "example-oauth-id";
@@ -76,4 +76,29 @@ void findByOauthId() {
7676
assertThat(foundVolunteer.get().getOauthId()).isEqualTo(oAuthId);
7777
assertThat(foundVolunteer.get().getNickname()).isEqualTo(volunteer.getNickname());
7878
}
79-
}
79+
80+
@DisplayName("아이디 리스트로 봉사자를 조회할 수있다.")
81+
@Test
82+
void findAllByIds() {
83+
// given
84+
Volunteer volunteer1 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
85+
Volunteer volunteer2 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
86+
Volunteer volunteer3 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
87+
Volunteer volunteer4 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
88+
volunteer4.markAsDeleted();
89+
90+
volunteerRepository.save(volunteer1);
91+
volunteerRepository.save(volunteer2);
92+
volunteerRepository.save(volunteer3);
93+
volunteerRepository.save(volunteer4);
94+
95+
// when
96+
List<Volunteer> volunteers = volunteerRepository.findAllByIds(
97+
List.of(volunteer1.getId(), volunteer2.getId(), volunteer3.getId(),
98+
volunteer4.getId()
99+
));
100+
101+
// then
102+
assertThat(volunteers).hasSize(3);
103+
}
104+
}

src/test/java/com/somemore/volunteer/service/VolunteerQueryServiceTest.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.somemore.volunteer.service;
22

3+
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;
4+
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_DETAIL;
5+
import static com.somemore.volunteer.domain.Volunteer.createDefault;
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
8+
39
import com.somemore.IntegrationTestSupport;
410
import com.somemore.auth.oauth.OAuthProvider;
511
import com.somemore.global.exception.BadRequestException;
@@ -9,19 +15,13 @@
915
import com.somemore.volunteer.dto.response.VolunteerProfileResponseDto;
1016
import com.somemore.volunteer.repository.VolunteerDetailRepository;
1117
import com.somemore.volunteer.repository.VolunteerRepository;
18+
import java.util.List;
19+
import java.util.UUID;
1220
import org.junit.jupiter.api.DisplayName;
1321
import org.junit.jupiter.api.Test;
1422
import org.springframework.beans.factory.annotation.Autowired;
1523
import org.springframework.transaction.annotation.Transactional;
1624

17-
import java.util.UUID;
18-
19-
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER;
20-
import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_DETAIL;
21-
import static com.somemore.volunteer.domain.Volunteer.createDefault;
22-
import static org.assertj.core.api.Assertions.assertThat;
23-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
24-
2525
@Transactional
2626
class VolunteerQueryServiceTest extends IntegrationTestSupport {
2727

@@ -123,7 +123,8 @@ void getVolunteerProfile() {
123123
volunteerDetailRepository.save(volunteerDetail);
124124

125125
// when
126-
VolunteerProfileResponseDto response = volunteerQueryService.getVolunteerProfile(volunteerId);
126+
VolunteerProfileResponseDto response = volunteerQueryService.getVolunteerProfile(
127+
volunteerId);
127128

128129
// then
129130
assertThat(response).isNotNull();
@@ -147,11 +148,38 @@ void getVolunteerDetailedProfile() {
147148

148149
// when
149150
// then
150-
assertThatThrownBy(() -> volunteerQueryService.getVolunteerDetailedProfile(volunteerId, centerId))
151+
assertThatThrownBy(
152+
() -> volunteerQueryService.getVolunteerDetailedProfile(volunteerId, centerId))
151153
.isInstanceOf(BadRequestException.class)
152154
.hasMessage(UNAUTHORIZED_VOLUNTEER_DETAIL.getMessage());
153155
}
154156

157+
@DisplayName("아이디 리스트로 봉사자를 조회할 수있다.")
158+
@Test
159+
void findAllByIds() {
160+
// given
161+
Volunteer volunteer1 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
162+
Volunteer volunteer2 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
163+
Volunteer volunteer3 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
164+
Volunteer volunteer4 = Volunteer.createDefault(OAuthProvider.NAVER, "1234");
165+
volunteer3.markAsDeleted();
166+
volunteer4.markAsDeleted();
167+
168+
volunteerRepository.save(volunteer1);
169+
volunteerRepository.save(volunteer2);
170+
volunteerRepository.save(volunteer3);
171+
volunteerRepository.save(volunteer4);
172+
173+
// when
174+
List<Volunteer> volunteers = volunteerQueryService.getAllByIds(
175+
List.of(volunteer1.getId(), volunteer2.getId(), volunteer3.getId(),
176+
volunteer4.getId(), UUID.randomUUID()
177+
));
178+
179+
// then
180+
assertThat(volunteers).hasSize(2);
181+
}
182+
155183
private static VolunteerDetail createVolunteerDetail(UUID volunteerId) {
156184

157185
VolunteerRegisterRequestDto volunteerRegisterRequestDto =

0 commit comments

Comments
 (0)