Skip to content

Commit

Permalink
Comment에서 이미지 의존관계 제거 및 테스트 리팩토링 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho authored Feb 1, 2024
1 parent 2e5918d commit e250874
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.spaceclub.global.Authenticated;
import com.spaceclub.global.dto.PageResponse;
import com.spaceclub.global.jwt.vo.JwtUser;
import com.spaceclub.global.s3.S3ImageUploader;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -35,7 +34,6 @@
public class CommentController {

private final CommentService commentService;
private final S3ImageUploader s3ImageUploader;

@GetMapping("/{postId}/comments")
public PageResponse<CommentResponse, CommentInfo> getCommentsByPaging(
Expand All @@ -44,7 +42,7 @@ public PageResponse<CommentResponse, CommentInfo> getCommentsByPaging(
) {
Page<CommentInfo> commentPages = commentService.getComments(postId, pageable);
List<CommentResponse> comments = commentPages.getContent().stream()
.map(comment -> CommentResponse.of(comment, s3ImageUploader.getBucketUrl()))
.map(CommentResponse::of)
.toList();

return new PageResponse<>(comments, commentPages);
Expand All @@ -56,7 +54,7 @@ public CommentResponse getSingleComment(
) {
CommentInfo commentInfo = commentService.getComment(commentId);

return CommentResponse.of(commentInfo, s3ImageUploader.getBucketUrl());
return CommentResponse.of(commentInfo);
}

@PostMapping("/{postId}/comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record CommentResponse(
boolean isPrivate
) {

public static CommentResponse of(CommentInfo commentInfo, String bucketUrl) {
public static CommentResponse of(CommentInfo commentInfo) {
return new CommentResponse(
commentInfo.commentId(),
commentInfo.content(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.spaceclub.global.config.WebConfig;
import com.spaceclub.global.interceptor.AuthenticationInterceptor;
import com.spaceclub.global.interceptor.AuthorizationInterceptor;
import com.spaceclub.global.s3.S3ImageUploader;
import com.spaceclub.user.service.vo.UserProfile;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -82,9 +81,6 @@ class CommentControllerTest {
@MockBean
private CommentService commentService;

@MockBean
private S3ImageUploader s3ImageUploader;

@MockBean
private UserArgumentResolver userArgumentResolver;

Expand Down Expand Up @@ -193,9 +189,6 @@ class CommentControllerTest {
UserProfile userProfile = new UserProfile("authorName", "authorPhoneNumber", "authorEmail", "authorImageUrl");
given(commentService.getComment(any(Long.class))).willReturn(CommentInfo.of(comment, userProfile));

String bucketUrl = "spaceclub.site/";
given(s3ImageUploader.getBucketUrl()).willReturn(bucketUrl);

mockMvc.perform(get("/api/v1/boards/posts/comments/{commentId}", commentId)
.header(AUTHORIZATION, "access token")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class PostControllerTest {
UserProfile userProfile = new UserProfile("authorName", "authorPhoneNumber", "authorEmail", "authorImageUrl");
List<PostInfo> postInfos = posts.stream().map(post -> PostInfo.of(post, userProfile)).toList();
Page<PostInfo> postPages = new PageImpl<>(postInfos);

final String bucketUrl = "spaceclub.site/";
given(imageUploader.getBucketUrl()).willReturn(bucketUrl);
given(postService.getClubBoardPostsByPaging(any(), any())).willReturn(postPages);
Long clubId = 1L;

Expand All @@ -143,6 +146,11 @@ class PostControllerTest {
.andExpect(jsonPath("$.data.size()").value(posts.size()))
.andExpect(jsonPath("$.data[0].createdDate").value("2024-01-01T00:00:00"))
.andExpect(jsonPath("$.data[0].lastModifiedDate").value("2024-01-01T00:00:00"))
.andExpect(jsonPath("$.data[0].postImageUrl").value(bucketUrl + posts.get(0).getPostImageUrl()))
.andExpect(jsonPath("$.data[0].authorImageUrl").value(userProfile.profileImageUrl()))
.andExpect(jsonPath("$.data[0].author").value(userProfile.username()))
.andExpect(jsonPath("$.data[1].postImageUrl").doesNotExist())
.andExpect(jsonPath("$.data[2].postImageUrl").value(bucketUrl + posts.get(2).getPostImageUrl()))
.andExpect(jsonPath("$.pageData.first").value(true))
.andExpect(jsonPath("$.pageData.last").value(true))
.andExpect(jsonPath("$.pageData.pageNumber").value(0))
Expand All @@ -165,7 +173,6 @@ class PostControllerTest {
parameterWithName("sort").optional().description("정렬 방법(ex. id,desc), default id,desc")
),
responseFields(

fieldWithPath("data").type(ARRAY).description("페이지 내 게시글 정보"),
fieldWithPath("data[].postId").type(NUMBER).description("게시글 아이디"),
fieldWithPath("data[].title").type(STRING).description("게시글 제목"),
Expand Down

0 comments on commit e250874

Please sign in to comment.