-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathApplicantsQueryTest.java
More file actions
282 lines (244 loc) · 15.5 KB
/
ApplicantsQueryTest.java
File metadata and controls
282 lines (244 loc) · 15.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
package com.example.solidconnection.e2e;
import com.example.solidconnection.application.domain.Application;
import com.example.solidconnection.application.domain.Gpa;
import com.example.solidconnection.application.domain.LanguageTest;
import com.example.solidconnection.application.dto.ApplicantResponse;
import com.example.solidconnection.application.dto.ApplicationsResponse;
import com.example.solidconnection.application.dto.UniversityApplicantsResponse;
import com.example.solidconnection.application.repository.ApplicationRepository;
import com.example.solidconnection.auth.service.AuthTokenProvider;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
import com.example.solidconnection.type.VerifyStatus;
import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.List;
import static com.example.solidconnection.e2e.DynamicFixture.createDummyGpa;
import static com.example.solidconnection.e2e.DynamicFixture.createDummyLanguageTest;
import static com.example.solidconnection.e2e.DynamicFixture.createSiteUserByEmail;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayName("지원자 조회 테스트")
class ApplicantsQueryTest extends UniversityDataSetUpEndToEndTest {
@Autowired
private SiteUserRepository siteUserRepository;
@Autowired
private ApplicationRepository applicationRepository;
@Autowired
private AuthTokenProvider authTokenProvider;
private String accessToken;
private String adminAccessToken;
private String user6AccessToken;
private Application 나의_지원정보;
private Application 사용자1_지원정보;
private Application 사용자2_지원정보;
private Application 사용자3_지원정보;
private Application 사용자4_이전학기_지원정보;
private Application 사용자5_관리자_지원정보;
private Application 사용자6_지원정보;
@Value("${university.term}")
private String term;
private String beforeTerm = "1988-1";
@BeforeEach
public void setUpUserAndToken() {
// setUp - 사용자 정보 저장
SiteUser 나 = siteUserRepository.save(createSiteUserByEmail("my-email"));
SiteUser 사용자1 = siteUserRepository.save(createSiteUserByEmail("email1"));
SiteUser 사용자2 = siteUserRepository.save(createSiteUserByEmail("email2"));
SiteUser 사용자3 = siteUserRepository.save(createSiteUserByEmail("email3"));
SiteUser 사용자4_이전학기_지원자 = siteUserRepository.save(createSiteUserByEmail("email4"));
SiteUser 사용자5_관리자 = siteUserRepository.save(createSiteUserByEmail("email5"));
SiteUser 사용자6 = siteUserRepository.save(createSiteUserByEmail("email6"));
// setUp - 엑세스 토큰 생성과 리프레시 토큰 생성 및 저장
accessToken = authTokenProvider.generateAccessToken(나);
authTokenProvider.generateAndSaveRefreshToken(나);
adminAccessToken = authTokenProvider.generateAccessToken(사용자5_관리자);
authTokenProvider.generateAndSaveRefreshToken(사용자5_관리자);
user6AccessToken = authTokenProvider.generateAccessToken(사용자6);
authTokenProvider.generateAndSaveRefreshToken(사용자6);
// setUp - 지원 정보 저장
Gpa gpa = createDummyGpa();
LanguageTest languageTest = createDummyLanguageTest();
나의_지원정보 = new Application(나, gpa, languageTest, term);
사용자1_지원정보 = new Application(사용자1, gpa, languageTest, term);
사용자2_지원정보 = new Application(사용자2, gpa, languageTest, term);
사용자3_지원정보 = new Application(사용자3, gpa, languageTest, term);
사용자4_이전학기_지원정보 = new Application(사용자4_이전학기_지원자, gpa, languageTest, beforeTerm);
사용자5_관리자_지원정보 = new Application(사용자5_관리자, gpa, languageTest, term);
사용자6_지원정보 = new Application(사용자6, gpa, languageTest, term);
나의_지원정보.updateUniversityChoice(괌대학_B_지원_정보, 괌대학_A_지원_정보, 린츠_카톨릭대학_지원_정보, "0");
사용자1_지원정보.updateUniversityChoice(괌대학_A_지원_정보, 괌대학_B_지원_정보, 그라츠공과대학_지원_정보, "1");
사용자2_지원정보.updateUniversityChoice(메이지대학_지원_정보, 그라츠대학_지원_정보, 서던덴마크대학교_지원_정보, "2");
사용자3_지원정보.updateUniversityChoice(네바다주립대학_라스베이거스_지원_정보, 그라츠공과대학_지원_정보, 메이지대학_지원_정보, "3");
사용자4_이전학기_지원정보.updateUniversityChoice(네바다주립대학_라스베이거스_지원_정보, 그라츠공과대학_지원_정보, 메이지대학_지원_정보, "4");
사용자6_지원정보.updateUniversityChoice(코펜하겐IT대학_지원_정보, null, null, "6");
나의_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자1_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자2_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자3_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자4_이전학기_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자5_관리자_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
사용자6_지원정보.setVerifyStatus(VerifyStatus.APPROVED);
applicationRepository.saveAll(List.of(나의_지원정보, 사용자1_지원정보, 사용자2_지원정보, 사용자3_지원정보, 사용자4_이전학기_지원정보, 사용자5_관리자_지원정보, 사용자6_지원정보));
}
@Test
void 전체_지원자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.when().log().all()
.get("/applications/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();
assertThat(firstChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of())
));
assertThat(secondChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, false))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, true))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of())
));
assertThat(thirdChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of()),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of()),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true)))
));
}
@Test
void 지역으로_필터링해서_지원자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.when().log().all()
.get("/applications/competitors?region=" + 영미권.getCode())
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
assertThat(firstChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true)))
));
assertThat(secondChoiceApplicants).containsAnyElementsOf(List.of(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false)))
));
}
@Test
void 지원자를_조회할_때_이전학기_지원자는_조회되지_않는다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.when().log().all()
.get("/applications/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();
assertThat(firstChoiceApplicants).doesNotContainAnyElementsOf(List.of(
UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보,
List.of(ApplicantResponse.of(사용자4_이전학기_지원정보, false)))
));
assertThat(secondChoiceApplicants).doesNotContainAnyElementsOf(List.of(
UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보,
List.of(ApplicantResponse.of(사용자4_이전학기_지원정보, false)))
));
assertThat(thirdChoiceApplicants).doesNotContainAnyElementsOf(List.of(
UniversityApplicantsResponse.of(네바다주립대학_라스베이거스_지원_정보,
List.of(ApplicantResponse.of(사용자4_이전학기_지원정보, false)))
));
}
@Test
void 경쟁자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.when().log().all()
.get("/applications/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
Integer choicedUniversityCount = 3;
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();
assertThat(firstChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보, List.of()));
assertThat(secondChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of()));
assertThat(thirdChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of()),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of()),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))));
assertThat(firstChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(secondChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(thirdChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
}
@Test
void 지원_대학중_미선택이_있을_떄_경쟁자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + user6AccessToken)
.when().log().all()
.get("/applications/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
Integer choicedUniversityCount = 1;
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();
assertThat(firstChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(secondChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(thirdChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
}
@Test
void 지원_대학이_모두_미선택일_때_경쟁자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + adminAccessToken)
.when().log().all()
.get("/applications/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);
Integer choicedUniversityCount = 0;
List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();
assertThat(firstChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(secondChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
assertThat(thirdChoiceApplicants.size()).isEqualTo(choicedUniversityCount);
}
}