From 4c83c661fe2c473cc791161b7562c60f10e99d3c Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 24 Nov 2023 16:58:57 +0100 Subject: [PATCH] Test inventory error handling --- .../InventoryControllerIntegrationTests.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java b/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java index 8e702c5..fd21002 100644 --- a/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java +++ b/src/test/java/catering/inventory/InventoryControllerIntegrationTests.java @@ -19,6 +19,7 @@ package catering.inventory; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.endsWith; import static org.salespointframework.core.Currencies.EURO; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -159,6 +160,42 @@ class InventoryControllerIntegrationTests { Money.of(0.01, EURO), hasPromotionPrice ? null : Money.of(0.01, EURO)); } + @Test + @WithMockUser(username = "admin", roles = "ADMIN") + void invalidAddReturnsNiceError() throws Exception { + mvc.perform(post("/inventory/add") + .param("type", "CONSUMABLE") + .param("name", "") + .param("quantity", "10") + .param("wholesalePrice", "1.00") + .param("retailPrice", "2.00")) + .andExpect(content().string(containsString("Ungültiger Name"))); + } + + @Test + @WithMockUser(username = "admin", roles = "ADMIN") + void missingRetailPriceIsNoError() throws Exception { + mvc.perform(post("/inventory/add") + .param("type", "CONSUMABLE") + .param("name", "MOCK") + .param("quantity", "10") + .param("wholesalePrice", "1.00") + .param("retailPrice", "2.00")) + .andExpect(content().string(not(containsString("Ungültiger Angebotspreis")))); + } + + @Test + @WithMockUser(username = "admin", roles = "ADMIN") + void invalidEditReturnsNiceError() throws Exception { + mvc.perform(post("/inventory/edit/" + anyPid) + .param("type", "CONSUMABLE") + .param("name", "") + .param("quantity", "10") + .param("wholesalePrice", "1.00") + .param("retailPrice", "2.00")) + .andExpect(content().string(containsString("Ungültiger Name"))); + } + /** * Helper function for asserting that protected endpoints are not accessible by * unauthentificated users.