Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record PostListResponse(
ZonedDateTime createdAt,
ZonedDateTime updatedAt,
String postCategory,
String url
String postThumbnailUrl
Comment on lines 15 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 pr과 관련은 없지만 불필요한 Long타입 나중에 한 번 싹 고치는 pr 제가 올리겠습니다!

) {

public static PostListResponse from(Post post) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,35 @@ 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<PostListResponse> actualResponses = postQueryService.findPostsByCodeAndPostCategory(
BoardCode.FREE.name(),
PostCategory.전체.name()
);

// then
PostListResponse post1Response = actualResponses.stream()
.filter(p -> p.id().equals(post1.getId()))
.findFirst()
.orElseThrow();

PostListResponse post3Response = actualResponses.stream()
.filter(p -> p.id().equals(post3.getId()))
.findFirst()
.orElseThrow();

assertAll(
() -> assertThat(post1Response.postThumbnailUrl()).isEqualTo(firstImageUrl),
() -> assertThat(post3Response.postThumbnailUrl()).isNull()
);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조금 사소한 부분일수도 있는데요..!

지금의 테스트는 두가지 동작을 테스트하고 있는 것 같아요.

  1. 게시글에 여러개의 이미지가 있으면 첫번째 이미지 썸네일을 반환한다.
  2. 게시글에 이미지가 없다면, 썸네일을 null로 반환한다.

이 두가지를 각각의 테스트로 나누어 "테스트가 한가지만 검증하도록" 하는 것도 좋을 것 같습니다~
하지만 치명적인 부분은 아니라 생각해서 approve 드립니다! ☺️

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아핫 그러네요 저도 분리하는 것이 더 적합하다고 생각합니다 !!

0ee3050

}
}
Loading