Skip to content

Commit

Permalink
test: article filter test 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
donghae-kim committed Sep 20, 2023
1 parent f4d5ad4 commit 262d414
Showing 1 changed file with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package wooteco.prolog.article.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static wooteco.prolog.login.ui.LoginMember.Authority.MEMBER;
import static wooteco.prolog.member.domain.Role.CREW;

import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -24,12 +15,28 @@
import wooteco.prolog.article.domain.Url;
import wooteco.prolog.article.domain.repository.ArticleRepository;
import wooteco.prolog.article.ui.ArticleRequest;
import wooteco.prolog.article.ui.ArticleResponse;
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.member.application.MemberService;
import wooteco.prolog.member.domain.Member;
import wooteco.prolog.member.domain.MemberGroupType;
import wooteco.prolog.member.domain.Role;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static wooteco.prolog.login.ui.LoginMember.Authority.ANONYMOUS;
import static wooteco.prolog.login.ui.LoginMember.Authority.MEMBER;
import static wooteco.prolog.member.domain.Role.CREW;

@ExtendWith(MockitoExtension.class)
class ArticleServiceTest {

Expand Down Expand Up @@ -232,4 +239,40 @@ void remove() {
.isTrue();
}
}

@DisplayName("비로그인 사용자가 백엔드 아티클을 필터링 한다.")
@Test
void filter() {
//given
final Member member = new Member(1L, "username", "nickname", CREW, 1L, "url");
final Article article = new Article(member, new Title("title"), new Url("url"), new ImageUrl("imageUrl"));
final LoginMember unLoginMember = new LoginMember(1L, ANONYMOUS);

when(articleRepository.findArticlesByCourse(any())).thenReturn(Arrays.asList(article));

//when
final List<ArticleResponse> articleResponses = articleService.filter(unLoginMember, MemberGroupType.BACKEND, false);

//then
verify(articleRepository).findArticlesByCourse(any());
Assertions.assertThat(articleResponses.get(0).getTitle()).isEqualTo(article.getTitle().getTitle());
}

@DisplayName("로그인 유저가 북마크 백엔드 아티클을 필터링 한다.")
@Test
void filter_isBookmarked() {
//given
final Member member = new Member(1L, "username", "nickname", CREW, 1L, "url");
final Article article = new Article(member, new Title("title"), new Url("url"), new ImageUrl("imageUrl"));
final LoginMember loginMember = new LoginMember(1L, MEMBER);

when(articleRepository.findArticlesByCourseAndMember(any(), any())).thenReturn(Arrays.asList(article));

//when
final List<ArticleResponse> articleResponses = articleService.filter(loginMember, MemberGroupType.BACKEND, true);

//then
verify(articleRepository).findArticlesByCourseAndMember(any(), any());
Assertions.assertThat(articleResponses.get(0).getTitle()).isEqualTo(article.getTitle().getTitle());
}
}

0 comments on commit 262d414

Please sign in to comment.