Skip to content

Commit

Permalink
test: Star Rating Service 별점 수정 Test 추가 #90
Browse files Browse the repository at this point in the history
  • Loading branch information
FaberJoo committed Nov 7, 2023
1 parent 9a2c0a5 commit ab3343c
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,61 @@ void chekRatedIfNotExist() {
assertThrows(NotFoundException.class, () -> starRatingService.checkRated(memberId, animeId));
}
}

@Nested
@DisplayName("별점 수정")
class UpdateScore {
Long memberId = 1L;
Long animeId = 1L;
int score = 2;

Member member = Member.builder()
.id(memberId)
.build();
Anime anime = Anime.builder()
.id(animeId)
.build();

@Test
@DisplayName("별점 수정 성공")
void updateScore() {
// given
StarRating starRating = StarRating.builder()
.member(member)
.anime(anime)
.score(score)
.build();

given(starRatingRepository.findByMemberIdAndAnimeId(memberId, animeId))
.willReturn(Optional.ofNullable(starRating));

// when
boolean result = starRatingService.updateScore(memberId, animeId, 5);

// then
assertDoesNotThrow(() -> starRatingService.updateScore(memberId, animeId, score));
assertTrue(result);
}

@Test
@DisplayName("별점 수정 실패")
void updateScoreIfNotExist() {
// given
StarRating starRating = StarRating.builder()
.member(member)
.anime(anime)
.score(score)
.build();

given(starRatingRepository.findByMemberIdAndAnimeId(memberId, animeId))
.willReturn(Optional.ofNullable(starRating));

// when
boolean result = starRatingService.updateScore(memberId, animeId, score);

// then
assertDoesNotThrow(() -> starRatingService.updateScore(memberId, animeId, score));
assertFalse(result);
}
}
}

0 comments on commit ab3343c

Please sign in to comment.