mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add missing order tests
This commit is contained in:
parent
1f5b897c2b
commit
e6542dce7a
|
@ -349,6 +349,7 @@ public class OrderController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/orders/calender")
|
@GetMapping("/orders/calender")
|
||||||
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
public String calender(Model model) {
|
public String calender(Model model) {
|
||||||
ArrayList<ArrayList<String>> datesOfMonth = new ArrayList<ArrayList<String>>(28);
|
ArrayList<ArrayList<String>> datesOfMonth = new ArrayList<ArrayList<String>>(28);
|
||||||
LocalDateTime startDateTime = LocalDateTime.now();
|
LocalDateTime startDateTime = LocalDateTime.now();
|
||||||
|
|
|
@ -39,6 +39,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.salespointframework.core.Currencies.EURO;
|
import static org.salespointframework.core.Currencies.EURO;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
|
@ -83,8 +84,8 @@ public class OrderControllerIntegrationTests {
|
||||||
|
|
||||||
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,
|
||||||
LocalDateTime.of(2023, 12, 23, 10, 0),
|
LocalDateTime.now(),
|
||||||
LocalDateTime.of(2023, 12, 24, 10, 0));
|
LocalDateTime.now().plusDays(1L));
|
||||||
myCart.addOrUpdateItem(inventory.findAll().stream().findFirst().get().getProduct(), Quantity.of(1));
|
myCart.addOrUpdateItem(inventory.findAll().stream().findFirst().get().getProduct(), Quantity.of(1));
|
||||||
|
|
||||||
myOrder = new CustomOrder(myUser.getId(), myCart);
|
myOrder = new CustomOrder(myUser.getId(), myCart);
|
||||||
|
@ -134,17 +135,39 @@ public class OrderControllerIntegrationTests {
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
void adminViewsOrderByDate() throws Exception {
|
void adminViewsOrderByDate() throws Exception {
|
||||||
mvc.perform(get("/allOrders/2023-12-23"))
|
mvc.perform(get("/allOrders/" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE)))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(containsString("Menge")))
|
.andExpect(content().string(containsString("Menge")))
|
||||||
.andExpect(model().attributeExists("orders"));
|
.andExpect(model().attributeExists("orders"));
|
||||||
|
|
||||||
mvc.perform(get("/allOrders/2023-10-12"))
|
mvc.perform(get("/allOrders/" + LocalDateTime.now().plusDays(10L).format(DateTimeFormatter.ISO_DATE)))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().string(not(containsString("Menge"))))
|
.andExpect(content().string(not(containsString("Menge"))))
|
||||||
.andExpect(model().attributeExists("orders"));
|
.andExpect(model().attributeExists("orders"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
|
void adminViewsOrderByDateAndStatus() throws Exception {
|
||||||
|
mvc.perform(get("/allOrders").param("orderStatus", myOrder.getOrderStatus().toString()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString(myUser.getId().toString())));
|
||||||
|
|
||||||
|
mvc.perform(get("/allOrders/" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE)).param("orderStatus", myOrder.getOrderStatus().toString()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString(myUser.getId().toString())));
|
||||||
|
|
||||||
|
mvc.perform(get("/allOrders/" + LocalDateTime.now().plusDays(10L).format(DateTimeFormatter.ISO_DATE)).param("orderStatus", "CANCELED"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(not(containsString(myUser.getId().toString()))));
|
||||||
|
|
||||||
|
mvc.perform(get("/allOrders").param("orderStatus", "CANCELED"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(not(containsString(myUser.getId().toString()))));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
|
@ -200,17 +223,20 @@ public class OrderControllerIntegrationTests {
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void userCheckOut() throws Exception {
|
void emptyCartCheckOut() throws Exception {
|
||||||
Product product = inventory.findAll().stream().findFirst().get().getProduct();
|
|
||||||
mvc.perform(post("/event/addProduct")
|
|
||||||
.param("pid", product.getId().toString())
|
|
||||||
.param("number", "2"));
|
|
||||||
|
|
||||||
mvc.perform(post("/event/checkout"))
|
mvc.perform(post("/event/checkout"))
|
||||||
.andExpect(status().is3xxRedirection())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(redirectedUrl("/event"));
|
.andExpect(redirectedUrl("/event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
|
void changeOrderType() throws Exception {
|
||||||
|
mvc.perform(post("/event/changeOrderType").param("type", "EVENT_CATERING"))
|
||||||
|
.andExpect(status().is3xxRedirection())
|
||||||
|
.andExpect(redirectedUrl("/event"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
|
@ -220,6 +246,13 @@ public class OrderControllerIntegrationTests {
|
||||||
.andExpect(redirectedUrl("/event"));
|
.andExpect(redirectedUrl("/event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
|
void removeWrongEmployee() throws Exception {
|
||||||
|
mvc.perform(post("/event/removeEmployee").param("sid", "1234321234321"))
|
||||||
|
.andExpect(content().string(containsString("Fehler")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void addWrongProduct() throws Exception {
|
void addWrongProduct() throws Exception {
|
||||||
|
@ -236,6 +269,7 @@ public class OrderControllerIntegrationTests {
|
||||||
.andExpect(content().string(not(containsString(wrongProduct.getName()))));
|
.andExpect(content().string(not(containsString(wrongProduct.getName()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
void customerViewsInvoice() throws Exception {
|
void customerViewsInvoice() throws Exception {
|
||||||
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice").with(user("andi").roles("CUSTOMER")))
|
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice").with(user("andi").roles("CUSTOMER")))
|
||||||
|
@ -246,19 +280,26 @@ public class OrderControllerIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
void wrongUserViewsInvoice() throws Exception {
|
||||||
void adminViewsInvoice() throws Exception {
|
userAccountManagement.create("peter", Password.UnencryptedPassword.of("123"), Role.of("CUSTOMER"));
|
||||||
mvc.perform(MockMvcRequestBuilders.get("/myOrders/" + myOrder.getId().toString() + "/invoice"))
|
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice").with(user("peter").roles("CUSTOMER")))
|
||||||
.andExpect(status().isOk())
|
.andExpect(redirectedUrl("/unauthorized"));
|
||||||
.andExpect(content().string(containsString("Beschreibung")))
|
|
||||||
.andExpect(model().attributeExists("order"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
void displayStaff() throws Exception {
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice")
|
void wrongUserViewsCalender() throws Exception {
|
||||||
.param("sid", myEmployee.getId().toString()));
|
mvc.perform(get("/orders/calender"))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
|
void adminViewsCalender() throws Exception {
|
||||||
|
mvc.perform(get("/orders/calender"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString(myOrder.getId().toString())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,23 +96,6 @@ public class OrderControllerUnitTests {
|
||||||
).stream().toList()).hasSize(1);
|
).stream().toList()).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(4)
|
|
||||||
@Disabled // because Spring does shit that I don't understand
|
|
||||||
void freeAmountInInterval() {
|
|
||||||
myProduct = (Rentable) inventory.findAll()
|
|
||||||
.filter(item -> item.getProduct().getName().equals("Kerze Rot"))
|
|
||||||
.stream().findFirst().get().getProduct();
|
|
||||||
|
|
||||||
assertThat(OrderController.findFreeAmountInInterval(
|
|
||||||
myProduct,
|
|
||||||
LocalDateTime.of(2023, 12, 11, 0, 0),
|
|
||||||
LocalDateTime.of(2023, 12, 11, 23, 0),
|
|
||||||
inventory,
|
|
||||||
customOrderRepository)
|
|
||||||
).isEqualTo(Quantity.of(7));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(5)
|
@Order(5)
|
||||||
void ordersByOrderStatus() {
|
void ordersByOrderStatus() {
|
||||||
|
|
Loading…
Reference in a new issue