Skip to content

Commit

Permalink
feat(article): add description input
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefulBrown committed May 29, 2024
1 parent 5ba4ecc commit d7c10bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class ArticleRequest {
private final String imageUrl;
private final String description;

public ArticleRequest(String title, String url, String imageUrl) {
this.title = title;
this.url = url;
this.imageUrl = imageUrl;
this.description = "";
}

public Article toArticle(final Member member) {
return new Article(member, new Title(title), new Description(description), new Url(url), new ImageUrl(imageUrl));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import wooteco.prolog.article.application.dto.ArticleRequest;
import wooteco.prolog.article.application.dto.ArticleResponse;
import wooteco.prolog.article.domain.Article;
import wooteco.prolog.article.domain.ArticleBookmarks;
import wooteco.prolog.article.domain.ArticleFilterType;
Expand All @@ -16,8 +18,6 @@
import wooteco.prolog.article.domain.Title;
import wooteco.prolog.article.domain.Url;
import wooteco.prolog.article.domain.repository.ArticleRepository;
import wooteco.prolog.article.application.dto.ArticleRequest;
import wooteco.prolog.article.application.dto.ArticleResponse;
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.login.ui.LoginMember;
import wooteco.prolog.member.application.MemberService;
Expand Down Expand Up @@ -57,12 +57,12 @@ class ArticleServiceTest {
@Test
void create_success() {
//given
final ArticleRequest judyRequest = new ArticleRequest("title", "url", "imageUrl");
final ArticleRequest judyRequest = new ArticleRequest("title", "url", "imageUrl", "desc");
final Member member = new Member(1L, "username", "nickname", CREW, 1L, "url");
when(memberService.findById(any())).thenReturn(member);

final Article article = new Article(member, new Title("title"), new Url("url"),
new ImageUrl("imageUrl"));
new ImageUrl("imageUrl"));
when(articleRepository.save(any())).thenReturn(article);
final LoginMember judyLogin = new LoginMember(1L, MEMBER);

Expand All @@ -77,7 +77,7 @@ void create_success() {
@Test
void create_fail_guest() {
//given
final ArticleRequest judyRequest = new ArticleRequest("title", "url", "imageUrl");
final ArticleRequest judyRequest = new ArticleRequest("title", "url", "imageUrl", "desc");
final Member member = new Member(1L, "username", "nickname", Role.GUEST, 1L, "url");
when(memberService.findById(any())).thenReturn(member);
final LoginMember judyLogin = new LoginMember(1L, MEMBER);
Expand All @@ -94,13 +94,13 @@ void update_success() {
//given
final Member judy = new Member(1L, "username", "nickname", CREW, 1L, "url");
final Article judyArticle = new Article(judy, new Title("judyTitle"), new Url("judyUrl"),
new ImageUrl("imageUrl"));
new ImageUrl("imageUrl"));
when(articleRepository.findById(any())).thenReturn(Optional.of(judyArticle));
when(memberService.findById(any())).thenReturn(judy);

final LoginMember judyLogin = new LoginMember(1L, MEMBER);
final ArticleRequest judyChangedRequest = new ArticleRequest("title", "changedUrl",
"imageUrl");
"imageUrl");

//when
articleService.update(1L, judyChangedRequest, judyLogin);
Expand All @@ -120,11 +120,11 @@ void update_fail_ArticleNotFoundException() {

final LoginMember judyLogin = new LoginMember(1L, MEMBER);
final ArticleRequest judyChangedRequest = new ArticleRequest("title", "changedUrl",
"imageUrl");
"imageUrl");

//when, then
assertThatThrownBy(() -> articleService.update(1L, judyChangedRequest, judyLogin))
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class);
}

@DisplayName("수정시 아티클 작성자가 아니라면 예외를 발생시킨다.")
Expand All @@ -134,17 +134,17 @@ void update_fail_InvalidArticleAuthorException() {
final Member judy = new Member(1L, "judith", "judy", CREW, 1L, "judyUrl");
final Member brown = new Member(2L, "brown", "brownie", CREW, 2L, "brownUrl");
final Article brownArticle = new Article(brown, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
when(articleRepository.findById(any())).thenReturn(Optional.of(brownArticle));

final LoginMember judyLogin = new LoginMember(1L, MEMBER);
when(memberService.findById(any())).thenReturn(judy);
final ArticleRequest judyChangedRequest = new ArticleRequest("title", "changedUrl",
"imageUrl");
"imageUrl");

//when, then
assertThatThrownBy(() -> articleService.update(1L, judyChangedRequest, judyLogin))
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class);
}

@DisplayName("아티클을 삭제한다.")
Expand All @@ -153,7 +153,7 @@ void delete_success() {
//given
final Member judy = new Member(1L, "judith", "judy", CREW, 1L, "judyUrl");
final Article judyArticle = new Article(judy, new Title("judyTitle"), new Url("judyUrl"),
new ImageUrl("imageUrl"));
new ImageUrl("imageUrl"));
when(articleRepository.findById(any())).thenReturn(Optional.of(judyArticle));
when(memberService.findById(any())).thenReturn(judy);
final LoginMember judyLogin = new LoginMember(1L, MEMBER);
Expand All @@ -178,7 +178,7 @@ void delete_fail_ArticleNotFoundException() {

//when, then
assertThatThrownBy(() -> articleService.delete(1L, judyLogin))
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class);
}

