Skip to content

Commit 0e88755

Browse files
committed
Test: 테스트 작성
1 parent b27ed2e commit 0e88755

File tree

6 files changed

+508
-10
lines changed

6 files changed

+508
-10
lines changed

src/main/java/com/back/domain/board/comment/controller/CommentLikeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ResponseEntity<RsData<CommentLikeResponse>> cancelLikeComment(
4040
CommentLikeResponse response = commentLikeService.cancelLikeComment(commentId, user.getUserId());
4141
return ResponseEntity
4242
.ok(RsData.success(
43-
"댓글 좋아요를 취소했습니다.",
43+
"댓글 좋아요가 취소되었습니다.",
4444
response
4545
));
4646
}

src/main/java/com/back/domain/board/comment/service/CommentLikeService.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public CommentLikeResponse likeComment(Long commentId, Long userId) {
5555
* 1. User 조회
5656
* 2. Comment 조회
5757
* 3. CommentLike 조회
58-
* 4. 사용자 검증
59-
* 5. CommentLike 삭제 및 likeCount 감소
58+
* 4. CommentLike 삭제 및 likeCount 감소
6059
*/
6160
public CommentLikeResponse cancelLikeComment(Long commentId, Long userId) {
6261
// User 조회
@@ -71,11 +70,6 @@ public CommentLikeResponse cancelLikeComment(Long commentId, Long userId) {
7170
CommentLike commentLike = commentLikeRepository.findByUserIdAndCommentId(userId, commentId)
7271
.orElseThrow(() -> new CustomException(ErrorCode.COMMENT_LIKE_NOT_FOUND));
7372

74-
// 사용자 검증
75-
if (!commentLike.getUser().getId().equals(userId)) {
76-
throw new CustomException(ErrorCode.COMMENT_LIKE_NO_PERMISSION);
77-
}
78-
7973
// CommentLike 삭제
8074
commentLikeRepository.delete(commentLike);
8175

src/main/java/com/back/global/exception/ErrorCode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ public enum ErrorCode {
102102
COMMENT_NO_PERMISSION(HttpStatus.FORBIDDEN, "COMMENT_002", "댓글 작성자만 수정/삭제할 수 있습니다."),
103103
COMMENT_PARENT_MISMATCH(HttpStatus.BAD_REQUEST, "COMMENT_003", "부모 댓글이 해당 게시글에 속하지 않습니다."),
104104
COMMENT_DEPTH_EXCEEDED(HttpStatus.BAD_REQUEST, "COMMENT_004", "대댓글은 한 단계까지만 작성할 수 있습니다."),
105-
COMMENT_ALREADY_LIKED(HttpStatus.BAD_REQUEST, "COMMENT_005", "이미 좋아요한 댓글입니다."),
105+
COMMENT_ALREADY_LIKED(HttpStatus.CONFLICT, "COMMENT_005", "이미 좋아요한 댓글입니다."),
106106
COMMENT_LIKE_NOT_FOUND(HttpStatus.NOT_FOUND, "COMMENT_006", "해당 댓글에 대한 좋아요 기록이 없습니다."),
107-
COMMENT_LIKE_NO_PERMISSION(HttpStatus.FORBIDDEN, "COMMENT_007", "좋아요를 등록한 본인만 취소할 수 있습니다"),
108107

109108
// ======================== 공통 에러 ========================
110109
BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON_400", "잘못된 요청입니다."),

src/main/java/com/back/global/exception/GlobalExceptionHandler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import org.springframework.http.ResponseEntity;
66
import org.springframework.security.access.AccessDeniedException;
77
import org.springframework.security.authorization.AuthorizationDeniedException;
8+
import org.springframework.web.HttpRequestMethodNotSupportedException;
89
import org.springframework.web.bind.MethodArgumentNotValidException;
910
import org.springframework.web.bind.MissingServletRequestParameterException;
1011
import org.springframework.web.bind.annotation.ExceptionHandler;
1112
import org.springframework.web.bind.annotation.ResponseStatus;
1213
import org.springframework.web.bind.annotation.RestControllerAdvice;
1314
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
15+
import org.springframework.web.servlet.NoHandlerFoundException;
1416

1517
import java.time.LocalDate;
1618

@@ -67,6 +69,20 @@ public ResponseEntity<RsData<Void>> handleMissingParam(MissingServletRequestPara
6769
.body(RsData.fail(ErrorCode.BAD_REQUEST));
6870
}
6971

72+
@ExceptionHandler(NoHandlerFoundException.class)
73+
public ResponseEntity<RsData<Void>> handleNoHandlerFoundException(NoHandlerFoundException ex) {
74+
return ResponseEntity
75+
.status(HttpStatus.BAD_REQUEST)
76+
.body(RsData.fail(ErrorCode.BAD_REQUEST));
77+
}
78+
79+
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
80+
public ResponseEntity<RsData<Void>> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex) {
81+
return ResponseEntity
82+
.status(HttpStatus.BAD_REQUEST)
83+
.body(RsData.fail(ErrorCode.BAD_REQUEST));
84+
}
85+
7086
@ExceptionHandler(SecurityException.class)
7187
public ResponseEntity<RsData<Void>> handleSecurityException(SecurityException ex) {
7288
return ResponseEntity

0 commit comments

Comments
 (0)