package me.weekbelt.studyolle.settings;
@SpringBootTest
@AutoConfigureMockMvc
class SettingsControllerTest {
// 기존 코드 .....
@Autowired
PasswordEncoder passwordEncoder;
// 기존 코드 ......
@WithAccount("joohyuk")
@DisplayName("패스워드 수정 폼")
@Test
public void updatePassword_form() throws Exception {
mockMvc.perform(get("/settings/password"))
.andExpect(status().isOk())
.andExpect(model().attributeExists("account"))
.andExpect(model().attributeExists("passwordForm"));
}
@WithAccount("joohyuk")
@DisplayName("패스워드 수정 - 입력값 정상")
@Test
public void updatePassword_success() throws Exception {
mockMvc.perform(post("/settings/password")
.param("newPassword", "12345678")
.param("newPasswordConfirm", "12345678")
.with(csrf()))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/settings/password"))
.andExpect(flash().attributeExists("message"));
Account joohyuk = accountRepository.findByNickname("joohyuk");
assertTrue(passwordEncoder.matches("12345678", joohyuk.getPassword()));
}
@WithAccount("joohyuk")
@DisplayName("패스워드 수정 - 입력값 에러 - 패스워드 불일치")
@Test
public void updatePassword_fail() throws Exception {
mockMvc.perform(post("/settings/password")
.param("newPassword", "12345678")
.param("newPasswordConfirm", "111111111")
.with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name("settings/password"))
.andExpect(model().hasErrors())
.andExpect(model().attributeExists("passwordForm"))
.andExpect(model().attributeExists("account"));
}
}
참고: https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-JPA-%EC%9B%B9%EC%95%B1#
'스프링과 JPA 기반 웹 어플리케이션 개발 > 1부 (개발환경, 회원가입, 로그인, 계정설정)' 카테고리의 다른 글
29. ModelMapper 적용 (0) | 2020.04.22 |
---|---|
28. 알림 설정 (0) | 2020.04.22 |
26. 패스워드 수정 (0) | 2020.04.21 |
25. 프로필 이미지 변경 (0) | 2020.04.21 |
24. 프로필 수정 테스트 (0) | 2020.04.21 |