Added tests

This commit is contained in:
BuildTools 2020-10-31 15:24:17 +01:00
parent 6ab2ec50dd
commit b4f51d4382

View File

@ -46,6 +46,7 @@ public class CommisionControllerTest {
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add"; private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add";
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions"; private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
@ -161,6 +162,28 @@ public class CommisionControllerTest {
.andExpect(status().is4xxClientError()); .andExpect(status().is4xxClientError());
} }
@Test
public void shouldGetStudentCommisionsListByDeanary() throws Exception {
this.checkUsers();
final String token = this.service.login(TEST_COMMISIONS_DEANERY_EMAIL);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
}
@Test
public void shouldFailStudentCommisionsListByOtherStudent() throws Exception {
this.checkUsers();
final String token = this.service.login(TEST_COMMISIONS_STUDENT_EMAIL);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
}
private void checkUsers() { private void checkUsers() {
if (CommisionControllerTest.user == null) { if (CommisionControllerTest.user == null) {
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT); CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);