@ -36,6 +36,7 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
|
||||
private static final String FILE_NAME = "Zajecia.xlsx";
|
||||
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
|
||||
private static final String COURSE_ENDPOINT = "/api/v1/configurator/config/courses";
|
||||
private static final String ADMIN_INIT_ENDPOINT = "/api/v1/configurator/admin/init";
|
||||
private static final String FIRST_TOUR_START = "firstTourBegin";
|
||||
private static final String FIRST_TOUR_END = "firstTourEnd";
|
||||
@ -242,4 +243,33 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOKAuthorizedForCourses() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorizedForCourses@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(multipart(COURSE_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeniedForCoursesDueToWrongRole() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorizedForCourses@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(multipart(COURSE_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user