Skip to content

Commit 7faad2e

Browse files
committed
test(community): community 게시글 페이징 테스트 추가
1 parent 755ac2d commit 7faad2e

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/test/java/com/somemore/community/service/board/CommunityBoardQueryServiceTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ void setUp() {
6565
communityBoardRepository.save(createCommunityBoard(writerId2));
6666

6767
communityId1 = communityBoard1.getId();
68+
69+
for (int i = 1; i <= 11; i++) {
70+
String title = "제목" + i;
71+
CommunityBoard communityBoard = createCommunityBoard(title, writerId1);
72+
communityBoardRepository.save(communityBoard);
73+
}
74+
75+
for (int i = 1; i <= 20; i++) {
76+
String title = "제목" + i;
77+
CommunityBoard communityBoard = createCommunityBoard(title, writerId2);
78+
communityBoardRepository.save(communityBoard);
79+
}
6880
}
6981

7082
@AfterEach
@@ -82,8 +94,9 @@ void getAllCommunityBoards() {
8294

8395
//then
8496
assertThat(dtos).isNotNull();
85-
assertThat(dtos.getTotalElements()).isEqualTo(2);
97+
assertThat(dtos.getTotalElements()).isEqualTo(33);
8698
assertThat(dtos.getSize()).isEqualTo(10);
99+
assertThat(dtos.getTotalPages()).isEqualTo(4);
87100
assertThat(dtos.getNumber()).isZero();
88101
}
89102

@@ -97,8 +110,9 @@ void getCommunityBoardsByWriter() {
97110

98111
//then
99112
assertThat(dtos).isNotNull();
100-
assertThat(dtos.getTotalElements()).isEqualTo(1);
113+
assertThat(dtos.getTotalElements()).isEqualTo(12);
101114
assertThat(dtos.getSize()).isEqualTo(10);
115+
assertThat(dtos.getTotalPages()).isEqualTo(2);
102116
assertThat(dtos.getNumber()).isZero();
103117
}
104118

src/test/java/com/somemore/community/service/comment/CommunityCommentQueryServiceTest.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CommunityCommentQueryServiceTest extends IntegrationTestSupport {
3535
@Autowired
3636
private DeleteCommunityCommentUseCase deleteCommunityCommentUseCase;
3737

38-
private Long boardId, commentId, replyId;
38+
private Long boardId, commentId, replyId, commentId2;
3939
UUID writerId;
4040

4141
@BeforeEach
@@ -53,7 +53,11 @@ void setUp() {
5353
communityCommentRepository.save(communityComment1);
5454
commentId = communityComment1.getId();
5555

56-
for (int i = 1; i <= 8; i++) {
56+
CommunityComment communityComment2 = createCommunityComment(boardId, writerId);
57+
communityCommentRepository.save(communityComment2);
58+
commentId2 = communityComment2.getId();
59+
60+
for (int i = 1; i <= 12; i++) {
5761
String content = "제목" + i;
5862
CommunityComment communityComment = createCommunityComment(content, boardId, writerId);
5963
communityCommentRepository.save(communityComment);
@@ -79,14 +83,15 @@ void getCommentsByCommunityBoardId() {
7983

8084
//then
8185
assertThat(comments).isNotNull();
82-
assertThat(comments.getTotalElements()).isEqualTo(10);
86+
assertThat(comments.getTotalElements()).isEqualTo(15);
8387
assertThat(comments.getSize()).isEqualTo(4);
84-
assertThat(comments.getNumber()).isZero();
88+
assertThat(comments.getTotalPages()).isEqualTo(4);
8589
}
8690

87-
@DisplayName("삭제된 댓글의 경우 조회할 수 없다.")
91+
@DisplayName("삭제된 대댓글의 경우 조회할 수 없다.")
8892
@Test
89-
void doesNotFind() {
93+
void doesNotFindReply() {
94+
9095
//given
9196
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, replyId, boardId);
9297

@@ -95,9 +100,24 @@ void doesNotFind() {
95100

96101
//then
97102
assertThat(comments).isNotNull();
98-
assertThat(comments.getTotalElements()).isEqualTo(9);
103+
assertThat(comments.getTotalElements()).isEqualTo(14);
104+
assertThat(comments.getSize()).isEqualTo(4);
105+
}
106+
107+
@DisplayName("대댓글이 없는 삭제된 댓글의 경우 조회할 수 없다.")
108+
@Test
109+
void doesNotFindCommennt() {
110+
111+
//given
112+
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId2, boardId);
113+
114+
//when
115+
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);
116+
117+
//then
118+
assertThat(comments).isNotNull();
119+
assertThat(comments.getTotalElements()).isEqualTo(14);
99120
assertThat(comments.getSize()).isEqualTo(4);
100-
assertThat(comments.getNumber()).isZero();
101121
}
102122

103123
@DisplayName("대댓글이 있는 댓글의 경우 삭제된 댓글로 조회할 수 있다.")
@@ -106,13 +126,13 @@ void getCommentsByCommunityBoardIdWithDeletedComment() {
106126

107127
//given
108128
deleteCommunityCommentUseCase.deleteCommunityComment(writerId, commentId, boardId);
129+
109130
//when
110131
Page<CommunityCommentResponseDto> comments = communityCommentQueryService.getCommunityCommentsByBoardId(boardId, 0);
111132

112133
//then
113134
assertThat(comments).isNotNull();
114-
assertThat(comments.getTotalElements()).isEqualTo(10);
135+
assertThat(comments.getTotalElements()).isEqualTo(15);
115136
assertThat(comments.getSize()).isEqualTo(4);
116-
assertThat(comments.getNumber()).isZero();
117137
}
118138
}

0 commit comments

Comments
 (0)