students endpoint
This commit is contained in:
@ -22,11 +22,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@ContextConfiguration
|
||||
|
||||
public class UsersControllerTest extends AbstractControllerTest {
|
||||
private static final String ENDPOINT = "/api/v1/users/student/search";
|
||||
private static final String SEARCH_ENDPOINT = "/api/v1/users/student/search";
|
||||
private static final String ALL_USERS_ENDPOINT = "/api/v1/users/students";
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
/* SEARCH_ENDPOINT */
|
||||
|
||||
@Test
|
||||
public void shouldRestrun200OK() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldRestrun200OK.test";
|
||||
@ -34,14 +37,14 @@ public class UsersControllerTest extends AbstractControllerTest {
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT).param("query", "").header("Authorization", "Bearer " + token))
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT).param("query", "").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRestrunForbiden() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -51,7 +54,37 @@ public class UsersControllerTest extends AbstractControllerTest {
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
/* ALL_USERS_ENDPOINT */
|
||||
|
||||
@Test
|
||||
public void shouldRestrunAllStudents200OK() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldRestrunAllStudents200OK.test";
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRestrunAllStudentsForbiden() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyAllStudentsTryByStudent() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldDenyAllStudentsTryByStudent.test";
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.STUDENT));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user