Skip to content
Snippets Groups Projects
Commit dea2bf8a authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Test login user

parent 1a617f38
No related branches found
No related tags found
2 merge requests!14Language school user tests,!13Language school user
......@@ -62,7 +62,7 @@ public class UserController {
}
@PostMapping("/login")
public String login(@RequestBody UserLoginDto dto) {
public String login(@Valid @RequestBody UserLoginDto dto) {
return String.format("User %s has spawned", dto.getUsername());
}
......
......@@ -90,6 +90,14 @@ class UserControllerTest {
return Stream.concat(invalidUsers, invalidAddressUsers.stream());
}
private static Stream<UserLoginDto> invalidLoginDtoStream() {
return Stream.of(
new UserLoginDto("", "skkckdvssg4v83sfsDRHCVVB"),
new UserLoginDto("xnovak", ""),
new UserLoginDto(null, "skkckdvssg4v83sfsDRHCVVB"),
new UserLoginDto("xnovak", null));
}
@Test
void create() throws Exception {
mockMvc.perform(post("/users")
......@@ -172,6 +180,15 @@ class UserControllerTest {
.andExpect(status().isOk());
}
@ParameterizedTest
@MethodSource("invalidLoginDtoStream")
void loginInvalidDto(UserLoginDto loginDto) throws Exception {
mockMvc.perform(post("/users/login")
.content(asJsonString(loginDto))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
}
private static String asJsonString(final Object obj) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(obj);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment