Skip to content

Commit

Permalink
[FEATURE] E4-S1 로그인 API - 회원가입 테스트코드 작성 #28
Browse files Browse the repository at this point in the history
  • Loading branch information
choisungwook committed Oct 8, 2021
1 parent 3aad5b3 commit af4d496
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.infp.ciat.config.security;

import lombok.NoArgsConstructor;

/***
* 로그인 요청 dto
*/
@NoArgsConstructor
public class RequestLoginDTO {
private String email;
private String password;
Expand All @@ -22,4 +25,9 @@ public void setEmail(String email) {
public void setPassword(String password) {
this.password = password;
}

public RequestLoginDTO(String email, String password) {
this.email = email;
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.infp.ciat.config.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.infp.ciat.user.controller.dto.request.SignupRequestDTO;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
class LoginfilterTest {
@Autowired
private MockMvc mockMvc;

@Test
@DisplayName("회원가입 후 로그인")
public void SignUp() throws Exception {
SignupRequestDTO signup_requestdto1 = create_signup_requestdto("[email protected]", "test1", "password");

mockMvc.perform(
post("/signup")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(signup_requestdto1))
)
.andExpect(status().isCreated())
.andDo(print());

RequestLoginDTO requestLoginDTO1 = new RequestLoginDTO(signup_requestdto1.getEmail(), signup_requestdto1.getPassword());

mockMvc.perform(
post("/signin")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(requestLoginDTO1))
)
.andExpect(status().isOk())
.andDo(print());
}

/***
* 회원가입 요청 DTO 생성
* @param email
* @param nickname
* @param password
* @return
*/
private SignupRequestDTO create_signup_requestdto(String email, String nickname, String password) {
SignupRequestDTO signupRequestDTO = new SignupRequestDTO();
signupRequestDTO.setEmail(email);
signupRequestDTO.setNickname(nickname);
signupRequestDTO.setPassword(password);

return signupRequestDTO;
}
}

0 comments on commit af4d496

Please sign in to comment.