forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminMentorApplicationServiceTest.java
More file actions
380 lines (322 loc) · 18.9 KB
/
AdminMentorApplicationServiceTest.java
File metadata and controls
380 lines (322 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
package com.example.solidconnection.admin.service;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_CONFIRMED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertAll;
import com.example.solidconnection.admin.dto.MentorApplicationCountResponse;
import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest;
import com.example.solidconnection.admin.dto.MentorApplicationSearchCondition;
import com.example.solidconnection.admin.dto.MentorApplicationSearchResponse;
import com.example.solidconnection.common.exception.CustomException;
import com.example.solidconnection.mentor.domain.MentorApplication;
import com.example.solidconnection.mentor.domain.MentorApplicationStatus;
import com.example.solidconnection.mentor.domain.UniversitySelectType;
import com.example.solidconnection.mentor.fixture.MentorApplicationFixture;
import com.example.solidconnection.mentor.repository.MentorApplicationRepository;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.fixture.SiteUserFixture;
import com.example.solidconnection.support.TestContainerSpringBootTest;
import com.example.solidconnection.university.domain.University;
import com.example.solidconnection.university.fixture.UniversityFixture;
import java.time.LocalDate;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@TestContainerSpringBootTest
@DisplayName("멘토 지원서 관리자 서비스 테스트")
class AdminMentorApplicationServiceTest {
@Autowired
private AdminMentorApplicationService adminMentorApplicationService;
@Autowired
private SiteUserFixture siteUserFixture;
@Autowired
private MentorApplicationFixture mentorApplicationFixture;
@Autowired
private UniversityFixture universityFixture;
@Autowired
private MentorApplicationRepository mentorApplicationRepository;
private MentorApplication mentorApplication1;
private MentorApplication mentorApplication2;
private MentorApplication mentorApplication3;
private MentorApplication mentorApplication4;
private MentorApplication mentorApplication5;
private MentorApplication mentorApplication6;
@BeforeEach
void setUp() {
SiteUser user1 = siteUserFixture.사용자(1, "test1");
SiteUser user2 = siteUserFixture.사용자(2, "test2");
SiteUser user3 = siteUserFixture.사용자(3, "test3");
SiteUser user4 = siteUserFixture.사용자(4, "test4");
SiteUser user5 = siteUserFixture.사용자(5, "test5");
SiteUser user6 = siteUserFixture.사용자(6, "test6");
University university1 = universityFixture.메이지_대학();
University university2 = universityFixture.괌_대학();
University university3 = universityFixture.그라츠_대학();
mentorApplication1 = mentorApplicationFixture.승인된_멘토신청(user1.getId(), UniversitySelectType.CATALOG, university1.getId());
mentorApplication2 = mentorApplicationFixture.대기중_멘토신청(user2.getId(), UniversitySelectType.CATALOG, university2.getId());
mentorApplication3 = mentorApplicationFixture.거절된_멘토신청(user3.getId(), UniversitySelectType.CATALOG, university3.getId());
mentorApplication4 = mentorApplicationFixture.승인된_멘토신청(user4.getId(), UniversitySelectType.CATALOG, university3.getId());
mentorApplication5 = mentorApplicationFixture.대기중_멘토신청(user5.getId(), UniversitySelectType.CATALOG, university1.getId());
mentorApplication6 = mentorApplicationFixture.거절된_멘토신청(user6.getId(), UniversitySelectType.CATALOG, university2.getId());
}
@Nested
class 멘토_승격_지원서_목록_조회 {
@Test
void 멘토_승격_상태를_조건으로_페이징하여_조회한다() {
// given
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING,null, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication2, mentorApplication5);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus())
.containsOnly(MentorApplicationStatus.PENDING);
}
@Test
void 닉네임_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
// given
String nickname = "test1";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, nickname, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication1);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.siteUserResponse().nickname())
.containsOnly(nickname);
}
@Test
void 대학명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
// given
String universityKoreanName = "메이지 대학";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, universityKoreanName, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication1, mentorApplication5);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().university())
.containsOnly(universityKoreanName);
}
@Test
void 지역명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
// given
String regionKoreanName = "유럽";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, regionKoreanName, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication3, mentorApplication4);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().region())
.containsOnly(regionKoreanName);
}
@Test
void 나라명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
// given
String countryKoreanName = "오스트리아";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, countryKoreanName, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication3, mentorApplication4);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().country())
.containsOnly(countryKoreanName);
}
@Test
void 모든_조건으로_페이징하여_조회한다() {
// given
String regionKoreanName = "영미권";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING, regionKoreanName, LocalDate.now());
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication2);
// when
Page<MentorApplicationSearchResponse> response = adminMentorApplicationService.searchMentorApplications(condition, pageable);
// then
assertThat(response.getContent()).hasSize(expectedMentorApplications.size());
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().id())
.containsOnly(expectedMentorApplications.stream()
.map(MentorApplication::getId)
.toArray(Long[]::new));
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus())
.containsOnly(MentorApplicationStatus.PENDING);
assertThat(response.getContent())
.extracting(content -> content.mentorApplicationResponse().region())
.containsOnly(regionKoreanName);
}
}
@Nested
class 멘토_승격_지원서_승인{
@Test
void 대기중인_멘토_지원서를_승인한다() {
// given
long pendingMentorApplicationId = mentorApplication2.getId();
// when
adminMentorApplicationService.approveMentorApplication(pendingMentorApplicationId);
// then
MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get();
assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.APPROVED);
assertThat(result.getApprovedAt()).isNotNull();
}
@Test
void 대학이_선택되지_않은_멘토_지원서를_승인하면_예외가_발생한다(){
// given
SiteUser user = siteUserFixture.사용자();
MentorApplication noUniversityIdMentorApplication = mentorApplicationFixture.대기중_멘토신청(user.getId(), UniversitySelectType.OTHER, null);
// when & then
assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(noUniversityIdMentorApplication.getId()))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED.getMessage());
}
@Test
void 이미_승인된_멘토_지원서를_승인하면_예외가_발생한다() {
// given
long approvedMentorApplicationId = mentorApplication1.getId();
// when & then
assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(approvedMentorApplicationId))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage());
}
@Test
void 이미_거절된_멘토_지원서를_승인하면_예외가_발생한다() {
// given
long rejectedMentorApplicationId = mentorApplication3.getId();
// when & then
assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(rejectedMentorApplicationId))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage());
}
@Test
void 존재하지_않는_멘토_지원서를_승인하면_예외가_발생한다() {
// given
long nonExistentId = 99999L;
// when & then
assertThatCode(() -> adminMentorApplicationService.approveMentorApplication(nonExistentId))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_NOT_FOUND.getMessage());
}
}
@Nested
class 멘토_승격_지원서_거절{
@Test
void 대기중인_멘토_지원서를_거절한다() {
// given
long pendingMentorApplicationId = mentorApplication2.getId();
MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락");
// when
adminMentorApplicationService.rejectMentorApplication(pendingMentorApplicationId, request);
// then
MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get();
assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.REJECTED);
assertThat(result.getRejectedReason()).isEqualTo(request.rejectedReason());
}
@Test
void 이미_승인된_멘토_지원서를_거절하면_예외가_발생한다() {
// given
long approvedMentorApplicationId = mentorApplication1.getId();
MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락");
// when & then
assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(approvedMentorApplicationId, request))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage());
}
@Test
void 이미_거절된_멘토_지원서를_거절하면_예외가_발생한다() {
// given
long rejectedMentorApplicationId = mentorApplication3.getId();
MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락");
// when & then
assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(rejectedMentorApplicationId, request))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_ALREADY_CONFIRMED.getMessage());
}
@Test
void 존재하지_않는_멘토_지원서를_거절하면_예외가_발생한다() {
// given
long nonExistentId = 99999L;
MentorApplicationRejectRequest request = new MentorApplicationRejectRequest("파견학교 인증 자료 누락");
// when & then
assertThatCode(() -> adminMentorApplicationService.rejectMentorApplication(nonExistentId, request))
.isInstanceOf(CustomException.class)
.hasMessage(MENTOR_APPLICATION_NOT_FOUND.getMessage());
}
}
@Nested
class 멘토_지원서_상태별_개수_조회 {
@Test
void 상태별_멘토_지원서_개수를_조회한다() {
// given
List<MentorApplication> expectedApprovedCount = List.of(mentorApplication1, mentorApplication4);
List<MentorApplication> expectedPendingCount = List.of(mentorApplication2, mentorApplication5);
List<MentorApplication> expectedRejectedCount = List.of(mentorApplication3, mentorApplication6);
// when
MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount();
// then
assertAll(
() -> assertThat(response.approvedCount()).isEqualTo(expectedApprovedCount.size()),
() -> assertThat(response.pendingCount()).isEqualTo(expectedPendingCount.size()),
() -> assertThat(response.rejectedCount()).isEqualTo(expectedRejectedCount.size())
);
}
@Test
void 멘토_지원서가_없으면_모든_개수가_0이다() {
// given
mentorApplicationRepository.deleteAll();
// when
MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount();
// then
assertAll(
() -> assertThat(response.approvedCount()).isEqualTo(0L),
() -> assertThat(response.pendingCount()).isEqualTo(0L),
() -> assertThat(response.rejectedCount()).isEqualTo(0L)
);
}
}
}