Skip to content

Commit 0f7ed47

Browse files
committed
refactor(community): community 댓글 생성, 수정 requestDto @RequestPart("data") -> @RequestBody
1 parent e4ac068 commit 0f7ed47

File tree

2 files changed

+11
-42
lines changed

2 files changed

+11
-42
lines changed

src/main/java/com/somemore/community/controller/CommunityCommentCommandApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class CommunityCommentCommandApiController {
3232
public ApiResponse<Long> createCommunityComment(
3333
@CurrentUser UUID userId,
3434
@PathVariable Long boardId,
35-
@Valid @RequestPart("data") CommunityCommentCreateRequestDto requestDto) {
35+
@Valid @RequestBody CommunityCommentCreateRequestDto requestDto) {
3636

3737
return ApiResponse.ok(
3838
201,
@@ -47,7 +47,7 @@ public ApiResponse<String> updateCommunityComment(
4747
@CurrentUser UUID userId,
4848
@PathVariable Long boardId,
4949
@PathVariable Long id,
50-
@Valid @RequestPart("data") CommunityCommentUpdateRequestDto requestDto
50+
@Valid @RequestBody CommunityCommentUpdateRequestDto requestDto
5151
) {
5252
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, userId, boardId);
5353

src/test/java/com/somemore/community/controller/CommunityCommentCommandApiControllerTest.java

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import static org.mockito.ArgumentMatchers.*;
44
import static org.mockito.BDDMockito.given;
55
import static org.mockito.BDDMockito.willDoNothing;
6-
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
7-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
8-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
6+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
97
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
108
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
119
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -24,11 +22,7 @@
2422
import org.springframework.beans.factory.annotation.Autowired;
2523
import org.springframework.boot.test.mock.mockito.MockBean;
2624
import org.springframework.http.MediaType;
27-
import org.springframework.mock.web.MockHttpServletRequest;
28-
import org.springframework.mock.web.MockMultipartFile;
2925
import org.springframework.test.web.servlet.MockMvc;
30-
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
31-
import org.springframework.test.web.servlet.request.RequestPostProcessor;
3226

3327
public class CommunityCommentCommandApiControllerTest extends ControllerTestSupport {
3428

@@ -60,20 +54,13 @@ void createCommunityComment() throws Exception {
6054
.parentCommentId(null)
6155
.build();
6256

63-
MockMultipartFile requestData = new MockMultipartFile(
64-
"data",
65-
"",
66-
MediaType.APPLICATION_JSON_VALUE,
67-
objectMapper.writeValueAsBytes(requestDto)
68-
);
69-
7057
given(createCommunityCommentUseCase.createCommunityComment(any(), any(UUID.class),
7158
eq(communityBoardId))).willReturn(communityCommentId);
7259

7360
//when
74-
mockMvc.perform(multipart("/api/community-board/{boardId}/comment", communityBoardId)
75-
.file(requestData)
76-
.contentType(MULTIPART_FORM_DATA)
61+
mockMvc.perform(post("/api/community-board/{boardId}/comment", communityBoardId)
62+
.content(objectMapper.writeValueAsString(requestDto))
63+
.contentType(MediaType.APPLICATION_JSON)
7764
.header("Authorization", "Bearer access-token"))
7865

7966
//then
@@ -92,32 +79,14 @@ void updateCommunityComment_success() throws Exception {
9279
.content("감사합니다.")
9380
.build();
9481

95-
MockMultipartFile requestData = new MockMultipartFile(
96-
"data",
97-
"",
98-
MediaType.APPLICATION_JSON_VALUE,
99-
objectMapper.writeValueAsBytes(requestDto)
100-
);
101-
10282
willDoNothing().given(updateCommunityCommentUseCase)
103-
.updateCommunityComment(any(), any(),
104-
any(UUID.class), any());
105-
106-
MockMultipartHttpServletRequestBuilder builder =
107-
multipart("/api/community-board/{boardId}/comment/{id}", communityBoardId, communityCommentId);
108-
builder.with(new RequestPostProcessor() {
109-
@Override
110-
public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
111-
request.setMethod("PUT");
112-
return request;
113-
}
114-
});
83+
.updateCommunityComment(any(), any(), any(UUID.class), any());
11584

11685
//when
117-
mockMvc.perform(builder
118-
.file(requestData)
119-
.contentType(MULTIPART_FORM_DATA)
120-
.header("Authorization", "Bearer access-token"))
86+
mockMvc.perform(put("/api/community-board/{boardId}/comment/{id}", communityBoardId, communityCommentId)
87+
.content(objectMapper.writeValueAsString(requestDto))
88+
.contentType(MediaType.APPLICATION_JSON)
89+
.header("Authorization", "Bearer access-token"))
12190

12291
//then
12392
.andExpect(status().isOk())

0 commit comments

Comments
 (0)