Skip to content

Commit d0e0072

Browse files
committed
test: Post 응답에 유저 좋아요, 스크랩 여부 포함 테스트
1 parent 368b800 commit d0e0072

File tree

2 files changed

+80
-31
lines changed

2 files changed

+80
-31
lines changed

src/test/java/com/daramg/server/post/application/PostQueryServiceTest.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.daramg.server.post.domain.vo.PostCreateVo;
1313
import com.daramg.server.post.dto.PostDetailResponse;
1414
import com.daramg.server.post.dto.PostResponseDto;
15+
import com.daramg.server.post.domain.PostLike;
16+
import com.daramg.server.post.repository.PostLikeRepository;
1517
import com.daramg.server.post.repository.PostRepository;
1618
import com.daramg.server.post.repository.PostScrapRepository;
1719
import com.daramg.server.testsupport.support.ServiceTestSupport;
@@ -48,6 +50,9 @@ public class PostQueryServiceTest extends ServiceTestSupport {
4850
@Autowired
4951
private PostScrapRepository postScrapRepository;
5052

53+
@Autowired
54+
private PostLikeRepository postLikeRepository;
55+
5156
private User user;
5257
private User otherUser;
5358
private List<FreePost> freePosts;
@@ -116,7 +121,7 @@ void getAllPublishedFreePosts_ReturnsOnlyPublishedPosts() {
116121
PageRequestDto pageRequest = new PageRequestDto(null, 100); // 모든 포스트 조회
117122

118123
// when
119-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
124+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
120125

121126
// then
122127
// PUBLISHED 포스트 25개만 반환되어야 함 (DRAFT 2개는 제외)
@@ -137,7 +142,7 @@ void getAllFreePosts_WithSize20AndNullCursor_Returns20Posts() {
137142
PageRequestDto pageRequest = new PageRequestDto(null, 20);
138143

139144
// when
140-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
145+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
141146

142147
// then
143148
assertThat(response.getContent()).hasSize(20);
@@ -154,12 +159,12 @@ void getAllFreePosts_WithSize20AndNullCursor_Returns20Posts() {
154159
void getAllFreePosts_WithNullSizeAndValidCursor_Returns10Posts() {
155160
// given
156161
PageRequestDto firstRequest = new PageRequestDto(null, 10);
157-
PageResponseDto<PostResponseDto> firstResponse = postQueryService.getAllPublishedFreePosts(firstRequest);
162+
PageResponseDto<PostResponseDto> firstResponse = postQueryService.getAllPublishedFreePosts(firstRequest, null);
158163
String nextCursor = firstResponse.getNextCursor();
159164

160165
// when - size가 null이고 cursor가 있는 두 번째 요청
161166
PageRequestDto secondRequest = new PageRequestDto(nextCursor, null);
162-
PageResponseDto<PostResponseDto> secondResponse = postQueryService.getAllPublishedFreePosts(secondRequest);
167+
PageResponseDto<PostResponseDto> secondResponse = postQueryService.getAllPublishedFreePosts(secondRequest, null);
163168

164169
// then
165170
assertThat(secondResponse.getContent()).hasSize(10); // default size 10이 적용됨
@@ -180,7 +185,7 @@ void getAllFreePosts_WithNegativeSize_AppliesDefaultSize10() {
180185
PageRequestDto pageRequest = new PageRequestDto(null, -5);
181186

182187
// when
183-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
188+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
184189

185190
// then
186191
assertThat(response.getContent()).hasSize(10); // 음수는 default 10으로 처리됨
@@ -194,7 +199,7 @@ void getAllFreePosts_WithZeroSize_AppliesDefaultSize10() {
194199
PageRequestDto pageRequest = new PageRequestDto(null, 0);
195200

196201
// when
197-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
202+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
198203

199204
// then
200205
assertThat(response.getContent()).hasSize(10); // 0은 default 10으로 처리됨
@@ -208,7 +213,7 @@ void getAllFreePosts_WithSizeLargerThanTotal_ReturnsAllPosts() {
208213
PageRequestDto pageRequest = new PageRequestDto(null, 100); // 25개보다 큰 값
209214

210215
// when
211-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
216+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
212217

213218
// then
214219
assertThat(response.getContent()).hasSize(25); // 모든 포스트 반환
@@ -224,7 +229,7 @@ void getAllFreePosts_WithInvalidCursor_ThrowsBusinessException() {
224229
PageRequestDto pageRequest = new PageRequestDto(invalidCursor, 10);
225230

226231
// when & then
227-
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest))
232+
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest, null))
228233
.isInstanceOf(BusinessException.class)
229234
.hasMessage("유효하지 않은 커서 포맷입니다.");
230235
}
@@ -237,7 +242,7 @@ void getAllFreePosts_WithMalformedBase64Cursor_ThrowsBusinessException() {
237242
PageRequestDto pageRequest = new PageRequestDto(malformedCursor, 10);
238243

239244
// when & then
240-
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest))
245+
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest, null))
241246
.isInstanceOf(BusinessException.class)
242247
.hasMessage("유효하지 않은 커서 포맷입니다.");
243248
}
@@ -251,7 +256,7 @@ void getAllFreePosts_WithInvalidCursorFormat_ThrowsBusinessException() {
251256
PageRequestDto pageRequest = new PageRequestDto(invalidFormatCursor, 10);
252257

253258
// when & then
254-
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest))
259+
assertThatThrownBy(() -> postQueryService.getAllPublishedFreePosts(pageRequest, null))
255260
.isInstanceOf(BusinessException.class)
256261
.hasMessage("유효하지 않은 커서 포맷입니다.");
257262
}
@@ -266,7 +271,7 @@ void getAllFreePosts_WithNonExistentCursor_ReturnsEmptyList() {
266271
PageRequestDto pageRequest = new PageRequestDto(validFormatCursor, 10);
267272

268273
// when
269-
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest);
274+
PageResponseDto<PostResponseDto> response = postQueryService.getAllPublishedFreePosts(pageRequest, null);
270275

