Skip to content

Commit ef53de8

Browse files
committed
test(review): 이미지 관련 로직 제거 테스트
1 parent 6be4576 commit ef53de8

File tree

9 files changed

+45
-165
lines changed

9 files changed

+45
-165
lines changed

src/test/java/com/somemore/domains/review/controller/ReviewCommandApiControllerTest.java

Lines changed: 19 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
package com.somemore.domains.review.controller;
22

33
import static org.mockito.ArgumentMatchers.any;
4-
import static org.mockito.ArgumentMatchers.anyString;
54
import static org.mockito.BDDMockito.given;
65
import static org.mockito.BDDMockito.willDoNothing;
76
import static org.springframework.http.MediaType.APPLICATION_JSON;
8-
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
97
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
10-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
8+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
119
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
1210
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
1311
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
1412

15-
import com.fasterxml.jackson.core.JsonProcessingException;
1613
import com.somemore.domains.review.dto.request.ReviewCreateRequestDto;
1714
import com.somemore.domains.review.dto.request.ReviewUpdateRequestDto;
1815
import com.somemore.domains.review.usecase.CreateReviewUseCase;
1916
import com.somemore.domains.review.usecase.DeleteReviewUseCase;
2017
import com.somemore.domains.review.usecase.UpdateReviewUseCase;
21-
import com.somemore.global.imageupload.usecase.ImageUploadUseCase;
2218
import com.somemore.support.ControllerTestSupport;
2319
import com.somemore.support.annotation.MockUser;
2420
import java.util.UUID;
2521
import org.junit.jupiter.api.DisplayName;
2622
import org.junit.jupiter.api.Test;
2723
import org.springframework.boot.test.mock.mockito.MockBean;
28-
import org.springframework.http.MediaType;
29-
import org.springframework.mock.web.MockMultipartFile;
30-
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
3124

