diff --git a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java index 016df9fd..865aee06 100644 --- a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java +++ b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java @@ -78,17 +78,14 @@ private List getUploadedImageUrls(List imageRequests) { return imageUrls; } - private List assignPostToImages(Post post, List imageUrls) { - final List images = new ArrayList<>(); + private void assignPostToImages(Post post, List imageUrls) { for (String imageUrl : imageUrls) { final Image image = Image.builder() .url(imageUrl) .build(); image.assignPost(post); imageRepository.save(image); - images.add(image); } - return images; } @Transactional @@ -108,7 +105,7 @@ public List findByVaccineType(VaccinationType vaccinationType, Opt } public List findByVaccineType(VaccinationType vaccinationType, int offset, int size, Sort sort, Optional optionalUser) { - List posts = postRepository.findByVaccineType(vaccinationType, offset, size, Sort.toOrderSpecifier(sort)); + List posts = postRepository.findByVaccineType(vaccinationType, offset, size, sort.getSort()); return PostResponse.toList(posts, optionalUser.orElse(null)); } @@ -146,8 +143,7 @@ public void delete(Long id, Optional optionalUser) { User user = optionalUser.get(); Post post = findPostByPostId(id); post.validateAuthor(user); - deleteImagesFromAwsS3(post.getS3PathsOfAllImages()); - imageRepository.deleteAll(post.getAllImagesAsList()); + deleteAllImagesInPost(post); postRepository.deleteById(id); } diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java index b0583bd7..c490fac8 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java @@ -168,7 +168,7 @@ void deleteComment() { Post foundPost = postRepository.findById(this.post.getId()).get(); //then assertThat(foundComment).isEmpty(); - assertThat(foundPost.getCommentsAsList()).extracting("id").doesNotContain(commentResponse.getId()); + assertThat(foundPost.getCommentsAsList()).isEmpty(); } @DisplayName("댓글 삭제 - 실패 - 댓글을 찾을 수 없음") diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java index 6e452b4e..f6568e64 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java @@ -194,7 +194,7 @@ void findByVaccineTypeNextPageAll() { List postResponses = postService.findByVaccineType(VaccinationType.ALL, 1, 1, Sort.CREATED_AT_DESC, optionalUser); //then assertThat(postResponses).size().isEqualTo(1); - assertThat(postResponses).extracting("content").containsExactlyElementsOf(Arrays.asList("Test 1")); + assertThat(postResponses).extracting("content").containsExactlyElementsOf(Collections.singletonList("Test 1")); assertThat(postResponses).extracting("vaccinationType").filteredOn(vaccinationType -> vaccinationType instanceof VaccinationType); } diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java index 24132ae6..845bcc76 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java @@ -354,8 +354,9 @@ void createWithImages() { assertThat(postResponse.getImages()).containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL); assertThat(foundPost).isNotNull(); + assertThat(foundPost.hasImages()).isTrue(); assertThat(foundPost.getUser()).isNotNull(); - assertThat(foundPost.getImages().getImages()) + assertThat(foundPost.getAllImagesAsList()) .extracting("url").containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL); verify(awsS3Uploader, times(3)).upload(any(String.class), any(File.class)); @@ -439,7 +440,7 @@ void updateWithImages() { .orElseThrow(() -> new NotFoundException("게시글을 찾을 수 없음.")); //then assertThat(updatedPost.getContent()).isEqualTo(updateRequest.getContent()); - assertThat(updatedPost.getImages().getImages()) + assertThat(updatedPost.getAllImagesAsList()) .extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL); assertThat(imageRepository.findAll()).extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL); verify(awsS3Uploader, times(3)).delete(any(String.class), any(String.class)); diff --git a/backend/build.gradle b/backend/build.gradle index 293a749b..b92e8e4e 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -84,6 +84,7 @@ subprojects { '**/Sort*', '**/Filter*', '**/ImageType*', + '**/JpaConfiguration*', // domain-cvi-oauth-service '**/KakaoProfile*', '**/NaverProfile*', @@ -109,7 +110,7 @@ subprojects { // domain-cvi-publicdata-parser "**/Parser.java, " + // domain-cvi - "**/Sort.java, **/Filter.java, **/ImageType.java, " + + "**/Sort.java, **/Filter.java, **/ImageType.java, **/JpaConfiguration.java, " + // domain-cvi-oauth-service "**/KakaoProfile.java, **/NaverProfile.java, **/UserInformation.java, **/AuthRequest.java, **/OAuthConfig.java" } diff --git a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java deleted file mode 100644 index 67ce5ae6..00000000 --- a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.cvi.dto; - -import com.cvi.dto.profile.SocialProfile; -import lombok.Getter; - -import javax.validation.constraints.NotBlank; - -@Getter -public class UserInformation { - - @NotBlank(message = "socialId(OAuth 고유의 id)는 null, '', ' ' 일 수 없습니다.") - private final String socialId; - - @NotBlank(message = "socialProfileUrl(OAuth profile url)은 null일 수 없습니다.") - private final String socialProfileUrl; - - private UserInformation(String socialId, String socialProfileUrl) { - this.socialId = socialId; - this.socialProfileUrl = socialProfileUrl; - } - - public static UserInformation of(SocialProfile socialProfile) { - return new UserInformation(socialProfile.extractSocialId(), socialProfile.extractProfileUrl()); - } -} diff --git a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java index fc0a56ef..a166f9ab 100644 --- a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java +++ b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java @@ -24,7 +24,7 @@ public UserInformation requestUserInfo(SocialProvider provider, String code, Str private Authorization extractAuthorization(SocialProvider provider) { validateSocialProvider(provider); - String key = provider.convertToComponentName(); + String key = provider.getProvider(); if (!authorizationMap.containsKey(key)) { log.info(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key)); throw new InvalidOperationException(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key)); diff --git a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java index 318ee350..30ee70f2 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java @@ -23,21 +23,21 @@ public CommentRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java index 4b65c7f3..04bed092 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java +++ b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java @@ -4,21 +4,16 @@ import com.cvi.config.entity.BaseEntity; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.Objects; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Objects; + @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java index c3253449..db98b83d 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java @@ -22,21 +22,21 @@ public LikeRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java index 2de7038c..16853772 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java @@ -2,16 +2,17 @@ import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.persistence.Embeddable; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.Embeddable; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Embeddable diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java index 80dd89dd..644697f8 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java @@ -7,29 +7,16 @@ import com.cvi.image.domain.Image; import com.cvi.like.domain.model.Like; import com.cvi.user.domain.model.User; +import lombok.*; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.validation.constraints.NotBlank; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; @Getter @Entity @@ -62,7 +49,7 @@ public class Post extends BaseEntity { @Builder public Post(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, User user, - String content, int viewCount, VaccinationType vaccinationType) { + String content, int viewCount, VaccinationType vaccinationType) { super(id, createdAt, lastModifiedAt); this.user = user; this.content = content; diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index d9af748f..73121ddc 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -1,12 +1,10 @@ package com.cvi.post.domain.model; -import static com.cvi.post.domain.model.QPost.post; - -import com.cvi.exception.InvalidInputException; import com.querydsl.core.types.OrderSpecifier; -import java.util.Arrays; import lombok.Getter; +import static com.cvi.post.domain.model.QPost.post; + @Getter public enum Sort { LIKE_COUNT_ASC(post.likes.likes.size().asc()), @@ -23,16 +21,4 @@ public enum Sort { Sort(OrderSpecifier sort) { this.sort = sort; } - - public static OrderSpecifier toOrderSpecifier(Sort input) { - return Arrays.stream(values()) - .filter(Sort::isSameTypeOf) - .findAny() - .map(sort -> input.getSort()) - .orElseThrow(() -> new InvalidInputException("잘못된 정렬 형식입니다.")); - } - - private static boolean isSameTypeOf(Sort sort) { - return sort == sort; - } -} \ No newline at end of file +} diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java index 301a041c..e7050a72 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java @@ -1,10 +1,5 @@ package com.cvi.post.domain.repository; -import static com.cvi.comment.domain.model.QComment.comment; -import static com.cvi.like.domain.model.QLike.like; -import static com.cvi.post.domain.model.QPost.post; -import static com.cvi.user.domain.model.QUser.user; - import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.QPost; import com.cvi.post.domain.model.VaccinationType; @@ -12,10 +7,16 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPQLQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; import java.util.List; import java.util.Objects; import java.util.Optional; -import javax.persistence.EntityManager; + +import static com.cvi.comment.domain.model.QComment.comment; +import static com.cvi.like.domain.model.QLike.like; +import static com.cvi.post.domain.model.QPost.post; +import static com.cvi.user.domain.model.QUser.user; public class PostRepositoryImpl implements PostQueryDsl { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java index 7ce619a1..5091b5ec 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java @@ -1,9 +1,10 @@ package com.cvi.publicdata.domain.model; +import lombok.Getter; + import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import lombok.Getter; @Getter public enum RegionPopulation { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java index 4ac68892..f016e4d3 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java @@ -39,8 +39,8 @@ public class VaccinationStatistic extends PublicData { @Builder public VaccinationStatistic(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, RegionPopulation regionPopulation, - LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, - long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { + LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, + long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { super(id, createdAt, lastModifiedAt, regionPopulation); this.baseDate = baseDate; this.firstCnt = firstCnt; diff --git a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java index 171edfb2..d4e1bc73 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java +++ b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java @@ -1,5 +1,8 @@ package com.cvi.user.domain.model; +import lombok.Getter; + +@Getter public enum SocialProvider { NAVER("naverAuthorization"), KAKAO("kakaoAuthorization"); @@ -9,8 +12,4 @@ public enum SocialProvider { SocialProvider(String provider) { this.provider = provider; } - - public String convertToComponentName() { - return this.provider; - } } diff --git a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java index 7f306154..bb39b3de 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java +++ b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java @@ -4,15 +4,10 @@ import com.cvi.exception.InvalidInputException; import lombok.*; import lombok.extern.slf4j.Slf4j; -import org.hibernate.validator.constraints.Length; -import org.springframework.util.StringUtils; import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.Objects; -import java.util.regex.Matcher; import java.util.regex.Pattern; @Slf4j diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java index 5209a98f..5830a573 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java @@ -1,8 +1,5 @@ package com.cvi.comment.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.exception.UnAuthorizedException; @@ -11,11 +8,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("댓글 도메인 테스트") class CommentTest { @@ -136,7 +137,7 @@ void updateFailure() { assertThatThrownBy(() -> comment.update(updateComment, anotherUser)).isInstanceOf(UnAuthorizedException.class); } - @DisplayName("댓글 작성자가 같은 지 확인") + @DisplayName("댓글 작성자가 같은 지 확인 - 성공") @Test void isSameUser() { //given @@ -147,7 +148,7 @@ void isSameUser() { assertThat(comment.isSameUser(user)).isTrue(); } - @DisplayName("같은 댓글인지 확인") + @DisplayName("같은 댓글인지 확인 - 성공") @Test void isSameAs() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java index 547e954c..199a4171 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java @@ -1,7 +1,6 @@ package com.cvi.comment.domain.repository; import com.cvi.comment.domain.model.Comment; -import com.cvi.image.domain.Image; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -15,8 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import java.util.Arrays; - import static org.assertj.core.api.Assertions.assertThat; @DisplayName("CommentRepository 테스트") @@ -49,51 +46,51 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); postRepository.save(post1); } private void initComments() { comment1 = Comment.builder() - .content("댓글 내용1") - .user(user1) - .build(); + .content("댓글 내용1") + .user(user1) + .build(); comment1.assignPost(post1); commentRepository.save(comment1); comment2 = Comment.builder() - .content("댓글 내용2") - .user(user2) - .build(); + .content("댓글 내용2") + .user(user2) + .build(); comment2.assignPost(post1); commentRepository.save(comment2); comment3 = Comment.builder() - .content("댓글 내용3") - .user(user2) - .build(); + .content("댓글 내용3") + .user(user2) + .build(); comment3.assignPost(post1); commentRepository.save(comment3); } @@ -106,7 +103,7 @@ private void assertIdAssigned() { assertThat(post1.getId()).isNotNull(); } - @DisplayName("유저 아이디로 댓글을 조회한다. - 성공") + @DisplayName("유저 아이디로 댓글을 조회한다 - 성공") @Test void findCommentByUserId() { //given @@ -116,16 +113,16 @@ void findCommentByUserId() { assertThat(commentRepository.findByUserId(user2.getId())).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 조회한다 - 성공 - null인 경우") @Test - void findCommentByUserIdFailure() { + void findCommentByUserIdWhenNull() { //given //when //then assertThat(commentRepository.findByUserId(null)).hasSize(3); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 성공") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공") @Test void findCommentByUserIdPaging() { //given @@ -135,9 +132,9 @@ void findCommentByUserIdPaging() { assertThat(commentRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공 - null인 경우") @Test - void findCommentByUserIdPagingFailure() { + void findCommentByUserIdPagingWhenNull() { //given //when //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java index 5fe78ce6..962aca34 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; @DisplayName("Boolean 을 Y/N로 변환 테스트") class BooleanToYNConverterTest { @@ -12,14 +11,26 @@ class BooleanToYNConverterTest { private final BooleanToYNConverter booleanToYNConverter = new BooleanToYNConverter(); @Test - @DisplayName("true 입력시 Y 반환") - void convertToDatabaseColumn() { + @DisplayName("true 입력시 Y 반환 - 성공") + void convertToDatabaseColumnTrueToY() { assertThat(booleanToYNConverter.convertToDatabaseColumn(true)).isEqualTo("Y"); } @Test - @DisplayName("Y 입력시 true 반환") - void convertToEntityAttribute() { + @DisplayName("false 입력시 N 반환 - 성공") + void convertToDatabaseColumnFalseToN() { + assertThat(booleanToYNConverter.convertToDatabaseColumn(false)).isEqualTo("N"); + } + + @Test + @DisplayName("Y 입력시 true 반환 - 성공") + void convertToEntityAttributeYToTrue() { assertThat(booleanToYNConverter.convertToEntityAttribute("Y")).isEqualTo(true); } -} \ No newline at end of file + + @Test + @DisplayName("N 입력시 false 반환 - 성공") + void convertToEntityAttributeNToFalse() { + assertThat(booleanToYNConverter.convertToEntityAttribute("N")).isEqualTo(false); + } +} diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java index a2c8c2de..8580cccc 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java @@ -1,32 +1,32 @@ package com.cvi.image.model; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.image.domain.Image; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("Image 도메인 테스트") class ImageTest { - @DisplayName("객체 주소값, 내용이 달라도 id만 같으면 동일한 객체로 본다.") + @DisplayName("객체 주소값, 내용이 달라도 id만 같으면 동일한 객체 - 성공") @Test void equalsAndHashcode() { //given final Image image1 = Image.builder() - .id(1L) - .url("aaaa/image1") - .build(); + .id(1L) + .url("aaaa/image1") + .build(); final Image image2 = Image.builder() - .id(1L) - .url("bbbb/image2") - .build(); + .id(1L) + .url("bbbb/image2") + .build(); //when //then assertThat(image1) - .isNotSameAs(image2) - .isEqualTo(image2) - .hasSameHashCodeAs(image2); + .isNotSameAs(image2) + .isEqualTo(image2) + .hasSameHashCodeAs(image2); assertThat(image1.getName()).isEqualTo("image1"); assertThat(image2.isSameAs(1L)).isTrue(); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index c4e60f2e..888a48dd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -1,9 +1,7 @@ package com.cvi.image.repository; -import static org.assertj.core.api.Assertions.assertThat; - +import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import com.cvi.image.repository.ImageRepository; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -11,13 +9,17 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; -import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("ImageRepository 테스트") @DataJpaTest class ImageRepositoryTest { @@ -31,53 +33,61 @@ class ImageRepositoryTest { @Autowired private ImageRepository imageRepository; - private User user1; - private Image image1; - private Post post1; + private Image image; + private Post post; @BeforeEach void setUp() { - user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); - userRepository.save(user1); + User user = User.builder() + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); + userRepository.save(user); - image1 = Image.builder() - .url("image1_s3_url") - .build(); - imageRepository.save(image1); + image = Image.builder() + .url("image1_s3_url") + .build(); + imageRepository.save(image); - post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); - postRepository.save(post1); + post = Post.builder() + .user(user) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); + postRepository.save(post); } - @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트") + @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트 - 성공") @Test void assignImageToPost() { //given //when - post1.assignImages(Collections.singletonList(image1)); + post.assignImages(Collections.singletonList(image)); //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); } - @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트") + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 성공") @Test void assignPostToImage() { //given //when - image1.assignPost(post1); + image.assignPost(post); + //then + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); + } + + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 성공 - null인 경우") + @Test + void assignPostToImageWhenNull() { + //given + //when //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThatThrownBy(() -> image.assignPost(null)).isInstanceOf(NotFoundException.class); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java index c58dba92..a36efbb5 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java @@ -1,8 +1,5 @@ package com.cvi.like.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; @@ -10,11 +7,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("좋아요 도메인 테스트") class LikeTest { @@ -71,7 +72,7 @@ void assignPostFailureWhenAlreadyAssignedPost() { assertThatThrownBy(() -> like.assignPost(post)).isInstanceOf(InvalidOperationException.class); } - @DisplayName("좋아요 누른 유저인지 확인") + @DisplayName("좋아요 누른 유저인지 확인 - 성공") @Test void isSameUser() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 229f71fc..667abd6d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -1,7 +1,5 @@ package com.cvi.like.domain.repository; -import com.cvi.comment.domain.model.Comment; -import com.cvi.comment.domain.repository.CommentRepository; import com.cvi.like.domain.model.Like; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; @@ -17,7 +15,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; @DisplayName("LikeRepository 테스트") @DataJpaTest @@ -50,54 +47,54 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); post2 = Post.builder() - .user(user1) - .content("내용 2") - .vaccinationType(VaccinationType.JANSSEN) - .build(); + .user(user1) + .content("내용 2") + .vaccinationType(VaccinationType.JANSSEN) + .build(); postRepository.save(post1); postRepository.save(post2); } private void initLikes() { like1 = Like.builder() - .user(user1) - .build(); + .user(user1) + .build(); like1.assignPost(post1); likeRepository.save(like1); like2 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like2.assignPost(post1); likeRepository.save(like2); like3 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like3.assignPost(post2); likeRepository.save(like3); } @@ -110,7 +107,7 @@ private void assertIdAssigned() { assertThat(post1.getId()).isNotNull(); } - @DisplayName("유저 아이디로 좋아요를 조회한다.") + @DisplayName("유저 아이디로 좋아요를 조회한다 - 성공") @Test void findCommentByUserId() { //given @@ -120,7 +117,16 @@ void findCommentByUserId() { assertThat(likeRepository.findByUserId(user2.getId())).hasSize(2); } - @DisplayName("유저 아이디로 좋아요를 페이징 조회한다.") + @DisplayName("유저 아이디로 댓글을 조회한다 - 실패") + @Test + void findCommentByUserIdWhenNull() { + //given + //when + //then + assertThat(likeRepository.findByUserId(null)).hasSize(3); + } + + @DisplayName("유저 아이디로 좋아요를 페이징 조회한다 - 성공") @Test void findCommentByUserIdPaging() { //given @@ -129,4 +135,13 @@ void findCommentByUserIdPaging() { assertThat(likeRepository.findByUserId(user1.getId(), 0, 2)).hasSize(1); assertThat(likeRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } -} \ No newline at end of file + + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공 - null인 경우") + @Test + void findCommentByUserIdPagingWhenNull() { + //given + //when + //then + assertThat(likeRepository.findByUserId(null, 0, 2)).hasSize(2); + } +} diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java index fc3ba624..607b9edd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java @@ -1,9 +1,5 @@ package com.cvi.post.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.CustomParameterizedTest; import com.cvi.comment.domain.model.Comment; import com.cvi.exception.InvalidOperationException; @@ -14,17 +10,20 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.*; + @DisplayName("게시글 도메인 테스트") class PostTest { @@ -59,9 +58,9 @@ void init() { .user(user) .build(); image = Image.builder() - .id(1L) - .url("image1_s3_url/image") - .build(); + .id(1L) + .url("image1_s3_url/image") + .build(); } @DisplayName("게시글 작성자 할당 - 성공") @@ -117,7 +116,7 @@ void assignCommentFailureWhenAlreadyExists() { post.assignComment(comment); //then assertThatThrownBy(() -> post.assignComment(comment)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 댓글 할당 - 실패 - 할당하려는 댓글이 없음") @@ -130,14 +129,14 @@ void assignCommentFailureWhenNull() { .isInstanceOf(NotFoundException.class); } - @DisplayName("게시글 댓글 수정") + @DisplayName("게시글 댓글 수정 - 성공") @Test void updateComment() { //given Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); post.updateComment(1L, updateComment, user); @@ -150,13 +149,13 @@ void updateComment() { void updateCommentFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .build(); + .id(2L) + .nickname("다른유저") + .build(); Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); //then @@ -164,7 +163,7 @@ void updateCommentFailure() { .isInstanceOf(UnAuthorizedException.class); } - @DisplayName("게시글 댓글 삭제") + @DisplayName("게시글 댓글 삭제 - 성공") @Test void deleteCommentInComments() { //given @@ -181,19 +180,19 @@ void deleteCommentInComments() { void deleteCommentInCommentsFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(2L) + .nickname("다른유저") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); //when post.assignComment(comment); Comments comments = post.getComments(); //then assertThatThrownBy(() -> comments.delete(comment.getId(), anotherUser)) - .isExactlyInstanceOf(UnAuthorizedException.class); + .isExactlyInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 좋아요 할당 - 성공") @@ -214,7 +213,7 @@ void assignLikeFailureWhenAlreadyExists() { post.assignLike(like); //then assertThatThrownBy(() -> post.assignLike(like)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 좋아요 할당 - 실패 - 할당하려는 좋아요가 없음") @@ -224,7 +223,7 @@ void assignLikeFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignLike(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 사진 할당 - 성공") @@ -232,7 +231,7 @@ void assignLikeFailureWhenNull() { void assignImage() { //given //when - post.assignImages(Arrays.asList(image)); + post.assignImages(Collections.singletonList(image)); //then assertThat(post.getAllImagesAsList()).hasSize(1); } @@ -244,10 +243,10 @@ void assignImagesFailureWhenAlreadyExists() { //when //then assertThatThrownBy(() -> post.assignImages(Collections.emptyList())) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } - @DisplayName("게시글 이미지 삭제") + @DisplayName("게시글 이미지 삭제 - 성공") @Test void delete() { //given @@ -259,7 +258,7 @@ void delete() { assertThat(images.getImages()).isEmpty(); } - @DisplayName("게시글의 모든 이미지 주소 조회") + @DisplayName("게시글의 모든 이미지 주소 조회 - 성공") @Test void s3PathsOfAllImages() { //given @@ -354,6 +353,93 @@ void deletePostFailureWhenNotAuthor() { .isInstanceOf(InvalidOperationException.class); } + @DisplayName("게시글 좋아요 이미 누름 - 성공") + @Test + void isAlreadyLikedBy() { + //given + post.assignLike(like); + //when + //then + assertThat(post.isAlreadyLikedBy(user)).isTrue(); + } + + @DisplayName("게시글 좋아요 누르지 않음 - 성공") + @Test + void isNotLikedBy() { + //given + //when + //then + assertThat(post.isAlreadyLikedBy(null)).isFalse(); + } + + @DisplayName("게시글 작성자 확인 - 실패 - 글 작성자가 아님") + @Test + void isNotAlreadyLikedBy() { + //given + User user = User.builder() + .id(2L) + .nickname("인비") + .build(); + User otherUser = User.builder() + .id(3L) + .nickname("라이언") + .build(); + Post post = Post.builder() + .content("내용") + .build(); + post.assignUser(user); + //when + //then + assertThatThrownBy(() -> post.validateAuthor(otherUser)) + .isInstanceOf(InvalidOperationException.class); + } + + @DisplayName("게시글이 이미지 보유 확인 - 성공 - 있음") + @Test + void hasImages() { + //given + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); + //when + final boolean hasImages = post.hasImages(); + //then + assertThat(hasImages).isTrue(); + } + + @DisplayName("게시글이 이미지 보유 확인 - 성공 - 없음") + @Test + void hasNoImages() { + //given + //when + final boolean hasImages = post.hasImages(); + //then + assertThat(hasImages).isFalse(); + } + + @DisplayName("게시글이 이미지 보유 확인 - 성공 - url 확인") + @Test + void getImagesAsUrlList() { + //given + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); + //when + final List imagesAsUrlList = post.getImagesAsUrlList(); + //then + assertThat(imagesAsUrlList).containsExactly("image1_s3_url/image"); + } + + @DisplayName("게시글 s3url 이미지 보유 확인 - 성공 - s3 url 확인") + @Test + void getS3PathsOfAllImages() { + //given + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); + //when + final List imagesAsUrlList = post.getS3PathsOfAllImages(); + //then + assertThat(imagesAsUrlList).containsExactly("image"); + } + @DisplayName("페이징 요청 값 resize - 성공") @CustomParameterizedTest @MethodSource @@ -380,8 +466,8 @@ void resizePagingRangeTest(int offset, int size, List contentResult) { static Stream resizePagingRangeTest() { return Stream.of( Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), - Arguments.of(1, 1, Arrays.asList("댓글2")), - Arguments.of(0, 1, Arrays.asList("댓글1")), + Arguments.of(1, 1, Collections.singletonList("댓글2")), + Arguments.of(0, 1, Collections.singletonList("댓글1")), Arguments.of(2, 1, Collections.emptyList()) ); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java index 1d05a691..6beee448 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java @@ -1,7 +1,5 @@ package com.cvi.post.domain.repository; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.comment.domain.model.Comment; import com.cvi.comment.domain.repository.CommentRepository; import com.cvi.image.domain.Image; @@ -15,19 +13,21 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import static org.assertj.core.api.Assertions.assertThat; @DisplayName("PostRepository 테스트") @DataJpaTest @@ -97,19 +97,19 @@ private void initPost() { .user(user1) .content("화이자 1차 맞았어요.") .vaccinationType(VaccinationType.PFIZER) - .createdAt(LocalDateTime.now().minusDays(1)) + .createdAt(LocalDateTime.now().minusHours(3)) .build(); post2 = Post.builder() .user(user2) .content("모더나 1차 맞았어요.") .vaccinationType(VaccinationType.MODERNA) - .createdAt(LocalDateTime.now()) + .createdAt(LocalDateTime.now().minusHours(2)) .build(); post3 = Post.builder() .user(user1) .content("화이자 2차 맞았어요.") .vaccinationType(VaccinationType.PFIZER) - .createdAt(LocalDateTime.now()) + .createdAt(LocalDateTime.now().minusHours(1)) .build(); postRepository.save(post1); postRepository.save(post2); @@ -240,13 +240,15 @@ void deleteImage() { void findByVaccineTypePaging() { //given //when - List posts = postRepository.findByVaccineType(VaccinationType.PFIZER, 0, 3, Sort.toOrderSpecifier(Sort.CREATED_AT_DESC)); + List posts = postRepository.findByVaccineType(VaccinationType.PFIZER, 0, 3, Sort.CREATED_AT_DESC.getSort()); //then - assertThat(posts).extracting("id").containsExactlyElementsOf(Arrays.asList(post3.getId(), post1.getId())); - assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post1.getContent())); + final List extractedIds = Arrays.asList(post3.getId(), post1.getId()); + assertThat(posts).extracting("id").containsExactlyElementsOf(extractedIds); + final List extractedContents = Arrays.asList(post3.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); } - @DisplayName("백신 타입별 조회") + @DisplayName("백신 타입별 조회 - 특정 타입 검색") @Test void findByVaccineType() { //given @@ -257,6 +259,30 @@ void findByVaccineType() { assertThat(posts).extracting("content").containsExactlyElementsOf(Collections.singletonList(post2.getContent())); } + @DisplayName("백신 타입별 조회 - 백신타입이 주어지지 않은 경우 모든 타입 검색") + @Test + void findByVaccineTypeNull() { + //given + //when + List posts = postRepository.findByVaccineType(null); + //then + assertThat(posts).hasSize(3); + final List extractedContents = Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); + } + + @DisplayName("백신 타입별 조회 - All로 주어지는 경우 모든 타입 검색") + @Test + void findByVaccineTypeAll() { + //given + //when + List posts = postRepository.findByVaccineType(VaccinationType.ALL); + //then + assertThat(posts).hasSize(3); + final List extractedContents = Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); + } + @DisplayName("작성자 ID로 게시글 페이징 조회") @Test void findByUserId() { diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java index f9dacaae..bd107eca 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java @@ -9,54 +9,54 @@ public class VaccinationStatisticFactory { public static final LocalDate TARGET_DATE = LocalDate.now(); public static final List KOREA_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() ); public static final List WORLD_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() ); public static final List VACCINATION_STATISTICS_FROM_DB = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() ); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java index 7db743ad..1c4a22d0 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java @@ -1,29 +1,29 @@ package com.cvi.publicdata.domain.model; -import static org.assertj.core.api.Assertions.assertThat; - -import java.math.BigDecimal; - import com.cvi.CustomParameterizedTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.provider.CsvSource; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("백신 접종률 도메인 테스트") class VaccinationStatisticTest { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "2100000, 4.1", - "21000000, 40.5", - "11000000, 21.2" + "2100000, 4.1", + "21000000, 40.5", + "11000000, 21.2" }) void accumulateFirstRate(long totalFirstCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalFirstCnt(totalFirstCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalFirstCnt(totalFirstCnt) + .build(); //when BigDecimal accumulateFirstRate = vaccinationStatistic.getTotalFirstRate(); //then @@ -33,16 +33,16 @@ void accumulateFirstRate(long totalFirstCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "1100000, 2.1", - "3000000, 5.8", - "11000000, 21.2" + "1100000, 2.1", + "3000000, 5.8", + "11000000, 21.2" }) void accumulateSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -52,16 +52,16 @@ void accumulateSecondRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "2253618189, 28.6", - "2276706840, 28.9", - "2303769251, 29.2" + "2253618189, 28.6", + "2276706840, 28.9", + "2303769251, 29.2" }) void accumulateWorldFirstRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -71,16 +71,16 @@ void accumulateWorldFirstRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "1153697698, 14.6", - "1175939230, 14.9", - "1181952381, 15.0" + "1153697698, 14.6", + "1175939230, 14.9", + "1181952381, 15.0" }) void accumulateWorldSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java index 75588d39..971867ce 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java @@ -1,15 +1,13 @@ package com.cvi.publicdata.domain.model; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.KOREA_VACCINATION_STATISTICS_FROM_API; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.TARGET_DATE; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.VACCINATION_STATISTICS_FROM_DB; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.WORLD_VACCINATION_STATISTICS_FROM_API; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.List; + +import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.*; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("VaccinationStatistic 일급 컬렉션 기능 테스트") class VaccinationStatisticsTest { @@ -20,7 +18,7 @@ void findUnSavedStatisticsWhenAnotherDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE ); //then assertThat(unSavedStatistics.size()).isEqualTo(RegionPopulation.size() - 1); @@ -34,7 +32,7 @@ void findUnSavedStatisticsWhenSameDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE + KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE ); //then assertThat(unSavedStatistics).isEmpty(); @@ -47,7 +45,7 @@ void findWorldUnSavedStatisticsWhenTargetDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(WORLD_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) ); //then assertThat(unSavedStatistics.size()).isEqualTo(WORLD_VACCINATION_STATISTICS_FROM_API.size() - 1); @@ -65,7 +63,7 @@ void findWorldRecentlyStatistics() { assertThat(koreaRecentlyStatistics.size()).isEqualTo(RegionPopulation.size() - 1); assertThat(koreaRecentlyStatistics).noneMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(koreaRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .contains(TARGET_DATE.minusDays(1)); + .contains(TARGET_DATE.minusDays(1)); } @DisplayName("타겟 날짜 이전의 데이터가 DB에 저장되어 있을때(타겟날짜에 데이터가 저장되어 있지 않음) 이전 날짜의 데이터 반환 - 성공 - 세계 데이터") @@ -78,6 +76,6 @@ void findKoreaRecentlyStatistics() { //then assertThat(worldRecentlyStatistics).allMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(worldRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .doesNotContain(TARGET_DATE); + .doesNotContain(TARGET_DATE); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java index 01f63ab1..39010b04 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java @@ -4,10 +4,13 @@ import com.cvi.exception.InvalidInputException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import java.time.LocalDateTime; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; @@ -19,13 +22,13 @@ class UserTest { @BeforeEach void init() { this.user = User.builder() - .id(1L) - .ageRange(AgeRange.TEENS) - .createdAt(LocalDateTime.now()) - .nickname("검프") - .profileUrl("www.gump.com") - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(AgeRange.TEENS) + .createdAt(LocalDateTime.now()) + .nickname("검프") + .profileUrl("www.gump.com") + .socialProvider(SocialProvider.KAKAO) + .build(); } @DisplayName("사용자 생성 - 성공") @@ -36,11 +39,11 @@ void save(String name) { //when //then assertThatCode(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).doesNotThrowAnyException(); } @@ -53,32 +56,40 @@ void saveFailure(String name) { //when //then assertThatThrownBy(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).isInstanceOf(InvalidInputException.class) - .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); + .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); } @DisplayName("사용자 수정 - 성공") @CustomParameterizedTest - @ValueSource(strings = {"ㅁㅇㄹㅁㅇㄹ", "ㅓㅓㅓㅓ", "adfdf", "검프", "검프23213"}) - void update(String name) { + @MethodSource + void update(String name, AgeRange ageRange, boolean shotVerified) { //given User updateUser = User.builder() - .id(1L) - .ageRange(AgeRange.TWENTIES) - .createdAt(LocalDateTime.now()) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(ageRange) + .createdAt(LocalDateTime.now()) + .nickname(name) + .profileUrl("www.budae.com") + .shotVerified(shotVerified) + .socialProvider(SocialProvider.KAKAO) + .build(); //when user.update(updateUser); //then assertThat(user.getNickname()).isEqualTo(updateUser.getNickname()); + assertThat(user.getAgeRange()).isEqualTo(updateUser.getAgeRange()); + assertThat(user.isShotVerified()).isEqualTo(updateUser.isShotVerified()); + } + + static Stream update() { + return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), + Arguments.of("2", AgeRange.THIRTIES, false)); } }