ADD delete Comment HTTP API
- Test 이름, DisplayName 오타 수정 (update api:: "articleId" -> "commentId") - 잘못된 Delete Comment 쿼리문 수정 (UPDATE COMMNET -> UPDATE COMMENT)
This commit is contained in:
@@ -21,4 +21,8 @@ public class CommentFacade {
|
||||
public void update(UpdateCommentCommand request, Long commentId, Long memberId) {
|
||||
commentProcessor.update(request.getContent(), commentId, memberId);
|
||||
}
|
||||
|
||||
public void delete(Long commentId, Long memberId) {
|
||||
commentProcessor.delete(commentId, memberId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.net.URI;
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -50,5 +51,15 @@ public final class CommentCommandApi {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("api/comments/{commentId}")
|
||||
public ResponseEntity<Void> deleteComment(
|
||||
@PathVariable Long commentId,
|
||||
@AuthenticationPrincipal Authentication authentication) {
|
||||
|
||||
commentFacade.delete(commentId, authentication.getMemberId());
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</update>
|
||||
|
||||
<update id="delete" parameterType="com.yam.app.comment.domain.Comment">
|
||||
UPDATE COMMNET
|
||||
UPDATE COMMENT
|
||||
SET status = #{status}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
@@ -4,6 +4,7 @@ public final class CommentApiUri {
|
||||
|
||||
public static final String CREATE_COMMENT = "/api/comments/create";
|
||||
public static final String UPDATE_COMMENT = "/api/comments/";
|
||||
public static final String DELETE_COMMENT = "/api/comments/";
|
||||
|
||||
private CommentApiUri() {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.yam.app.comment.presentation;
|
||||
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.CREATE_COMMENT;
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.DELETE_COMMENT;
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.UPDATE_COMMENT;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
@@ -15,6 +17,7 @@ import org.javaunit.autoparams.customization.Customization;
|
||||
import org.javaunit.autoparams.customization.SettablePropertyWriter;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -155,7 +158,7 @@ final class CommentCommandApiTest {
|
||||
|
||||
@Nested
|
||||
@DisplayName("댓글 수정 HTTP API")
|
||||
class UpdateComment {
|
||||
class UpdateCommentApi {
|
||||
|
||||
@ParameterizedTest
|
||||
@AutoSource
|
||||
@@ -207,7 +210,7 @@ final class CommentCommandApiTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@AutoSource
|
||||
@DisplayName("인증된 사용자의 요청 바디의 articleId 가 null 이라면 400에러를 반환한다.")
|
||||
@DisplayName("인증된 사용자의 요청 바디의 commentId 가 null 이라면 400에러를 반환한다.")
|
||||
void authenticated_user_request_body_articleId_is_null(String args) throws Exception {
|
||||
//Arrange
|
||||
var session = new MockHttpSession();
|
||||
@@ -261,4 +264,27 @@ final class CommentCommandApiTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("댓글 삭제 HTTP API")
|
||||
class DeleteCommentApi {
|
||||
|
||||
@Test
|
||||
@DisplayName("인증되지 않은 사용자가 요청을 보냈다면 401에러를 반환한다.")
|
||||
void unauthenticated_user_request() throws Exception {
|
||||
//Act
|
||||
final var actions = mockMvc.perform(delete(DELETE_COMMENT + "1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
|
||||
//Assert
|
||||
actions
|
||||
.andExpect(status().isUnauthorized())
|
||||
.andExpect(jsonPath("$.success").value(false))
|
||||
.andExpect(jsonPath("$.data").doesNotExist())
|
||||
.andExpect(jsonPath("$.message").value("Unauthorized request"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.yam.app.integration;
|
||||
|
||||
import static com.yam.app.account.presentation.AccountApiUri.LOGIN;
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.CREATE_COMMENT;
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.DELETE_COMMENT;
|
||||
import static com.yam.app.comment.presentation.CommentApiUri.UPDATE_COMMENT;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
@@ -13,6 +15,7 @@ import com.yam.app.comment.presentation.CreateCommentCommand;
|
||||
import com.yam.app.comment.presentation.UpdateCommentCommand;
|
||||
import org.javaunit.autoparams.AutoSource;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@@ -21,7 +24,8 @@ final class CommentIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@AutoSource
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여 성공하고 인증된 사용자가 댓글을 작성하는 시나리오 테스트")
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여 성공하고"
|
||||
+ " 인증된 사용자가 댓글을 작성하는 시나리오 테스트")
|
||||
void login_success_and_create_comment_scenarios(String args) throws Exception {
|
||||
//Arrange
|
||||
var loginCommand = new LoginAccountCommand();
|
||||
@@ -56,9 +60,9 @@ final class CommentIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@AutoSource
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여 성공하고 인증된 사용자가 댓글을 수정하는 시나리오 테스트")
|
||||
void login_success_and_update_comment_and_then_delete_it_scenarios(String args)
|
||||
throws Exception {
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여 성공하고"
|
||||
+ " 인증된 사용자가 댓글을 수정하는 시나리오 테스트")
|
||||
void login_success_and_update_comment_scenarios(String args) throws Exception {
|
||||
//Arrange
|
||||
var loginCommand = new LoginAccountCommand();
|
||||
loginCommand.setEmail("comment@gmail.com");
|
||||
@@ -89,4 +93,35 @@ final class CommentIntegrationTests extends AbstractIntegrationTests {
|
||||
.andExpect(status().isOk());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("로그인에 적절한 파라미터를 입력하여 성공하고"
|
||||
+ " 인증된 사용자가 댓글을 삭제하는 시나리오 테스트")
|
||||
void login_success_and_delete_comment_scenarios() throws Exception {
|
||||
//Arrange
|
||||
var loginCommand = new LoginAccountCommand();
|
||||
loginCommand.setEmail("comment@gmail.com");
|
||||
loginCommand.setPassword("password!");
|
||||
|
||||
var deleteCommentId = 1L;
|
||||
|
||||
//Act & Assert
|
||||
mockMvc.perform(post(LOGIN)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(loginCommand))
|
||||
)
|
||||
.andExpect(status().isOk())
|
||||
.andDo(
|
||||
result -> {
|
||||
final var actions = mockMvc.perform(delete(DELETE_COMMENT + deleteCommentId)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
);
|
||||
|
||||
actions
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user