diff --git a/backend/src/main/java/com/funeat/review/domain/Review.java b/backend/src/main/java/com/funeat/review/domain/Review.java index 3545371e3..d990666d3 100644 --- a/backend/src/main/java/com/funeat/review/domain/Review.java +++ b/backend/src/main/java/com/funeat/review/domain/Review.java @@ -88,6 +88,10 @@ public void minusFavoriteCount() { this.favoriteCount--; } + public boolean checkAuthor(final Member member) { + return Objects.equals(this.member, member); + } + public Long getId() { return id; } diff --git a/backend/src/main/java/com/funeat/review/dto/SortingReviewDto.java b/backend/src/main/java/com/funeat/review/dto/SortingReviewDto.java index 5f6174bea..9173fdd63 100644 --- a/backend/src/main/java/com/funeat/review/dto/SortingReviewDto.java +++ b/backend/src/main/java/com/funeat/review/dto/SortingReviewDto.java @@ -55,7 +55,7 @@ public static SortingReviewDto toDto(final Review review, final Member member) { review.getFavoriteCount(), findReviewFavoriteChecked(review, member), review.getCreatedAt(), - findAuthorChecked(review, member) + review.checkAuthor(member) ); } @@ -76,13 +76,6 @@ private static boolean findReviewFavoriteChecked(final Review review, final Memb .orElse(false); } - private static boolean findAuthorChecked(final Review review, final Member member) { - final Long reviewMemberId = review.getMember().getId(); - final Long loginMemberId = member.getId(); - - return reviewMemberId.equals(loginMemberId); - } - public Long getId() { return id; } diff --git a/backend/src/test/java/com/funeat/review/domain/ReviewTest.java b/backend/src/test/java/com/funeat/review/domain/ReviewTest.java new file mode 100644 index 000000000..20bb1a792 --- /dev/null +++ b/backend/src/test/java/com/funeat/review/domain/ReviewTest.java @@ -0,0 +1,54 @@ +package com.funeat.review.domain; + +import static org.assertj.core.api.Assertions.*; + +import com.funeat.member.domain.Member; +import com.funeat.product.domain.Product; +import java.util.ArrayList; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(ReplaceUnderscores.class) +public class ReviewTest { + + @Nested + class isAuthor_성공테스트 { + + @Test + void 리뷰를_작성한_멤버이면_true를_반환한다() { + // given + final var product = new Product("test", 1000L, "image", "content", null); + + final var member = new Member("member1", "one", "1"); + + final var review = new Review(member, product, "imgae", 5L, "content", true); + + // when + final var actual = review.checkAuthor(member); + + // then + assertThat(actual).isTrue(); + } + + @Test + void 리뷰를_작성한_멤버가_아니면_false를_반환한다() { + // given + final var product = new Product("test", 1000L, "image", "content", null); + + final var correctMember = new Member("realMember", "one", "1"); + final var wrongMember = new Member("wrongMember", "one", "1"); + + final var review = new Review(correctMember, product, "imgae", 5L, "content", true); + + // when + final var actual = review.checkAuthor(wrongMember); + + // then + assertThat(actual).isFalse(); + } + } +}