33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatCode ;
55import static org .assertj .core .api .AssertionsForClassTypes .tuple ;
6+ import static org .junit .jupiter .api .Assertions .assertAll ;
67
78import com .example .solidconnection .chat .domain .ChatRoom ;
89import com .example .solidconnection .chat .fixture .ChatRoomFixture ;
910import com .example .solidconnection .common .VerifyStatus ;
1011import com .example .solidconnection .common .dto .SliceResponse ;
1112import com .example .solidconnection .common .exception .CustomException ;
1213import com .example .solidconnection .common .exception .ErrorCode ;
14+ import com .example .solidconnection .mentor .domain .Channel ;
1315import com .example .solidconnection .mentor .domain .Mentor ;
1416import com .example .solidconnection .mentor .domain .Mentoring ;
17+ import com .example .solidconnection .mentor .dto .ChannelResponse ;
18+ import com .example .solidconnection .mentor .dto .MatchedMentorResponse ;
1519import com .example .solidconnection .mentor .dto .MentoringForMenteeResponse ;
1620import com .example .solidconnection .mentor .dto .MentoringForMentorResponse ;
21+ import com .example .solidconnection .mentor .fixture .ChannelFixture ;
1722import com .example .solidconnection .mentor .fixture .MentorFixture ;
1823import com .example .solidconnection .mentor .fixture .MentoringFixture ;
1924import com .example .solidconnection .mentor .repository .MentoringRepository ;
2025import com .example .solidconnection .siteuser .domain .SiteUser ;
2126import com .example .solidconnection .siteuser .fixture .SiteUserFixture ;
2227import com .example .solidconnection .support .TestContainerSpringBootTest ;
28+ import com .example .solidconnection .university .domain .University ;
29+ import com .example .solidconnection .university .fixture .UniversityFixture ;
30+ import java .util .Map ;
31+ import java .util .function .Function ;
32+ import java .util .stream .Collectors ;
2333import org .junit .jupiter .api .BeforeEach ;
2434import org .junit .jupiter .api .DisplayName ;
2535import org .junit .jupiter .api .Nested ;
@@ -44,6 +54,12 @@ class MentoringQueryServiceTest {
4454 @ Autowired
4555 private MentoringFixture mentoringFixture ;
4656
57+ @ Autowired
58+ private UniversityFixture universityFixture ;
59+
60+ @ Autowired
61+ private ChannelFixture channelFixture ;
62+
4763 @ Autowired
4864 private MentoringRepository mentoringRepository ;
4965
@@ -53,6 +69,7 @@ class MentoringQueryServiceTest {
5369 private SiteUser mentorUser1 , mentorUser2 ;
5470 private SiteUser menteeUser1 , menteeUser2 , menteeUser3 ;
5571 private Mentor mentor1 , mentor2 , mentor3 ;
72+ private University university ;
5673 private Pageable pageable ;
5774
5875 @ BeforeEach
@@ -63,9 +80,10 @@ void setUp() {
6380 menteeUser1 = siteUserFixture .사용자 (1 , "mentee1" );
6481 menteeUser2 = siteUserFixture .사용자 (2 , "mentee2" );
6582 menteeUser3 = siteUserFixture .사용자 (3 , "mentee3" );
66- mentor1 = mentorFixture .멘토 (mentorUser1 .getId (), 1L );
67- mentor2 = mentorFixture .멘토 (mentorUser2 .getId (), 1L );
68- mentor3 = mentorFixture .멘토 (mentorUser3 .getId (), 1L );
83+ university = universityFixture .괌_대학 ();
84+ mentor1 = mentorFixture .멘토 (mentorUser1 .getId (), university .getId ());
85+ mentor2 = mentorFixture .멘토 (mentorUser2 .getId (), university .getId ());
86+ mentor3 = mentorFixture .멘토 (mentorUser3 .getId (), university .getId ());
6987 pageable = PageRequest .of (0 , 3 );
7088 }
7189
@@ -239,4 +257,71 @@ class 멘티의_멘토링_목록_조회_테스트 {
239257 assertThat (response .content ()).isEmpty ();
240258 }
241259 }
260+
261+ @ Nested
262+ class 멘티의_멘토_목록_조회_테스트 {
263+
264+ private static final int NO_NEXT_PAGE_NUMBER = -1 ;
265+
266+ private Mentoring mentoring1 , mentoring2 ;
267+ private ChatRoom chatRoom1 , chatRoom2 ;
268+
269+ @ BeforeEach
270+ void setUp () {
271+ mentoring1 = mentoringFixture .승인된_멘토링 (mentor1 .getId (), menteeUser1 .getId ());
272+ mentoring2 = mentoringFixture .승인된_멘토링 (mentor2 .getId (), menteeUser1 .getId ());
273+
274+ chatRoom1 = chatRoomFixture .멘토링_채팅방 (mentoring1 .getId ());
275+ chatRoom2 = chatRoomFixture .멘토링_채팅방 (mentoring2 .getId ());
276+ }
277+
278+ @ Test
279+ void 매칭된_멘토의_목록_정보를_조회한다 () {
280+ // given
281+ Channel channel1 = channelFixture .채널 (1 , mentor1 );
282+ Channel channel2 = channelFixture .채널 (2 , mentor2 );
283+
284+ // when
285+ SliceResponse <MatchedMentorResponse > response = mentoringQueryService .getMatchedMentors (menteeUser1 .getId (), PageRequest .of (0 , 10 ));
286+
287+ // then
288+ Map <Long , MatchedMentorResponse > matchMentorMap = response .content ().stream ()
289+ .collect (Collectors .toMap (MatchedMentorResponse ::id , Function .identity ()));
290+ MatchedMentorResponse mentor1Response = matchMentorMap .get (mentor1 .getId ());
291+ MatchedMentorResponse mentor2Response = matchMentorMap .get (mentor2 .getId ());
292+ assertAll (
293+ () -> assertThat (mentor1Response .roomId ()).isEqualTo (chatRoom1 .getId ()),
294+ () -> assertThat (mentor1Response .nickname ()).isEqualTo (mentorUser1 .getNickname ()),
295+ () -> assertThat (mentor1Response .universityName ()).isEqualTo (university .getKoreanName ()),
296+ () -> assertThat (mentor1Response .country ()).isEqualTo (university .getCountry ().getKoreanName ()),
297+ () -> assertThat (mentor1Response .channels ()).extracting (ChannelResponse ::url )
298+ .containsOnly (channel1 .getUrl ()),
299+
300+ () -> assertThat (mentor2Response .roomId ()).isEqualTo (chatRoom2 .getId ()),
301+ () -> assertThat (mentor2Response .nickname ()).isEqualTo (mentorUser2 .getNickname ()),
302+ () -> assertThat (mentor2Response .universityName ()).isEqualTo (university .getKoreanName ()),
303+ () -> assertThat (mentor2Response .country ()).isEqualTo (university .getCountry ().getKoreanName ()),
304+ () -> assertThat (mentor2Response .channels ()).extracting (ChannelResponse ::url )
305+ .containsOnly (channel2 .getUrl ())
306+ );
307+ }
308+
309+ @ Test
310+ void 다음_페이지_번호를_응답한다 () {
311+ // given
312+ SliceResponse <MatchedMentorResponse > response = mentoringQueryService .getMatchedMentors (menteeUser1 .getId (), PageRequest .of (0 , 1 ));
313+
314+ // then
315+ assertThat (response .nextPageNumber ()).isEqualTo (2 );
316+ }
317+
318+ @ Test
319+ void 다음_페이지가_없으면_페이지_없음을_의미하는_값을_응답한다 () {
320+ // given
321+ SliceResponse <MatchedMentorResponse > response = mentoringQueryService .getMatchedMentors (menteeUser1 .getId (), PageRequest .of (0 , 10 ));
322+
323+ // then
324+ assertThat (response .nextPageNumber ()).isEqualTo (NO_NEXT_PAGE_NUMBER );
325+ }
326+ }
242327}
0 commit comments