mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add invoice test
This commit is contained in:
parent
f961071265
commit
d6abbdcfa2
|
@ -25,7 +25,9 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.security.test.context.support.WithMockUser;
|
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.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
|
||||||
|
@ -61,6 +63,7 @@ public class OrderControllerIntegrationTests {
|
||||||
UserAccount admin;
|
UserAccount admin;
|
||||||
CustomCart myCart;
|
CustomCart myCart;
|
||||||
Employee myEmployee;
|
Employee myEmployee;
|
||||||
|
CustomOrder myOrder;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
|
@ -83,8 +86,9 @@ public class OrderControllerIntegrationTests {
|
||||||
LocalDateTime.of(2023, 12, 24, 10, 0));
|
LocalDateTime.of(2023, 12, 24, 10, 0));
|
||||||
myCart.addOrUpdateItem(inventory.findAll().stream().findFirst().get().getProduct(), Quantity.of(1));
|
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.addItemsTo(myOrder);
|
||||||
|
myCart.addStaffTo(myOrder);
|
||||||
|
|
||||||
orderManagement.payOrder(myOrder);
|
orderManagement.payOrder(myOrder);
|
||||||
orderManagement.completeOrder(myOrder);
|
orderManagement.completeOrder(myOrder);
|
||||||
|
@ -92,6 +96,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
void customerViewsOrder() throws Exception {
|
void customerViewsOrder() throws Exception {
|
||||||
mvc.perform(get("/myOrders").with(user("andi").roles("CUSTOMER")))
|
mvc.perform(get("/myOrders").with(user("andi").roles("CUSTOMER")))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
@ -107,6 +112,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
void adminViewsOrder() throws Exception {
|
void adminViewsOrder() throws Exception {
|
||||||
mvc.perform(get("/allOrders"))
|
mvc.perform(get("/allOrders"))
|
||||||
|
@ -119,6 +125,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
void adminViewsOrderByDate() throws Exception {
|
void adminViewsOrderByDate() throws Exception {
|
||||||
mvc.perform(get("/allOrders/2023-12-23"))
|
mvc.perform(get("/allOrders/2023-12-23"))
|
||||||
|
@ -133,6 +140,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "admin", roles = "ADMIN")
|
@WithMockUser(username = "admin", roles = "ADMIN")
|
||||||
void adminRemovesOrder() throws Exception {
|
void adminRemovesOrder() throws Exception {
|
||||||
mvc.perform(post("/allOrders/remove")
|
mvc.perform(post("/allOrders/remove")
|
||||||
|
@ -142,6 +150,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void userPlansEvent() throws Exception {
|
void userPlansEvent() throws Exception {
|
||||||
mvc.perform(get("/event"))
|
mvc.perform(get("/event"))
|
||||||
|
@ -158,6 +167,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void userRemovesItemFromCart() throws Exception {
|
void userRemovesItemFromCart() throws Exception {
|
||||||
CartItem myItem = myCart.toList().get(0);
|
CartItem myItem = myCart.toList().get(0);
|
||||||
|
@ -169,6 +179,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void userChangesDate() throws Exception {
|
void userChangesDate() throws Exception {
|
||||||
mvc.perform(post("/event/changeDate")
|
mvc.perform(post("/event/changeDate")
|
||||||
|
@ -181,6 +192,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void userCheckOut() throws Exception {
|
void userCheckOut() throws Exception {
|
||||||
Product product = inventory.findAll().stream().findFirst().get().getProduct();
|
Product product = inventory.findAll().stream().findFirst().get().getProduct();
|
||||||
|
@ -194,6 +206,7 @@ public class OrderControllerIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||||
void addEmployee() throws Exception {
|
void addEmployee() throws Exception {
|
||||||
mvc.perform(post("/event/addEmployee")
|
mvc.perform(post("/event/addEmployee")
|
||||||
|
@ -217,4 +230,29 @@ public class OrderControllerIntegrationTests {
|
||||||
.andExpect(content().string(not(containsString(wrongProduct.getName()))));
|
.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()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue