Add invoice test

This commit is contained in:
Paul Heimer 2023-12-12 16:12:08 +01:00 committed by Denis Natusch
parent f961071265
commit d6abbdcfa2
No known key found for this signature in database
GPG key ID: 5E57BD8EDACFA985

View file

@ -25,7 +25,9 @@ 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.annotation.DirtiesContext;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.hamcrest.Matchers.not;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
@ -61,6 +63,7 @@ public class OrderControllerIntegrationTests {
UserAccount admin;
CustomCart myCart;
Employee myEmployee;
CustomOrder myOrder;
@BeforeEach
void setUp() {
@ -83,8 +86,9 @@ public class OrderControllerIntegrationTests {
LocalDateTime.of(2023, 12, 24, 10, 0));
myCart.addOrUpdateItem(inventory.findAll().stream().findFirst().get().getProduct(), Quantity.of(1));
CustomOrder myOrder = new CustomOrder(myUser.getId(), myCart);
myOrder = new CustomOrder(myUser.getId(), myCart);
myCart.addItemsTo(myOrder);
myCart.addStaffTo(myOrder);
orderManagement.payOrder(myOrder);
orderManagement.completeOrder(myOrder);
@ -92,6 +96,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
void customerViewsOrder() throws Exception {
mvc.perform(get("/myOrders").with(user("andi").roles("CUSTOMER")))
.andExpect(status().isOk())
@ -107,6 +112,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "admin", roles = "ADMIN")
void adminViewsOrder() throws Exception {
mvc.perform(get("/allOrders"))
@ -119,6 +125,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "admin", roles = "ADMIN")
void adminViewsOrderByDate() throws Exception {
mvc.perform(get("/allOrders/2023-12-23"))
@ -133,6 +140,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "admin", roles = "ADMIN")
void adminRemovesOrder() throws Exception {
mvc.perform(post("/allOrders/remove")
@ -142,6 +150,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "andi", roles = "CUSTOMER")
void userPlansEvent() throws Exception {
mvc.perform(get("/event"))
@ -158,6 +167,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "andi", roles = "CUSTOMER")
void userRemovesItemFromCart() throws Exception {
CartItem myItem = myCart.toList().get(0);
@ -169,6 +179,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "andi", roles = "CUSTOMER")
void userChangesDate() throws Exception {
mvc.perform(post("/event/changeDate")
@ -181,6 +192,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "andi", roles = "CUSTOMER")
void userCheckOut() throws Exception {
Product product = inventory.findAll().stream().findFirst().get().getProduct();
@ -194,6 +206,7 @@ public class OrderControllerIntegrationTests {
}
@Test
@DirtiesContext
@WithMockUser(username = "andi", roles = "CUSTOMER")
void addEmployee() throws Exception {
mvc.perform(post("/event/addEmployee")
@ -217,4 +230,29 @@ public class OrderControllerIntegrationTests {
.andExpect(content().string(not(containsString(wrongProduct.getName()))));
}
@DirtiesContext
void customerViewsInvoice() throws Exception {
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice").with(user("andi").roles("CUSTOMER")))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Beschreibung")))
.andExpect(model().attributeExists("order"));
}
@Test
@DirtiesContext
@WithMockUser(username = "admin", roles = "ADMIN")
void adminViewsInvoice() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/myOrders/" + myOrder.getId().toString() + "/invoice"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Beschreibung")))
.andExpect(model().attributeExists("order"));
}
@Test
@DirtiesContext
void displayStaff() throws Exception {
mvc.perform(get("/myOrders/" + myOrder.getId().toString() + "/invoice")
.param("sid", myEmployee.getId().toString()));
}
}