Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/backend-main' into backend-main
Browse files Browse the repository at this point in the history
  • Loading branch information
java-saeng committed Aug 17, 2023
2 parents 81a66f3 + 9d1811b commit b21af29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.emmsale.comment.domain;

import static com.emmsale.comment.exception.CommentExceptionType.NOT_CREATE_CHILD_CHILD_COMMENT;

import com.emmsale.base.BaseEntity;
import com.emmsale.comment.exception.CommentException;
import com.emmsale.event.domain.Event;
import com.emmsale.member.domain.Member;
import java.util.List;
Expand Down Expand Up @@ -69,9 +72,17 @@ public static Comment createChild(
final Member member,
final String content
) {
if (isGrandChildComment(parent)) {
throw new CommentException(NOT_CREATE_CHILD_CHILD_COMMENT);
}

return new Comment(event, parent, member, content);
}

private static boolean isGrandChildComment(final Comment parent) {
return parent.parent != null;
}

public void delete() {
isDeleted = true;
content = DELETED_COMMENT_MESSAGE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public enum CommentExceptionType implements BaseExceptionType {
NOT_EVENT_AND_MEMBER_ID_BOTH_NULL(
HttpStatus.BAD_REQUEST,
"댓글 조회할 때 행사 또는 사용자의 ID 둘 다 NULL일 수는 없습니다"
),

NOT_CREATE_CHILD_CHILD_COMMENT(
HttpStatus.BAD_REQUEST,
"대대댓글은 작성할 수 없습니다."
)

;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.emmsale.comment.domain;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import com.emmsale.comment.exception.CommentException;
import com.emmsale.comment.exception.CommentExceptionType;
import com.emmsale.event.EventFixture;
import com.emmsale.event.domain.Event;
import com.emmsale.member.MemberFixture;
Expand Down Expand Up @@ -92,4 +95,21 @@ void test_isNotDeleted(final Comment comment, final boolean result) throws Excep
//when & then
assertEquals(comment.isNotDeleted(), result);
}

@Test
@DisplayName("createChild() : 대대댓글은 작성할 경우 NOT_CREATE_CHILD_CHILD_COMMENT 발생할 수 있다.")
void test_createChild_not_create_child_child_comment() throws Exception {
//given
final Event event = EventFixture.구름톤();
final Member member = new Member(1333L, "imageUrl", "usrename");

final Comment root = Comment.createRoot(event, member, "부모내용");
final Comment child1 = Comment.createChild(event, root, member, "자식내용1");
final Comment child2 = Comment.createChild(event, root, member, "자식내용2");

//when & then
assertThatThrownBy(() -> Comment.createChild(event, child1, member, "자자식댓글1"))
.isInstanceOf(CommentException.class)
.hasMessage(CommentExceptionType.NOT_CREATE_CHILD_CHILD_COMMENT.errorMessage());
}
}

0 comments on commit b21af29

Please sign in to comment.