Test inventory error handling

This commit is contained in:
Simon Bruder 2023-11-24 16:58:57 +01:00
parent cbe7d14a64
commit 4c83c661fe
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -19,6 +19,7 @@ package catering.inventory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple; import static org.assertj.core.api.Assertions.tuple;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.endsWith;
import static org.salespointframework.core.Currencies.EURO; 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.get;
@ -159,6 +160,42 @@ class InventoryControllerIntegrationTests {
Money.of(0.01, EURO), hasPromotionPrice ? null : Money.of(0.01, EURO)); 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 * Helper function for asserting that protected endpoints are not accessible by
* unauthentificated users. * unauthentificated users.