3225
class ReviewCommandApiControllerTest extends ControllerTestSupport {
3326

34-
@MockBean
35-
private ImageUploadUseCase imageUploadUseCase;
36-
3727
@MockBean
3828
private CreateReviewUseCase createReviewUseCase;
3929

@@ -54,27 +44,17 @@ void createReview() throws Exception {
5444
.content("리뷰 내용")
5545
.build();
5646

57-
MockMultipartFile imageFile = new MockMultipartFile(
58-
"img_file",
59-
"test-image.jpg",
60-
MediaType.IMAGE_JPEG_VALUE,
61-
"test image content".getBytes()
62-
);
47+
String requestData = objectMapper.writeValueAsString(requestDto);
6348

64-
MockMultipartFile requestData = getRequestData(requestDto);
65-
66-
String imgUrl = "https://example.com/image/test-image.jpg";
6749
Long reviewId = 1L;
6850

69-
given(imageUploadUseCase.uploadImage(any())).willReturn(imgUrl);
70-
given(createReviewUseCase.createReview(any(), any(UUID.class),
71-
anyString())).willReturn(reviewId);
51+
given(createReviewUseCase.createReview(any(), any(UUID.class)))
52+
.willReturn(reviewId);
7253

7354
// when
74-
mockMvc.perform(multipart("/api/review")
75-
.file(requestData)
76-
.file(imageFile)
77-
.contentType(MULTIPART_FORM_DATA)
55+
mockMvc.perform(post("/api/review")
56+
.content(requestData)
57+
.contentType(APPLICATION_JSON)
7858
.header("Authorization", "Bearer access-token"))
7959
// then
8060
.andExpect(status().isOk())
@@ -93,14 +73,12 @@ void createReviewValidateTestRecruitBoardId() throws Exception {
9373
.content("리뷰 내용")
9474
.build();
9575

96-
MockMultipartFile requestData = getRequestData(requestDto);
97-
98-
given(imageUploadUseCase.uploadImage(any())).willReturn("");
76+
String requestData = objectMapper.writeValueAsString(requestDto);
9977

10078
// when
101-
mockMvc.perform(multipart("/api/review")
102-
.file(requestData)
103-
.contentType(MULTIPART_FORM_DATA)
79+
mockMvc.perform(post("/api/review")
80+
.content(requestData)
81+
.contentType(APPLICATION_JSON)
10482
.header("Authorization", "Bearer access-token"))
10583
// then
10684
.andExpect(status().isBadRequest())
@@ -119,14 +97,12 @@ void createReviewValidateTestTitle() throws Exception {
11997
.content("리뷰 내용")
12098
.build();
12199

122-
MockMultipartFile requestData = getRequestData(requestDto);
123-
124-
given(imageUploadUseCase.uploadImage(any())).willReturn("");
100+
String requestData = objectMapper.writeValueAsString(requestDto);
125101

126102
// when
127-
mockMvc.perform(multipart("/api/review")
128-
.file(requestData)
129-
.contentType(MULTIPART_FORM_DATA)
103+
mockMvc.perform(post("/api/review")
104+
.content(requestData)
105+
.contentType(APPLICATION_JSON)
130106
.header("Authorization", "Bearer access-token"))
131107
// then
132108
.andExpect(status().isBadRequest())
@@ -145,14 +121,12 @@ void createReviewValidateTestContent() throws Exception {
145121
.title("리뷰 제목")
146122
.build();
147123

148-
MockMultipartFile requestData = getRequestData(requestDto);
149-
150-
given(imageUploadUseCase.uploadImage(any())).willReturn("");
124+
String requestData = objectMapper.writeValueAsString(requestDto);
151125

152126
// when
153-
mockMvc.perform(multipart("/api/review")
154-
.file(requestData)
155-
.contentType(MULTIPART_FORM_DATA)
127+
mockMvc.perform(post("/api/review")
128+
.content(requestData)
129+
.contentType(APPLICATION_JSON)
156130
.header("Authorization", "Bearer access-token"))
157131
// then
158132
.andExpect(status().isBadRequest())
@@ -235,38 +209,6 @@ void updateReviewValidateContent() throws Exception {
235209
.andExpect(jsonPath("$.detail").value("리뷰 내용은 필수 값입니다."));
236210
}
237211

238-
@DisplayName("리뷰 이미지 수정 성공")
239-
@Test
240-
@MockUser
241-
void updateReviewImage() throws Exception {
242-
// given
243-
Long reviewId = 1L;
244-
245-
MockMultipartFile imageFile = new MockMultipartFile(
246-
"img_file",
247-
"test-image.jpg",
248-
MediaType.IMAGE_JPEG_VALUE,
249-
"test image content".getBytes()
250-
);
251-
252-
String imgUrl = "https://example.com/image/test-image.jpg";
253-
254-
given(imageUploadUseCase.uploadImage(any())).willReturn(imgUrl);
255-
256-
willDoNothing().given(updateReviewUseCase)
257-
.updateReviewImageUrl(any(), any(UUID.class), anyString());
258-
259-
// when
260-
mockMvc.perform(createMultipartPutRequest("/api/review/{id}", reviewId)
261-
.file(imageFile)
262-
.contentType(MULTIPART_FORM_DATA)
263-
.header("Authorization", "Bearer access-token"))
264-
// then
265-
.andExpect(status().isOk())
266-
.andExpect(jsonPath("$.code").value(200))
267-
.andExpect(jsonPath("$.message").value("리뷰 이미지 수정 성공"));
268-
}
269-
270212
@DisplayName("리뷰 삭제 성공 테스트")
271213
@Test
272214
@MockUser
@@ -286,23 +228,4 @@ void deleteReview() throws Exception {
286228
.andExpect(jsonPath("$.message").value("리뷰 삭제 성공"));
287229
}
288230

289-
private MockMultipartFile getRequestData(ReviewCreateRequestDto requestDto)
290-
throws JsonProcessingException {
291-
return new MockMultipartFile(
292-
"data",
293-
"",
294-
MediaType.APPLICATION_JSON_VALUE,
295-
objectMapper.writeValueAsBytes(requestDto)
296-
);
297-
}
298-
299-
private MockMultipartHttpServletRequestBuilder createMultipartPutRequest(String url, Long id) {
300-
MockMultipartHttpServletRequestBuilder builder = multipart(url, id);
301-
builder.with(request -> {
302-
request.setMethod("PUT");
303-
return request;
304-
});
305-
return builder;
306-
}
307-
308231
}

src/test/java/com/somemore/domains/review/domain/ReviewTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.somemore.domains.review.domain;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import com.somemore.domains.review.dto.request.ReviewUpdateRequestDto;
6+
import java.util.UUID;
47
import org.junit.jupiter.api.BeforeEach;
58
import org.junit.jupiter.api.DisplayName;
69
import org.junit.jupiter.api.Test;
710

8-
import java.util.UUID;
9-
10-
import static org.assertj.core.api.Assertions.assertThat;
11-
12-
1311
class ReviewTest {
1412

1513
private UUID volunteerId;
@@ -50,26 +48,12 @@ void updateWith() {
5048
assertThat(review.getContent()).isEqualTo(dto.content());
5149
}
5250

53-
@DisplayName("이미지 링크를 업데이트 할 수 있다.")
54-
@Test
55-
void updateWithImgUrl() {
56-
// given
57-
String newImgUrl = "newLink";
58-
59-
// when
60-
review.updateWith(newImgUrl);
61-
62-
// then
63-
assertThat(review.getImgUrl()).isEqualTo(newImgUrl);
64-
}
65-
6651
private Review createReview(Long applyId, UUID volunteerId) {
6752
return Review.builder()
6853
.volunteerApplyId(applyId)
6954
.volunteerId(volunteerId)
7055
.title("제목제목")
7156
.content("내용내용")
72-
.imgUrl("이미지링크")
7357
.build();
7458
}
7559
}

src/test/java/com/somemore/domains/review/repository/ReviewRepositoryImplTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ private Review createReview(Long applyId, UUID volunteerId, String title) {
246246
.volunteerId(volunteerId)
247247
.title(title)
248248
.content("내용내용")
249-
.imgUrl("이미지링크")
250249
.build();
251250
}
252251

src/test/java/com/somemore/domains/review/service/CreateReviewServiceTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.somemore.domains.review.service;
22

3+
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED;
4+
import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS;
5+
import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED;
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
8+
39
import com.somemore.domains.review.domain.Review;
410
import com.somemore.domains.review.dto.request.ReviewCreateRequestDto;
511
import com.somemore.domains.review.repository.ReviewRepository;
@@ -8,20 +14,13 @@
814
import com.somemore.global.exception.BadRequestException;
915
import com.somemore.global.exception.DuplicateException;
1016
import com.somemore.support.IntegrationTestSupport;
17+
import java.util.Optional;
18+
import java.util.UUID;
1119
import org.junit.jupiter.api.DisplayName;
1220
import org.junit.jupiter.api.Test;
1321
import org.springframework.beans.factory.annotation.Autowired;
1422
import org.springframework.transaction.annotation.Transactional;
1523

16-
import java.util.Optional;
17-
import java.util.UUID;
18-
19-
import static com.somemore.domains.volunteerapply.domain.ApplyStatus.APPROVED;
20-
import static com.somemore.global.exception.ExceptionMessage.REVIEW_ALREADY_EXISTS;
21-
import static com.somemore.global.exception.ExceptionMessage.REVIEW_RESTRICTED_TO_ATTENDED;
22-
import static org.assertj.core.api.Assertions.assertThat;
23-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
24-
2524
@Transactional
2625
class CreateReviewServiceTest extends IntegrationTestSupport {
2726

@@ -55,7 +54,7 @@ void createReview() {
5554
.build();
5655

5756
// when
58-
Long reviewId = createReviewService.createReview(requestDto, volunteerId, "");
57+
Long reviewId = createReviewService.createReview(requestDto, volunteerId);
5958

6059
// then
6160
Optional<Review> findReview = reviewRepository.findById(reviewId);
@@ -82,7 +81,6 @@ void createReviewWhenExistsReview() {
8281
.volunteerId(volunteerId)
8382
.title("리뷰 제목")
8483
.content("리뷰 내용")
85-
.imgUrl("")
8684
.build();
8785
reviewRepository.save(review);
8886

@@ -95,7 +93,7 @@ void createReviewWhenExistsReview() {
9593
// when
9694
// then
9795
assertThatThrownBy(
98-
() -> createReviewService.createReview(requestDto, volunteerId, ""))
96+
() -> createReviewService.createReview(requestDto, volunteerId))
9997
.isInstanceOf(DuplicateException.class)
10098
.hasMessage(REVIEW_ALREADY_EXISTS.getMessage());
10199
}
@@ -124,7 +122,7 @@ void createReviewWhenNotCompleted() {
124122
// when
125123
// then
126124
assertThatThrownBy(
127-
() -> createReviewService.createReview(requestDto, volunteerId, ""))
125+
() -> createReviewService.createReview(requestDto, volunteerId))
128126
.isInstanceOf(BadRequestException.class)
129127
.hasMessage(REVIEW_RESTRICTED_TO_ATTENDED.getMessage());
130128
}

src/test/java/com/somemore/domains/review/service/DeleteReviewServiceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private Review createReview(UUID volunteerId, String title, String content, Stri
4747
.volunteerId(volunteerId)
4848
.title(title)
4949
.content(content)
50-
.imgUrl(imgUrl)
5150
.build();
5251
}
5352
}

src/test/java/com/somemore/domains/review/service/ReviewQueryServiceTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ void getDetailById() {
121121
assertThat(findOne).extracting("volunteerId").isEqualTo(review.getVolunteerId());
122122
assertThat(findOne).extracting("title").isEqualTo(review.getTitle());
123123
assertThat(findOne).extracting("content").isEqualTo(review.getContent());
124-
assertThat(findOne).extracting("imgUrl").isEqualTo(review.getImgUrl());
125124
}
126125

127126

@@ -230,7 +229,6 @@ private Review createReview(Long applyId, UUID volunteerId) {
230229
.volunteerId(volunteerId)
231230
.title("리뷰 제목")
232231
.content("리뷰 내용")
233-
.imgUrl("")
234232
.build();
235233
}
236234

@@ -241,7 +239,6 @@ private Review createReview(Long applyId, UUID volunteerId, String title, String
241239
.volunteerId(volunteerId)
242240
.title(title)
243241
.content(content)
244-
.imgUrl(imgUrl)
245242
.build();
246243
}
247244

src/test/java/com/somemore/domains/review/service/UpdateReviewServiceTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,12 @@ void updateReview() {
5151
assertThat(updateReview.getContent()).isEqualTo(dto.content());
5252
}
5353

54-
@DisplayName("리뷰 이미지 링크를 업데이트 할 수 있다.")
55-
@Test
56-
void updateReviewImageUrl() {
57-
// given
58-
Long id = review.getId();
59-
String newImgUrl = "newLink.co.kr";
60-
61-
// when
62-
updateReviewService.updateReviewImageUrl(id, volunteerId, newImgUrl);
63-
64-
// then
65-
Review updateReview = reviewRepository.findById(id).orElseThrow();
66-
assertThat(updateReview.getImgUrl()).isEqualTo(newImgUrl);
67-
}
68-
6954
private Review createReview(Long applyId, UUID volunteerId) {
7055
return Review.builder()
7156
.volunteerApplyId(applyId)
7257
.volunteerId(volunteerId)
7358
.title("제목제목")
7459
.content("내용내용")
75-
.imgUrl("이미지링크")
7660
.build();
7761
}
7862
}

0 commit comments

Comments
 (0)