22
33import com .example .solidconnection .mentor .domain .Channel ;
44import com .example .solidconnection .mentor .domain .Mentor ;
5+ import com .example .solidconnection .mentor .dto .ChannelRequest ;
56import com .example .solidconnection .mentor .dto .ChannelResponse ;
67import com .example .solidconnection .mentor .dto .MentorMyPageResponse ;
8+ import com .example .solidconnection .mentor .dto .MentorMyPageUpdateRequest ;
79import com .example .solidconnection .mentor .fixture .ChannelFixture ;
810import com .example .solidconnection .mentor .fixture .MentorFixture ;
11+ import com .example .solidconnection .mentor .repository .ChannelRepositoryForTest ;
12+ import com .example .solidconnection .mentor .repository .MentorRepository ;
913import com .example .solidconnection .siteuser .domain .SiteUser ;
1014import com .example .solidconnection .siteuser .fixture .SiteUserFixture ;
15+ import com .example .solidconnection .siteuser .service .MyPageService ;
1116import com .example .solidconnection .support .TestContainerSpringBootTest ;
1217import org .junit .jupiter .api .BeforeEach ;
1318import org .junit .jupiter .api .DisplayName ;
1419import org .junit .jupiter .api .Nested ;
1520import org .junit .jupiter .api .Test ;
1621import org .springframework .beans .factory .annotation .Autowired ;
22+ import org .springframework .boot .test .mock .mockito .MockBean ;
23+ import org .springframework .mock .web .MockMultipartFile ;
1724
25+ import java .util .List ;
26+
27+ import static com .example .solidconnection .mentor .domain .ChannelType .BLOG ;
28+ import static com .example .solidconnection .mentor .domain .ChannelType .INSTAGRAM ;
1829import static org .assertj .core .api .Assertions .assertThat ;
1930import static org .junit .jupiter .api .Assertions .assertAll ;
31+ import static org .mockito .BDDMockito .then ;
32+ import static org .mockito .Mockito .times ;
2033
2134@ TestContainerSpringBootTest
2235@ DisplayName ("멘토 마이페이지 서비스 테스트" )
@@ -34,9 +47,18 @@ class MentorMyPageServiceTest {
3447 @ Autowired
3548 private ChannelFixture channelFixture ;
3649
50+ @ Autowired
51+ private MentorRepository mentorRepository ;
52+
53+ @ Autowired
54+ private ChannelRepositoryForTest channelRepositoryForTest ;
55+
56+ @ MockBean
57+ private MyPageService myPageService ;
58+
3759 private SiteUser mentorUser ;
3860 private Mentor mentor ;
39- long universityId = 1L ;
61+ private long universityId = 1L ;
4062
4163 @ BeforeEach
4264 void setUp () {
@@ -65,4 +87,71 @@ class 멘토의_마이_페이지를_조회한다 {
6587 );
6688 }
6789 }
90+
91+ @ Nested
92+ class 멘토의_마이_페이지를_수정한다 {
93+
94+ @ Test
95+ void 멘토의_사용자_정보_수정은_기존_수정로직에_위임한다 () {
96+ // given
97+ String newNickname = "새로운 닉네임" ;
98+ MockMultipartFile newProfileImg = createImageFile ();
99+ MentorMyPageUpdateRequest request = new MentorMyPageUpdateRequest (newNickname , "자기소개" , "합격 팁" , List .of ());
100+
101+ // when
102+ mentorMyPageService .updateMentorMyPage (mentorUser , request , newProfileImg );
103+
104+ // then
105+ then (myPageService ).should (times (1 ))
106+ .updateMyPageInfo (mentorUser , newProfileImg , newNickname );
107+ }
108+
109+ @ Test
110+ void 멘토_정보를_수정한다 () {
111+ // given
112+ String newIntroduction = "새로운 자기소개" ;
113+ String newPassTip = "새로운 합격 팁" ;
114+ MentorMyPageUpdateRequest request = new MentorMyPageUpdateRequest ("nickname" , newIntroduction , newPassTip , List .of ());
115+
116+ // when
117+ mentorMyPageService .updateMentorMyPage (mentorUser , request , null );
118+
119+ // then
120+ Mentor updatedMentor = mentorRepository .findById (mentor .getId ()).get ();
121+ assertAll (
122+ () -> assertThat (updatedMentor .getIntroduction ()).isEqualTo (newIntroduction ),
123+ () -> assertThat (updatedMentor .getPassTip ()).isEqualTo (newPassTip )
124+ );
125+ }
126+
127+ @ Test
128+ void 채널_정보를_수정한다 () {
129+ // given
130+ List <ChannelRequest > newChannels = List .of (
131+ new ChannelRequest (BLOG , "https://blog.com" ),
132+ new ChannelRequest (INSTAGRAM , "https://instagram.com" )
133+ );
134+ MentorMyPageUpdateRequest request = new MentorMyPageUpdateRequest ("nickname" , "introduction" , "passTip" , newChannels );
135+
136+ // when
137+ mentorMyPageService .updateMentorMyPage (mentorUser , request , null );
138+ // then
139+ List <Channel > updatedChannels = channelRepositoryForTest .findAllByMentorId (mentor .getId ());
140+ assertAll (
141+ () -> assertThat (updatedChannels ).extracting (Channel ::getType )
142+ .containsExactly (BLOG , INSTAGRAM ),
143+ () -> assertThat (updatedChannels ).extracting (Channel ::getUrl )
144+ .containsExactly ("https://blog.com" , "https://instagram.com" )
145+ );
146+ }
147+ }
148+
149+ private MockMultipartFile createImageFile () {
150+ return new MockMultipartFile (
151+ "image" ,
152+ "test.jpg" ,
153+ "image/jpeg" ,
154+ "test image content" .getBytes ()
155+ );
156+ }
68157}
0 commit comments