32 lines
1.1 KiB
Java
32 lines
1.1 KiB
Java
package pl.edu.amu.wmi.bookapi.fixtures.api;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.ResultActions;
|
|
|
|
import java.net.URI;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
|
|
|
public class UserControllerRequests {
|
|
|
|
private final MockMvc mvc;
|
|
private final ObjectMapper objectMapper;
|
|
|
|
public UserControllerRequests(MockMvc mvc, ObjectMapper objectMapper) {
|
|
this.mvc = mvc;
|
|
this.objectMapper = objectMapper;
|
|
}
|
|
|
|
public ResultActions registerUser(String userName, String password) throws Exception {
|
|
return mvc.perform(post(URI.create("/users/sign-up"))
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.content("{\n" +
|
|
" \"username\": " + objectMapper.writeValueAsString(userName) + ",\n" +
|
|
" \"password\": " + objectMapper.writeValueAsString(password) + "\n" +
|
|
"}"));
|
|
}
|
|
|
|
}
|