271276
// then
272277
assertThat(response.getContent()).isEmpty();
@@ -637,7 +642,7 @@ void getPostById_ReturnsPostDetails() {
637642
Long postId = savedPost.getId();
638643

639644
// when
640-
PostDetailResponse response = postQueryService.getPostById(postId);
645+
PostDetailResponse response = postQueryService.getPostById(postId, null);
641646

642647
// then
643648
assertThat(response.id()).isEqualTo(postId);
@@ -656,6 +661,8 @@ void getPostById_ReturnsPostDetails() {
656661
assertThat(response.type()).isEqualTo(com.daramg.server.post.domain.PostType.FREE);
657662
assertThat(response.primaryComposer()).isNull();
658663
assertThat(response.additionalComposers()).isNull();
664+
assertThat(response.isLiked()).isNull(); // 비로그인 유저는 null
665+
assertThat(response.isScrapped()).isNull(); // 비로그인 유저는 null
659666
}
660667

661668
@Test
@@ -665,7 +672,7 @@ void getPostById_WithNonExistentId_ThrowsNotFoundException() {
665672
Long nonExistentPostId = 999L;
666673

667674
// when & then
668-
assertThatThrownBy(() -> postQueryService.getPostById(nonExistentPostId))
675+
assertThatThrownBy(() -> postQueryService.getPostById(nonExistentPostId, null))
669676
.isInstanceOf(NotFoundException.class)
670677
.hasMessageContaining("존재하지 않는 Post입니다");
671678
}
@@ -678,7 +685,7 @@ void getPostById_IncludesAllPostFields() {
678685
Long postId = savedPost.getId();
679686

680687
// when
681-
PostDetailResponse response = postQueryService.getPostById(postId);
688+
PostDetailResponse response = postQueryService.getPostById(postId, null);
682689

683690
// then
684691
assertThat(response.id()).isNotNull();
@@ -692,6 +699,8 @@ void getPostById_IncludesAllPostFields() {
692699
assertThat(response.updatedAt()).isNotNull();
693700
assertThat(response.writerNickname()).isNotNull();
694701
assertThat(response.type()).isNotNull();
702+
assertThat(response.isLiked()).isNull();
703+
assertThat(response.isScrapped()).isNull();
695704
}
696705
}
697706
}

0 commit comments

Comments
 (0)