@DisplayName("삭제시 아티클 작성자가 아니라면 예외를 발생시킨다.")
Expand All @@ -188,15 +188,15 @@ void delete_fail_InvalidArticleAuthorException() {
final Member judy = new Member(1L, "judith", "judy", CREW, 1L, "judyUrl");
final Member brown = new Member(2L, "brown", "brownie", CREW, 2L, "brownUrl");
final Article brownArticle = new Article(brown, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
when(articleRepository.findById(any())).thenReturn(Optional.of(brownArticle));

final LoginMember judyLogin = new LoginMember(1L, MEMBER);
when(memberService.findById(any())).thenReturn(judy);

//when, then
assertThatThrownBy(() -> articleService.delete(1L, judyLogin))
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class);
}

@Nested
Expand All @@ -208,14 +208,14 @@ class bookmarkArticle {
void add() {
//given
final Member member = new Member(1L, "userName", "nickName",
CREW, 1L, "imageUrl");
CREW, 1L, "imageUrl");
final Article article = new Article(member, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
final Long articleId = 3L;
final LoginMember loginMember = new LoginMember(member.getId(), MEMBER);

when(articleRepository.findFetchBookmarkById(articleId)).thenReturn(
Optional.of(article));
Optional.of(article));
when(memberService.findById(member.getId())).thenReturn(member);

//when
Expand All @@ -224,22 +224,22 @@ void add() {
//then
final ArticleBookmarks articleBookmarks = article.getArticleBookmarks();
assertThat(articleBookmarks.containBookmark(member.getId()))
.isTrue();
.isTrue();
}

@DisplayName("아티클의 북마크를 삭제한다.")
@Test
void remove() {
//given
final Member member = new Member(1L, "userName", "nickName",
CREW, 1L, "imageUrl");
CREW, 1L, "imageUrl");
final Article article = new Article(member, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
final Long articleId = 3L;
final LoginMember loginMember = new LoginMember(member.getId(), MEMBER);

when(articleRepository.findFetchBookmarkById(articleId)).thenReturn(
Optional.of(article));
Optional.of(article));
when(memberService.findById(member.getId())).thenReturn(member);

//when
Expand All @@ -248,7 +248,7 @@ void remove() {
//then
final ArticleBookmarks articleBookmarks = article.getArticleBookmarks();
assertThat(articleBookmarks.containBookmark(member.getId()))
.isTrue();
.isTrue();
}
}

Expand All @@ -261,9 +261,9 @@ class likeArticle {
void add() {
//given
final Member member = new Member(1L, "userName", "nickName",
CREW, 1L, "imageUrl");
CREW, 1L, "imageUrl");
final Article article = new Article(member, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
final Long articleId = 3L;
final LoginMember loginMember = new LoginMember(member.getId(), MEMBER);

Expand All @@ -276,17 +276,17 @@ void add() {
//then
final ArticleLikes articleBookmarks = article.getArticleLikes();
assertThat(articleBookmarks.isAlreadyLike(member.getId()))
.isTrue();
.isTrue();
}

@DisplayName("아티클의 좋아요를 삭제한다.")
@Test
void remove() {
//given
final Member member = new Member(1L, "userName", "nickName",
CREW, 1L, "imageUrl");
CREW, 1L, "imageUrl");
final Article article = new Article(member, new Title("brownTitle"),
new Url("brownUrl"), new ImageUrl("imageUrl"));
new Url("brownUrl"), new ImageUrl("imageUrl"));
final Long articleId = 3L;
final LoginMember loginMember = new LoginMember(member.getId(), MEMBER);

Expand All @@ -299,7 +299,7 @@ void remove() {
//then
final ArticleLikes articleBookmarks = article.getArticleLikes();
assertThat(articleBookmarks.isAlreadyLike(member.getId()))
.isFalse();
.isFalse();
}
}

Expand Down

0 comments on commit d7c10bf

Please sign in to comment.