Skip to content

Commit

Permalink
Merge pull request #1506 from woowacourse/feat/#1505
Browse files Browse the repository at this point in the history
refactor: 아티클 생성시 CREW 권한 확인 로직 추가
  • Loading branch information
splitCoding authored Aug 11, 2023
2 parents 26a6b5d + 9615102 commit 13f70d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class ArticleService {
@Transactional
public Long create(final ArticleRequest articleRequest, final LoginMember loginMember) {
final Member member = memberService.findById(loginMember.getId());
if (member.isAnonymous()) {
throw new BadRequestException(BadRequestCode.UNVALIDATED_MEMBER_EXCEPTION);
}
final Article article = articleRequest.toArticle(member);
return articleRepository.save(article).getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ public enum BadRequestCode {
INVALID_ARTICLE_AUTHOR_EXCEPTION(12005, "INVALID_ARTICLE_AUTHOR_EXCEPTION"),
ARTICLE_IMAGE_URL_NULL_OR_EMPTY_EXCEPTION(12006, "ARTICLE_IMAGE_URL_NULL_OR_EMPTY_EXCEPTION"),
ARTICLE_IMAGE_URL_OVER_LENGTH_EXCEPTION(12007, "ARTICLE_IMAGE_URL_OVER_LENGTH_EXCEPTION"),
ARTICLE_INVALID_URL_EXCEPTION(12008, "ARTICLE_INVALID_URL_EXCEPTION");

ARTICLE_INVALID_URL_EXCEPTION(12008, "ARTICLE_INVALID_URL_EXCEPTION"),
UNVALIDATED_MEMBER_EXCEPTION(12009, "UNVALIDATED_MEMBER_EXCEPTION");

private int code;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ void create_success() {
verify(articleRepository).save(any());
}

@DisplayName("아티클 생성시 UNVALIDATED 권한일 경우 예외를 발생한다.")
@Test
void create_success_unAuthorized() {
//given
final ArticleRequest judyRequest = new ArticleRequest("title", "url", "imageUrl");
final Member member = new Member(1L, "username", "nickname", Role.UNVALIDATED, 1L, "url");
final LoginMember judyLogin = new LoginMember(1L, MEMBER);

when(memberService.findById(any())).thenReturn(member);

//when
assertThatThrownBy(() -> articleService.create(judyRequest, judyLogin))
.isInstanceOf(BadRequestException.class);
}

@DisplayName("아티클을 수정한다.")
@Test
void update_success() {
Expand Down

0 comments on commit 13f70d1

Please sign in to comment.