Skip to content

Commit

Permalink
feat: 리뷰에 리뷰의 저자인지 확인하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Oct 10, 2023
1 parent 0c5b38c commit 43ea289
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
4 changes: 4 additions & 0 deletions backend/src/main/java/com/funeat/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand All @@ -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;
}
Expand Down
54 changes: 54 additions & 0 deletions backend/src/test/java/com/funeat/review/domain/ReviewTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 43ea289

Please sign in to comment.