Skip to content

Commit

Permalink
test: MemberControllerTest 추가
Browse files Browse the repository at this point in the history
- 회원 가입 성공 테스트 추가
  • Loading branch information
LineYK committed Nov 21, 2023
1 parent 26d6778 commit e236181
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.milk.milkweb.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.milk.milkweb.config.OAuth2Config;
import com.milk.milkweb.config.SecurityConfig;
import com.milk.milkweb.dto.MemberFormDto;
Expand All @@ -13,6 +14,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser;
Expand All @@ -22,15 +24,17 @@
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@Import({SecurityConfig.class, OAuth2Config.class})
@WebMvcTest(MemberController.class)
public class MemberControllerTest {

@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;

@MockBean
private MemberService memberService;
Expand All @@ -52,6 +56,23 @@ void entryMemberFormTest() throws Exception {
.andExpect(model().attribute("memberFormDto", Matchers.instanceOf(MemberFormDto.class)));
}

@Test
@DisplayName("회원 가입 성공 테스트")
void registerMemberSuccessTest() throws Exception {
// given
MemberFormDto memberFormDto = MemberFormDto.builder()
.email("test@test.com")
.name("tester")
.password("12345678")
.build();

// when, then
mockMvc.perform(post("/member/register").with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(memberFormDto)))
.andExpect(status().is2xxSuccessful());
}

@Test
@WithMockUser(username = "test@test.com", password = "1234")
@DisplayName("로그인 성공 테스트")
Expand Down

0 comments on commit e236181

Please sign in to comment.