From b4f51d438244f93e1388b77eabcd8bf8cdba8303 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 31 Oct 2020 15:24:17 +0100 Subject: [PATCH] Added tests --- .../controllers/CommisionControllerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java index ab32320..f80b0d5 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java @@ -46,6 +46,7 @@ public class CommisionControllerTest { 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_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user"; private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); @@ -161,6 +162,28 @@ public class CommisionControllerTest { .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() { if (CommisionControllerTest.user == null) { CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);