Students registered satistics

This commit is contained in:
Filip Izydorczyk
2021-01-21 15:41:56 +01:00
parent 7045844653
commit 676070c8c7
6 changed files with 106 additions and 34 deletions

View File

@ -23,6 +23,7 @@ import com.plannaplan.types.UserRoles;
public class StatisticsControllerTest extends AbstractControllerTest {
private static final String GROUP_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/created";
private static final String USER_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/registered";
@Autowired
private UserService userService;
@ -61,4 +62,39 @@ public class StatisticsControllerTest extends AbstractControllerTest {
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS ASSIGNED TESTS */
@Test
public void shouldFailWithWrongAccesRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccesRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenRegisteredStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
}