diff --git a/application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserControllerTest.java b/application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserControllerTest.java index a1d282ef4482148e605015c382d113a6702e5400..858d772c9bd00061eb405bfb80a7505b4cc81e8a 100644 --- a/application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserControllerTest.java +++ b/application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserControllerTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.fuseri.model.dto.user.AddressDto; import org.fuseri.model.dto.user.UserCreateDto; +import org.fuseri.model.dto.user.UserDto; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -25,6 +26,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @AutoConfigureMockMvc class UserControllerTest { + @Autowired + private ObjectMapper objectMapper; + @Autowired private MockMvc mockMvc; @@ -99,6 +103,20 @@ class UserControllerTest { .andExpect(status().is4xxClientError()); } + @Test + void findUser() throws Exception { + String response = mockMvc.perform(post("/users") + .content(asJsonString(USER_TO_CREATE)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); + + String id = objectMapper.readValue(response, UserDto.class).getId(); + + mockMvc.perform(get("/users/" + id)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id").value(id)); + } + private static String asJsonString(final Object obj) throws JsonProcessingException { return new ObjectMapper().writeValueAsString(obj); }