Add test for wrong addProduct request

This works on #100
This commit is contained in:
Mathis Kral 2023-12-12 14:02:40 +01:00 committed by Mathis
parent 44c9eb8f3a
commit 699db13864

View file

@ -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()))));
}
}