33import static com .example .solidconnection .common .exception .ErrorCode .UNIV_APPLY_INFO_NOT_FOUND ;
44import static com .example .solidconnection .university .domain .LanguageTestType .TOEIC ;
55import static org .assertj .core .api .Assertions .assertThat ;
6+ import static org .assertj .core .api .Assertions .assertThatCode ;
67import static org .assertj .core .api .AssertionsForClassTypes .assertThatExceptionOfType ;
78import static org .junit .jupiter .api .Assertions .assertAll ;
89import static org .mockito .BDDMockito .then ;
2324import org .junit .jupiter .api .Nested ;
2425import org .junit .jupiter .api .Test ;
2526import org .springframework .beans .factory .annotation .Autowired ;
27+ import org .springframework .beans .factory .annotation .Value ;
2628import org .springframework .boot .test .mock .mockito .SpyBean ;
2729
2830@ TestContainerSpringBootTest
@@ -41,6 +43,9 @@ class UnivApplyInfoQueryServiceTest {
4143 @ Autowired
4244 private LanguageRequirementFixture languageRequirementFixture ;
4345
46+ @ Value ("${university.term}" )
47+ public String term ;
48+
4449 @ Nested
4550 class 대학_지원_정보_상세_조회 {
4651
@@ -97,7 +102,7 @@ class 대학_지원_정보_필터링_검색 {
97102 languageRequirementFixture .토플_70 (괌대학_B_지원_정보 );
98103
99104 // when
100- UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request );
105+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request , term );
101106
102107 // then
103108 assertThat (response .univApplyInfoPreviews ())
@@ -114,7 +119,7 @@ class 대학_지원_정보_필터링_검색 {
114119 languageRequirementFixture .토익_900 (괌대학_B_지원_정보 );
115120
116121 // when
117- UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request );
122+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request , term );
118123
119124 // then
120125 assertThat (response .univApplyInfoPreviews ())
@@ -132,8 +137,8 @@ class 대학_지원_정보_필터링_검색 {
132137 languageRequirementFixture .토익_800 (메모리얼대학_세인트존스_A_지원_정보 );
133138
134139 // when
135- UnivApplyInfoPreviewResponses response1 = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request1 );
136- UnivApplyInfoPreviewResponses response2 = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request2 );
140+ UnivApplyInfoPreviewResponses response1 = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request1 , term );
141+ UnivApplyInfoPreviewResponses response2 = univApplyInfoQueryService .searchUnivApplyInfoByFilter (request2 , term );
137142
138143 // then
139144 assertAll (
@@ -147,4 +152,132 @@ class 대학_지원_정보_필터링_검색 {
147152 );
148153 }
149154 }
155+
156+ @ Nested
157+ class 대학_지원_정보_텍스트_검색 {
158+
159+ @ Test
160+ void 텍스트가_없으면_전체_대학을_id_순으로_정렬하여_반환한다 () {
161+ // given
162+ UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture .괌대학_A_지원_정보 ();
163+ UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture .메이지대학_지원_정보 ();
164+
165+ // when
166+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByText (null , term );
167+
168+ // then
169+ assertThat (response .univApplyInfoPreviews ())
170+ .containsExactly (
171+ UnivApplyInfoPreviewResponse .from (괌대학_A_지원_정보 ),
172+ UnivApplyInfoPreviewResponse .from (메이지대학_지원_정보 )
173+ );
174+ }
175+
176+ @ Nested
177+ class 각각의_검색_대상에_대해_검색한다 {
178+
179+ @ Test
180+ void 국문_대학_지원_정보명 () {
181+ // given
182+ String text = "메" ;
183+ UnivApplyInfo 메이지대학_지원_정보 = univApplyInfoFixture .메이지대학_지원_정보 ();
184+ UnivApplyInfo 메모리얼대학_세인트존스_A_지원_정보 = univApplyInfoFixture .메모리얼대학_세인트존스_A_지원_정보 ();
185+ univApplyInfoFixture .괌대학_A_지원_정보 ();
186+
187+ // when
188+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
189+
190+ // then
191+ assertThat (response .univApplyInfoPreviews ())
192+ .containsExactly (
193+ UnivApplyInfoPreviewResponse .from (메이지대학_지원_정보 ),
194+ UnivApplyInfoPreviewResponse .from (메모리얼대학_세인트존스_A_지원_정보 )
195+ );
196+ }
197+
198+ @ Test
199+ void 국문_국가명 () {
200+ // given
201+ String text = "미국" ;
202+ UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture .괌대학_A_지원_정보 ();
203+ UnivApplyInfo 괌대학_B_지원_정보 = univApplyInfoFixture .괌대학_B_지원_정보 ();
204+ univApplyInfoFixture .메이지대학_지원_정보 ();
205+
206+ // when
207+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
208+
209+ // then
210+ assertThat (response .univApplyInfoPreviews ())
211+ .containsExactly (
212+ UnivApplyInfoPreviewResponse .from (괌대학_A_지원_정보 ),
213+ UnivApplyInfoPreviewResponse .from (괌대학_B_지원_정보 )
214+ );
215+ }
216+
217+ @ Test
218+ void 국문_권역명 () {
219+ // given
220+ String text = "유럽" ;
221+ UnivApplyInfo 린츠_카톨릭대학_지원_정보 = univApplyInfoFixture .린츠_카톨릭대학_지원_정보 ();
222+ UnivApplyInfo 서던덴마크대학교_지원_정보 = univApplyInfoFixture .서던덴마크대학교_지원_정보 ();
223+ univApplyInfoFixture .메이지대학_지원_정보 ();
224+
225+ // when
226+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
227+
228+ // then
229+ assertThat (response .univApplyInfoPreviews ())
230+ .containsExactly (
231+ UnivApplyInfoPreviewResponse .from (린츠_카톨릭대학_지원_정보 ),
232+ UnivApplyInfoPreviewResponse .from (서던덴마크대학교_지원_정보 )
233+ );
234+ }
235+ }
236+
237+ @ Test
238+ void 대학_국가_권역_일치_순서로_정렬하여_응답한다 () {
239+ // given
240+ String text = "아" ;
241+ UnivApplyInfo 권역_아 = univApplyInfoFixture .메이지대학_지원_정보 ();
242+ UnivApplyInfo 국가_아 = univApplyInfoFixture .그라츠대학_지원_정보 ();
243+ UnivApplyInfo 대학지원정보_아 = univApplyInfoFixture .아칸소주립대학_지원_정보 ();
244+
245+ // when
246+ UnivApplyInfoPreviewResponses response = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
247+
248+ // then
249+ assertThat (response .univApplyInfoPreviews ())
250+ .containsExactly (
251+ UnivApplyInfoPreviewResponse .from (대학지원정보_아 ),
252+ UnivApplyInfoPreviewResponse .from (국가_아 ),
253+ UnivApplyInfoPreviewResponse .from (권역_아 )
254+ );
255+ }
256+
257+ @ Test
258+ void 캐시가_적용된다 () {
259+ // given
260+ String text = "Guam" ;
261+ UnivApplyInfo 괌대학_A_지원_정보 = univApplyInfoFixture .괌대학_A_지원_정보 ();
262+
263+ // when
264+ UnivApplyInfoPreviewResponses firstResponse = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
265+ UnivApplyInfoPreviewResponses secondResponse = univApplyInfoQueryService .searchUnivApplyInfoByText (text , term );
266+
267+ // then
268+ assertThatCode (() -> {
269+ List <Long > firstResponseIds = extractIds (firstResponse );
270+ List <Long > secondResponseIds = extractIds (secondResponse );
271+ assertThat (firstResponseIds ).isEqualTo (secondResponseIds );
272+ }).doesNotThrowAnyException ();
273+ then (univApplyInfoRepository ).should (times (1 )).findAllByText (text , term );
274+ }
275+
276+ private List <Long > extractIds (UnivApplyInfoPreviewResponses responses ) {
277+ return responses .univApplyInfoPreviews ()
278+ .stream ()
279+ .map (UnivApplyInfoPreviewResponse ::id )
280+ .toList ();
281+ }
282+ }
150283}
0 commit comments