diff --git a/src/main/java/com/example/solidconnection/community/post/dto/PostListResponse.java b/src/main/java/com/example/solidconnection/community/post/dto/PostListResponse.java index 89fb20aab..7c4871419 100644 --- a/src/main/java/com/example/solidconnection/community/post/dto/PostListResponse.java +++ b/src/main/java/com/example/solidconnection/community/post/dto/PostListResponse.java @@ -15,7 +15,7 @@ public record PostListResponse( ZonedDateTime createdAt, ZonedDateTime updatedAt, String postCategory, - String url + String postThumbnailUrl ) { public static PostListResponse from(Post post) { diff --git a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java index 2377847d6..f5e1bb45b 100644 --- a/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java @@ -166,4 +166,44 @@ void setUp() { () -> assertThat(redisService.isKeyExists(validateKey)).isTrue() ); } + + @Test + void 게시글_목록_조회시_첫번째_이미지를_썸네일로_반환한다() { + // given + String firstImageUrl = "first-thumbnail-url"; + String secondImageUrl = "second-thumbnail-url"; + postImageFixture.게시글_이미지(firstImageUrl, post1); + postImageFixture.게시글_이미지(secondImageUrl, post1); + + // when + List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + BoardCode.FREE.name(), + PostCategory.전체.name() + ); + + // then + PostListResponse postResponse = actualResponses.stream() + .filter(p -> p.id().equals(post1.getId())) + .findFirst() + .orElseThrow(); + + assertThat(postResponse.postThumbnailUrl()).isEqualTo(firstImageUrl); + } + + @Test + void 게시글에_이미지가_없다면_썸네일로_null을_반환한다() { + // when + List actualResponses = postQueryService.findPostsByCodeAndPostCategory( + BoardCode.FREE.name(), + PostCategory.전체.name() + ); + + // then + PostListResponse postResponse = actualResponses.stream() + .filter(p -> p.id().equals(post3.getId())) + .findFirst() + .orElseThrow(); + + assertThat(postResponse.postThumbnailUrl()).isNull(); + } }