Skip to content

Commit 68b4cae

Browse files
committed
test: 멘토 마이페이지 수정 테스트 코드 작성
1 parent 8a0eaff commit 68b4cae

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.solidconnection.mentor.repository;
2+
3+
import com.example.solidconnection.mentor.domain.Channel;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.List;
7+
8+
public interface ChannelRepositoryForTest extends JpaRepository<Channel, Long> {
9+
10+
List<Channel> findAllByMentorId(long mentorId);
11+
}

src/test/java/com/example/solidconnection/mentor/service/MentorMyPageServiceTest.java

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,34 @@
22

33
import com.example.solidconnection.mentor.domain.Channel;
44
import com.example.solidconnection.mentor.domain.Mentor;
5+
import com.example.solidconnection.mentor.dto.ChannelRequest;
56
import com.example.solidconnection.mentor.dto.ChannelResponse;
67
import com.example.solidconnection.mentor.dto.MentorMyPageResponse;
8+
import com.example.solidconnection.mentor.dto.MentorMyPageUpdateRequest;
79
import com.example.solidconnection.mentor.fixture.ChannelFixture;
810
import com.example.solidconnection.mentor.fixture.MentorFixture;
11+
import com.example.solidconnection.mentor.repository.ChannelRepositoryForTest;
12+
import com.example.solidconnection.mentor.repository.MentorRepository;
913
import com.example.solidconnection.siteuser.domain.SiteUser;
1014
import com.example.solidconnection.siteuser.fixture.SiteUserFixture;
15+
import com.example.solidconnection.siteuser.service.MyPageService;
1116
import com.example.solidconnection.support.TestContainerSpringBootTest;
1217
import org.junit.jupiter.api.BeforeEach;
1318
import org.junit.jupiter.api.DisplayName;
1419
import org.junit.jupiter.api.Nested;
1520
import org.junit.jupiter.api.Test;
1621
import 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;
1829
import static org.assertj.core.api.Assertions.assertThat;
1930
import 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

Comments
 (0)