From 699db13864679c1de4c48781a4b0f9bad7da236e Mon Sep 17 00:00:00 2001 From: Mathis Kral Date: Tue, 12 Dec 2023 14:02:40 +0100 Subject: [PATCH] Add test for wrong addProduct request This works on #100 --- .../order/OrderControllerIntegrationTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/catering/order/OrderControllerIntegrationTests.java b/src/test/java/catering/order/OrderControllerIntegrationTests.java index 1666f1d..84133f5 100644 --- a/src/test/java/catering/order/OrderControllerIntegrationTests.java +++ b/src/test/java/catering/order/OrderControllerIntegrationTests.java @@ -22,6 +22,7 @@ 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.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; @@ -200,4 +201,20 @@ public class OrderControllerIntegrationTests { .andExpect(redirectedUrl("/event")); } + @Test + @WithMockUser(username = "andi", roles = "CUSTOMER") + void addWrongProduct() throws Exception { + myCart.setOrderType(OrderType.RENT_A_COOK); + Product wrongProduct = inventory.findAll(Pageable.unpaged()).stream() + .filter(item -> item.getProduct().getCategories().stream() + .noneMatch(c -> c.equals(myCart.getOrderType().toString()))) + .findFirst().get().getProduct(); + + mvc.perform(post("/event/addProduct") + .param("pid", wrongProduct.getId().toString()) + .param("number", "1")) + .andExpect(redirectedUrl("/event")) + .andExpect(content().string(not(containsString(wrongProduct.getName())))); + } + }