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:
Denis Natusch 2023-12-07 20:14:47 +01:00
parent 56f212396b
commit 8df82fec85
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985
2 changed files with 56 additions and 0 deletions

View file

@ -72,6 +72,7 @@ public class OrderControllerIntegrationTests {
myUser = userAccountManagement.findByUsername("andi").get();
admin = userAccountManagement.findByUsername("admin").get();
orderManagement.findAll(Pageable.unpaged()).forEach(orderManagement::delete);
if (orderManagement.findAll(Pageable.unpaged()).stream().findAny().isEmpty()) {
myCart = new CustomCart(OrderType.EVENT_CATERING,

View file

@ -3,6 +3,7 @@ package catering.staff;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.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.status;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.Set;
import org.javamoney.moneta.Money;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
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.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
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
@SpringBootTest
class StaffControllerIntegrationTests {
@ -38,13 +52,40 @@ class StaffControllerIntegrationTests {
@Autowired
private StaffManagement staffManagement;
@Autowired
private OrderManagement<CustomOrder> orderManagement;
@Autowired
private UserManagement userManagement;
@Autowired
private UserAccountManagement userAccountManagement;
Employee defaultEmployee;
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
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)));
defaultEmployeeId = defaultEmployee.getId();
if (userAccountManagement.findByUsername("hemming").isEmpty()) {
userManagement.createCustomer("hemming", "Nürnberger Platz", "123", "Hemming Quark");
}
defaultCustomer = userManagement.getUserByName("hemming").get();
}
@AfterEach
@ -158,6 +199,20 @@ class StaffControllerIntegrationTests {
.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
@WithMockUser(username = "dieter", password = "123", roles = "CUSTOMER")
void refuseCustomer() throws Exception {