Skip to content

Commit

Permalink
#44 - Test: 회원 기본정보, 비밀번호 수정 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ahah525 committed Dec 21, 2022
1 parent cce984e commit aad5ced
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.example.mutbooks.app.member.entity.AuthLevel;
import com.example.mutbooks.app.member.entity.Member;
import com.example.mutbooks.app.member.exception.EmailDuplicationException;
import com.example.mutbooks.app.member.exception.PasswordNotMatchedException;
import com.example.mutbooks.app.member.exception.UsernameDuplicationException;
import com.example.mutbooks.app.member.form.JoinForm;
import com.example.mutbooks.app.member.form.ModifyForm;
import com.example.mutbooks.app.member.form.PasswordUpdateForm;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -100,4 +103,50 @@ void join4() {
// when, then
assertThrows(EmailDuplicationException.class, () -> memberService.join(joinForm));
}

@Test
@DisplayName("회원기본정보 수정")
void modifyProfile() {
// given
ModifyForm modifyForm = ModifyForm.builder()
.email("[email protected]")
.nickname("new")
.build();
// when
memberService.modifyProfile("user1", modifyForm);
Member member = memberService.findByUsername("user1");
// then
assertThat(member.getEmail()).isEqualTo("[email protected]");
assertThat(member.getNickname()).isEqualTo("new");
}

@Test
@DisplayName("회원 비밀번호 수정")
void modifyPassword1() {
// given
PasswordUpdateForm passwordUpdateForm = PasswordUpdateForm.builder()
.password("1234")
.newPassword("12345")
.newPasswordConfirm("12345")
.build();
// when
memberService.modifyPassword("user1", passwordUpdateForm);
Member member = memberService.findByUsername("user1");
// then
assertTrue(passwordEncoder.matches("12345", member.getPassword()));
}

@Test
@DisplayName("기존 비밀번호가 일치하지 않으면 비밀번호 수정 불가")
void modifyPassword2() {
// given
PasswordUpdateForm passwordUpdateForm = PasswordUpdateForm.builder()
.password("123")
.newPassword("12345")
.newPasswordConfirm("12345")
.build();
// when, then
assertThrows(PasswordNotMatchedException.class,
() -> memberService.modifyPassword("user1", passwordUpdateForm));
}
}

0 comments on commit aad5ced

Please sign in to comment.