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.