mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Fix Me
The order and staff integration tests are strongly influencing each other. For example just adding one order breaks basiclly every OrderControllerIntegrationTest.
This commit is contained in:
parent
56f212396b
commit
8df82fec85
|
@ -72,6 +72,7 @@ public class OrderControllerIntegrationTests {
|
||||||
myUser = userAccountManagement.findByUsername("andi").get();
|
myUser = userAccountManagement.findByUsername("andi").get();
|
||||||
admin = userAccountManagement.findByUsername("admin").get();
|
admin = userAccountManagement.findByUsername("admin").get();
|
||||||
|
|
||||||
|
orderManagement.findAll(Pageable.unpaged()).forEach(orderManagement::delete);
|
||||||
|
|
||||||
if (orderManagement.findAll(Pageable.unpaged()).stream().findAny().isEmpty()) {
|
if (orderManagement.findAll(Pageable.unpaged()).stream().findAny().isEmpty()) {
|
||||||
myCart = new CustomCart(OrderType.EVENT_CATERING,
|
myCart = new CustomCart(OrderType.EVENT_CATERING,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package catering.staff;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
import static org.hamcrest.CoreMatchers.endsWith;
|
import static org.hamcrest.CoreMatchers.endsWith;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.salespointframework.core.Currencies.EURO;
|
import static org.salespointframework.core.Currencies.EURO;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
@ -11,19 +12,32 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.YearMonth;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.javamoney.moneta.Money;
|
import org.javamoney.moneta.Money;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.salespointframework.order.OrderManagement;
|
||||||
|
import org.salespointframework.useraccount.UserAccountManagement;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.security.test.context.support.WithAnonymousUser;
|
import org.springframework.security.test.context.support.WithAnonymousUser;
|
||||||
import org.springframework.security.test.context.support.WithMockUser;
|
import org.springframework.security.test.context.support.WithMockUser;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
|
import catering.order.CustomCart;
|
||||||
|
import catering.order.CustomOrder;
|
||||||
|
import catering.order.OrderType;
|
||||||
|
import catering.users.User;
|
||||||
|
import catering.users.UserManagement;
|
||||||
|
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class StaffControllerIntegrationTests {
|
class StaffControllerIntegrationTests {
|
||||||
|
@ -38,13 +52,40 @@ class StaffControllerIntegrationTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StaffManagement staffManagement;
|
private StaffManagement staffManagement;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderManagement<CustomOrder> orderManagement;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserManagement userManagement;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserAccountManagement userAccountManagement;
|
||||||
|
|
||||||
Employee defaultEmployee;
|
Employee defaultEmployee;
|
||||||
Long defaultEmployeeId;
|
Long defaultEmployeeId;
|
||||||
|
User defaultCustomer;
|
||||||
|
Employee orderEmployee;
|
||||||
|
CustomOrder defaultStaffOrder;
|
||||||
|
|
||||||
|
CustomOrder createCustomOrder(LocalDateTime start, LocalDateTime end, Set<Employee> staff) {
|
||||||
|
CustomOrder order = orderManagement.save(new CustomOrder(defaultCustomer.getUserAccount().getId(),
|
||||||
|
new CustomCart(OrderType.EVENT_CATERING, start, end)));
|
||||||
|
staff.forEach(order::addEmployee);
|
||||||
|
return orderManagement.save(order);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
|
orderManagement.findAll(Pageable.unpaged()).forEach(orderManagement::delete);
|
||||||
|
staffManagement.findAll().forEach(e -> staffManagement.delete(e.getId()));
|
||||||
|
|
||||||
defaultEmployee = staffManagement.save(new Employee("Dieter Baum", JobType.COOK, Money.of(0, EURO)));
|
defaultEmployee = staffManagement.save(new Employee("Dieter Baum", JobType.COOK, Money.of(0, EURO)));
|
||||||
defaultEmployeeId = defaultEmployee.getId();
|
defaultEmployeeId = defaultEmployee.getId();
|
||||||
|
|
||||||
|
if (userAccountManagement.findByUsername("hemming").isEmpty()) {
|
||||||
|
userManagement.createCustomer("hemming", "Nürnberger Platz", "123", "Hemming Quark");
|
||||||
|
}
|
||||||
|
defaultCustomer = userManagement.getUserByName("hemming").get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
@ -158,6 +199,20 @@ class StaffControllerIntegrationTests {
|
||||||
.containsExactly("Dieter Baum", JobType.COOK);
|
.containsExactly("Dieter Baum", JobType.COOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockUser(username = "admin", password = "admin", roles = "ADMIN")
|
||||||
|
void viewHoursesOfWork() throws Exception {
|
||||||
|
orderEmployee = staffManagement.save(new Employee("Tyler Baum", JobType.COOK, Money.of(10, EURO)));
|
||||||
|
defaultStaffOrder = createCustomOrder(LocalDateTime.of(2023, 12, 20, 10, 0),
|
||||||
|
LocalDateTime.of(2023, 12, 20, 21, 0), Set.of(orderEmployee));
|
||||||
|
|
||||||
|
mvc.perform(get("/staff"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("11.0")));
|
||||||
|
assertThat(staffManagement.getWorkingHoursByEmployee(orderEmployee, YearMonth.of(2023, 12))).isEqualTo(11);
|
||||||
|
assertThat(staffManagement.getWorkingHoursByEmployee(orderEmployee, YearMonth.of(2023, 11))).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "dieter", password = "123", roles = "CUSTOMER")
|
@WithMockUser(username = "dieter", password = "123", roles = "CUSTOMER")
|
||||||
void refuseCustomer() throws Exception {
|
void refuseCustomer() throws Exception {
|
||||||
|
|
Loading…
Reference in a new issue