forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationQueryServiceTest.java
More file actions
432 lines (387 loc) · 16.5 KB
/
ApplicationQueryServiceTest.java
File metadata and controls
432 lines (387 loc) · 16.5 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
package com.example.solidconnection.application.service;
import static org.assertj.core.api.Assertions.assertThat;
import com.example.solidconnection.application.domain.Application;
import com.example.solidconnection.application.dto.ApplicantResponse;
import com.example.solidconnection.application.dto.ApplicantsResponse;
import com.example.solidconnection.application.dto.ApplicationsResponse;
import com.example.solidconnection.application.fixture.ApplicationFixture;
import com.example.solidconnection.application.repository.ApplicationRepository;
import com.example.solidconnection.common.VerifyStatus;
import com.example.solidconnection.location.region.fixture.RegionFixture;
import com.example.solidconnection.score.domain.GpaScore;
import com.example.solidconnection.score.domain.LanguageTestScore;
import com.example.solidconnection.score.fixture.GpaScoreFixture;
import com.example.solidconnection.score.fixture.LanguageTestScoreFixture;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.fixture.SiteUserFixture;
import com.example.solidconnection.support.TestContainerSpringBootTest;
import com.example.solidconnection.term.domain.Term;
import com.example.solidconnection.term.fixture.TermFixture;
import com.example.solidconnection.university.domain.UnivApplyInfo;
import com.example.solidconnection.university.fixture.UnivApplyInfoFixture;
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;
@TestContainerSpringBootTest
@DisplayName("지원서 조회 서비스 테스트")
class ApplicationQueryServiceTest {
@Autowired
private ApplicationQueryService applicationQueryService;
@Autowired
private ApplicationRepository applicationRepository;
@Autowired
private SiteUserFixture siteUserFixture;
@Autowired
private RegionFixture regionFixture;
@Autowired
private UnivApplyInfoFixture univApplyInfoFixture;
@Autowired
private GpaScoreFixture gpaScoreFixture;
@Autowired
private LanguageTestScoreFixture languageTestScoreFixture;
@Autowired
private ApplicationFixture applicationFixture;
@Autowired
private TermFixture termFixture;
private SiteUser user1;
private SiteUser user2;
private SiteUser user3;
private GpaScore gpaScore1;
private GpaScore gpaScore2;
private GpaScore gpaScore3;
private LanguageTestScore languageTestScore1;
private LanguageTestScore languageTestScore2;
private LanguageTestScore languageTestScore3;
private UnivApplyInfo 괌대학_A_지원_정보;
private UnivApplyInfo 버지니아공과대학_지원_정보;
private UnivApplyInfo 서던덴마크대학교_지원_정보;
private Term term;
@BeforeEach
void setUp() {
term = termFixture.현재_학기("2025-2");
user1 = siteUserFixture.사용자(1, "test1");
gpaScore1 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user1);
languageTestScore1 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user1);
user2 = siteUserFixture.사용자(2, "test2");
gpaScore2 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user2);
languageTestScore2 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user2);
user3 = siteUserFixture.사용자(3, "test3");
gpaScore3 = gpaScoreFixture.GPA_점수(VerifyStatus.APPROVED, user3);
languageTestScore3 = languageTestScoreFixture.어학_점수(VerifyStatus.APPROVED, user3);
괌대학_A_지원_정보 = univApplyInfoFixture.괌대학_A_지원_정보(term.getId());
버지니아공과대학_지원_정보 = univApplyInfoFixture.버지니아공과대학_지원_정보(term.getId());
서던덴마크대학교_지원_정보 = univApplyInfoFixture.서던덴마크대학교_지원_정보(term.getId());
}
@Nested
class 지원자_목록_조회_테스트 {
@Test
void 이번_학기_전체_지원자를_조회한다() {
// given
Application application1 = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application application2 = applicationFixture.지원서(
user2,
"nickname2",
term.getId(),
gpaScore2.getGpa(),
languageTestScore2.getLanguageTest(),
버지니아공과대학_지원_정보.getId(),
null,
null
);
Application application3 = applicationFixture.지원서(
user3,
"nickname3",
term.getId(),
gpaScore3.getGpa(),
languageTestScore3.getLanguageTest(),
서던덴마크대학교_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicants(
user1.getId(),
"",
""
);
// then
assertThat(response.firstChoice()).containsAll(List.of(
ApplicantsResponse.of(괌대학_A_지원_정보,
List.of(application1), user1),
ApplicantsResponse.of(버지니아공과대학_지원_정보,
List.of(application2), user1),
ApplicantsResponse.of(서던덴마크대학교_지원_정보,
List.of(application3), user1)
));
}
@Test
void 이번_학기_특정_지역_지원자를_조회한다() {
//given
Application application1 = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application application2 = applicationFixture.지원서(
user2,
"nickname2",
term.getId(),
gpaScore2.getGpa(),
languageTestScore2.getLanguageTest(),
버지니아공과대학_지원_정보.getId(),
null,
null
);
applicationFixture.지원서(
user3,
"nickname3",
term.getId(),
gpaScore3.getGpa(),
languageTestScore3.getLanguageTest(),
서던덴마크대학교_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicants(
user1.getId(),
regionFixture.영미권().getCode(),
""
);
// then
assertThat(response.firstChoice()).containsExactlyInAnyOrder(
ApplicantsResponse.of(괌대학_A_지원_정보,
List.of(application1), user1),
ApplicantsResponse.of(버지니아공과대학_지원_정보,
List.of(application2), user1)
);
}
@Test
void 이번_학기_지원자를_대학_국문_이름으로_필터링해서_조회한다() {
//given
Application application1 = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application application2 = applicationFixture.지원서(
user2,
"nickname2",
term.getId(),
gpaScore2.getGpa(),
languageTestScore2.getLanguageTest(),
버지니아공과대학_지원_정보.getId(),
null,
null
);
applicationFixture.지원서(
user3,
"nickname3",
term.getId(),
gpaScore3.getGpa(),
languageTestScore3.getLanguageTest(),
서던덴마크대학교_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicants(
user1.getId(),
null,
"미국"
);
// then
assertThat(response.firstChoice()).containsExactlyInAnyOrder(
ApplicantsResponse.of(괌대학_A_지원_정보,
List.of(application1), user1),
ApplicantsResponse.of(버지니아공과대학_지원_정보,
List.of(application2), user1)
);
}
@Test
void 현재_학기_지원서만_조회되고_이전_학기_지원서는_제외된다() {
// given
Term previousTerm = termFixture.이전_학기("2024-2");
Application application = applicationFixture.지원서(
user1,
"nickname1_past",
previousTerm.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application currentApplication = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicants(
user1.getId(),
"",
""
);
// then
assertThat(response.firstChoice()).containsExactlyInAnyOrder(
ApplicantsResponse.of(괌대학_A_지원_정보, List.of(currentApplication), user1),
ApplicantsResponse.of(버지니아공과대학_지원_정보, List.of(), user1),
ApplicantsResponse.of(서던덴마크대학교_지원_정보, List.of(), user1)
);
}
@Test
void 동일_유저의_여러_지원서_중_최신_지원서만_조회된다() {
// given
Application firstApplication = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
firstApplication.setIsDeleteTrue();
applicationRepository.save(firstApplication);
Application secondApplication = applicationFixture.지원서(
user1,
"nickname2",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
버지니아공과대학_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicants(
user1.getId(),
"",
""
);
// then
assertThat(response.firstChoice().stream()
.flatMap(univ -> univ.applicants().stream())
.filter(ApplicantResponse::isMine))
.containsExactly(ApplicantResponse.of(secondApplication, true));
}
}
@Nested
class 경쟁자_목록_조회_테스트 {
@Test
void 이번_학기_지원한_대학의_경쟁자_목록을_조회한다() {
// given
Application application1 = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application application2 = applicationFixture.지원서(
user2,
"nickname2",
term.getId(),
gpaScore2.getGpa(),
languageTestScore2.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
applicationFixture.지원서(
user3,
"nickname3",
term.getId(),
gpaScore3.getGpa(),
languageTestScore3.getLanguageTest(),
서던덴마크대학교_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications(user1.getId());
// then
assertThat(response.firstChoice()).containsExactlyInAnyOrder(
ApplicantsResponse.of(괌대학_A_지원_정보,
List.of(application1, application2), user1)
);
}
@Test
void 이번_학기_지원한_대학_중_미선택이_있을_때_경쟁자_목록을_조회한다() {
// given
Application application1 = applicationFixture.지원서(
user1,
"nickname1",
term.getId(),
gpaScore1.getGpa(),
languageTestScore1.getLanguageTest(),
괌대학_A_지원_정보.getId(),
null,
null
);
Application application2 = applicationFixture.지원서(
user2,
"nickname2",
term.getId(),
gpaScore2.getGpa(),
languageTestScore2.getLanguageTest(),
괌대학_A_지원_정보.getId(),
버지니아공과대학_지원_정보.getId(),
서던덴마크대학교_지원_정보.getId()
);
Application application3 = applicationFixture.지원서(
user3,
"nickname3",
term.getId(),
gpaScore3.getGpa(),
languageTestScore3.getLanguageTest(),
서던덴마크대학교_지원_정보.getId(),
null,
null
);
// when
ApplicationsResponse response = applicationQueryService.getApplicantsByUserApplications(user1.getId());
// then
assertThat(response.firstChoice())
.hasSize(1)
.allSatisfy(uar -> {
assertThat(uar.koreanName()).isEqualTo(괌대학_A_지원_정보.getKoreanName());
assertThat(uar.applicants())
.extracting(ApplicantResponse::nicknameForApply)
.containsExactlyInAnyOrder("nickname1", "nickname2");
});
}
}
}