Added new tests

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2020-12-26 14:31:09 +01:00
parent c3d78505c8
commit 09cc994d92
2 changed files with 30 additions and 79 deletions

View File

@ -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());
}
}