Skip to content

Commit 7472fc6

Browse files
committed
test: 테스트 수정
1 parent 7628f88 commit 7472fc6

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/test/java/org/devkor/apu/saerok_server/domain/community/application/CommunityQueryServiceTest.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import org.devkor.apu.saerok_server.domain.collection.core.entity.AccessLevelType;
44
import org.devkor.apu.saerok_server.domain.collection.core.entity.UserBirdCollection;
55
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityCollectionInfo;
6+
import org.devkor.apu.saerok_server.domain.community.api.dto.common.CommunityFreeBoardPostInfo;
67
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityCollectionsResponse;
78
import org.devkor.apu.saerok_server.domain.community.api.dto.response.GetCommunityMainResponse;
89
import org.devkor.apu.saerok_server.domain.community.application.dto.CommunityQueryCommand;
9-
import org.devkor.apu.saerok_server.domain.freeboard.api.dto.response.FreeBoardPostPreviewResponse;
1010
import org.devkor.apu.saerok_server.domain.community.core.repository.CommunityRepository;
11+
import org.devkor.apu.saerok_server.domain.community.mapper.CommunityWebMapper;
12+
import org.devkor.apu.saerok_server.domain.freeboard.application.dto.FreeBoardPostPreview;
1113
import org.devkor.apu.saerok_server.domain.dex.bird.core.entity.Bird;
1214
import org.devkor.apu.saerok_server.domain.dex.bird.core.entity.BirdName;
1315
import org.devkor.apu.saerok_server.domain.freeboard.application.FreeBoardPostQueryService;
@@ -37,6 +39,7 @@ class CommunityQueryServiceTest {
3739

3840
@Mock CommunityRepository communityRepository;
3941
@Mock CommunityDataAssembler dataAssembler;
42+
@Mock CommunityWebMapper communityWebMapper;
4043
@Mock FreeBoardPostQueryService freeBoardPostQueryService;
4144

4245
private static User user(Long id, String nickname) {
@@ -103,6 +106,7 @@ void setUp() {
103106
communityQueryService = new CommunityQueryService(
104107
communityRepository,
105108
dataAssembler,
109+
communityWebMapper,
106110
freeBoardPostQueryService
107111
);
108112
}
@@ -232,28 +236,38 @@ void getCommunityMain_returnsRecentFreeBoardPosts() {
232236
given(dataAssembler.toCollectionInfos(List.of(), userId))
233237
.willReturn(List.of());
234238

235-
List<FreeBoardPostPreviewResponse> freeBoardPosts = List.of(
236-
new FreeBoardPostPreviewResponse(1L, 10L, "유저A", "https://img/a.jpg", "https://img/thumb/a.webp",
239+
List<FreeBoardPostPreview> freeBoardPosts = List.of(
240+
new FreeBoardPostPreview(1L, 10L, "유저A", "https://img/a.jpg", "https://img/thumb/a.webp",
237241
"오늘 한강에서 백로를 봤어요!", LocalDateTime.of(2025, 7, 5, 15, 0), LocalDateTime.of(2025, 7, 5, 15, 0)),
238-
new FreeBoardPostPreviewResponse(2L, 11L, "유저B", "https://img/b.jpg", "https://img/thumb/b.webp",
242+
new FreeBoardPostPreview(2L, 11L, "유저B", "https://img/b.jpg", "https://img/thumb/b.webp",
239243
"참새 귀엽다", LocalDateTime.of(2025, 7, 5, 14, 30), LocalDateTime.of(2025, 7, 5, 14, 30)),
240-
new FreeBoardPostPreviewResponse(3L, 12L, "유저C", "https://img/c.jpg", "https://img/thumb/c.webp",
244+
new FreeBoardPostPreview(3L, 12L, "유저C", "https://img/c.jpg", "https://img/thumb/c.webp",
241245
"까치 발견!", LocalDateTime.of(2025, 7, 5, 14, 0), LocalDateTime.of(2025, 7, 5, 14, 0)),
242-
new FreeBoardPostPreviewResponse(4L, 13L, "유저D", "https://img/d.jpg", "https://img/thumb/d.webp",
246+
new FreeBoardPostPreview(4L, 13L, "유저D", "https://img/d.jpg", "https://img/thumb/d.webp",
243247
"비둘기가 많네요", LocalDateTime.of(2025, 7, 5, 13, 30), LocalDateTime.of(2025, 7, 5, 13, 30)),
244-
new FreeBoardPostPreviewResponse(5L, 14L, "유저E", "https://img/e.jpg", "https://img/thumb/e.webp",
248+
new FreeBoardPostPreview(5L, 14L, "유저E", "https://img/e.jpg", "https://img/thumb/e.webp",
245249
"딱따구리 소리가 들려요", LocalDateTime.of(2025, 7, 5, 13, 0), LocalDateTime.of(2025, 7, 5, 13, 0))
246250
);
247251
given(freeBoardPostQueryService.getRecentPostsForMain(5))
248252
.willReturn(freeBoardPosts);
249253

254+
for (FreeBoardPostPreview post : freeBoardPosts) {
255+
given(communityWebMapper.toCommunityFreeBoardPostInfo(post))
256+
.willReturn(new CommunityFreeBoardPostInfo(
257+
post.postId(), post.userId(), post.nickname(),
258+
post.profileImageUrl(), post.thumbnailProfileImageUrl(),
259+
post.content(), post.createdAt(), post.updatedAt()
260+
));
261+
}
262+
250263
// When
251264
GetCommunityMainResponse response = communityQueryService.getCommunityMain(userId);
252265

253266
// Then
254267
assertThat(response.recentFreeBoardPosts()).hasSize(5);
255268
assertThat(response.recentFreeBoardPosts().get(0).postId()).isEqualTo(1L);
256269
assertThat(response.recentFreeBoardPosts().get(4).postId()).isEqualTo(5L);
270+
assertThat(response.recentFreeBoardPosts().get(0)).isInstanceOf(CommunityFreeBoardPostInfo.class);
257271
then(freeBoardPostQueryService).should().getRecentPostsForMain(5);
258272
}
259273
}

0 commit comments

Comments
 (0)