Use findAll in staff tests

Co-authored-by: Simon Bruder <simon.bruder@mailbox.tu-dresden.de>
This commit is contained in:
Denis Natusch 2023-11-27 16:44:22 +01:00 committed by Simon Bruder
parent 1b1aac5476
commit b72fa87445
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -10,6 +10,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -43,6 +44,13 @@ class StaffControllerIntegrationTests {
defaultEmployeeId = defaultEmployee.getId();
}
@AfterEach
void tearDown() throws Exception {
staffManagement.delete(defaultEmployeeId);
defaultEmployee = null;
defaultEmployeeId = null;
}
@Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
void viewStaff() throws Exception {
@ -62,8 +70,13 @@ class StaffControllerIntegrationTests {
@Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
void addStaff() throws Exception {
// Needs to be updated if findAll() returns something useful
assertThat(staffManagement.findAll().stream())
.extracting("name")
.doesNotContain("Karl Baum");
mvc.perform(createStaff).andExpect(redirectedUrl("/staff"));
assertThat(staffManagement.findAll().stream())
.extracting("name")
.contains("Karl Baum");
}
@Test
@ -81,10 +94,13 @@ class StaffControllerIntegrationTests {
@Test
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
void removeStaff() throws Exception {
assertThat(staffManagement.findAll().stream())
.extracting("name")
.contains("Dieter Baum");
mvc.perform(post("/staff/remove").param("id", defaultEmployeeId.toString()));
// this should be replaced once we have proper access to all employees
mvc.perform(get("/staff/edit/" + defaultEmployeeId.toString()))
.andExpect(status().isInternalServerError());
assertThat(staffManagement.findAll().stream())
.extracting("name")
.doesNotContain("Dieter Baum");
}
@Test
@ -100,7 +116,7 @@ class StaffControllerIntegrationTests {
mvc.perform(get("/staff"))
.andExpect(status().is3xxRedirection())
.andExpect(header().string(HttpHeaders.LOCATION, endsWith("/login")));
mvc.perform(get("/staff/edit/1"))
mvc.perform(get("/staff/edit/" + defaultEmployeeId))
.andExpect(status().is3xxRedirection())
.andExpect(header().string(HttpHeaders.LOCATION, endsWith("/login")));
}