swt23w23/src/test/java/catering/order/OrderControllerUnitTests.java
Simon Bruder bac025fd0a
Make project REUSE compliant
This finally makes the licensing under AGPL-3.0-or-later explicit after
I got the okay from the kickstart source owners.

This also checks the REUSE compliance in a pre commit hook, and
therefore also in CI.
2023-12-11 17:59:14 +01:00

115 lines
3.2 KiB
Java

// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2023 swt23w23
package catering.order;
import catering.catalog.Rentable;
import org.junit.jupiter.api.*;
import org.salespointframework.inventory.UniqueInventory;
import org.salespointframework.inventory.UniqueInventoryItem;
import org.salespointframework.order.OrderManagement;
import org.salespointframework.quantity.Quantity;
import org.salespointframework.useraccount.UserAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Pageable;
import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.*;
@SpringBootTest
public class OrderControllerUnitTests {
@Autowired
UniqueInventory<UniqueInventoryItem> inventory;
@Autowired
OrderManagement<CustomOrder> orderManagement;
@Autowired
CustomOrderRepository customOrderRepository;
Rentable myProduct;
@BeforeEach
void setup() {
// because of FUUUUUUUN
if (!orderManagement.findAll(Pageable.unpaged()).isEmpty()) {
return;
}
// #1
CustomCart myCart = new CustomCart(
OrderType.EVENT_CATERING,
LocalDateTime.of(2023, 12, 11, 9, 0),
LocalDateTime.of(2023, 12, 13, 22, 0)
);
myProduct = (Rentable) inventory.findAll()
.filter(item -> item.getProduct().getName().equals("Kerze Rot"))
.stream().findFirst().get().getProduct();
myCart.addOrUpdateItem(myProduct, 3);
CustomOrder myOrder = new CustomOrder(UserAccount.UserAccountIdentifier.of("12345"), myCart);
myCart.addItemsTo(myOrder);
orderManagement.payOrder(myOrder);
orderManagement.completeOrder(myOrder);
// #2
myCart = new CustomCart(
OrderType.EVENT_CATERING,
LocalDateTime.of(2023, 12, 13, 9, 0),
LocalDateTime.of(2023, 12, 15, 22, 0)
);
myCart.addOrUpdateItem(myProduct, 4);
myOrder = new CustomOrder(UserAccount.UserAccountIdentifier.of("12345"), myCart);
myCart.addItemsTo(myOrder);
orderManagement.payOrder(myOrder);
orderManagement.completeOrder(myOrder);
}
@Test
@Order(1)
void thisShouldNeverFail() {
assertThat(orderManagement.findAll(Pageable.unpaged()).stream().count()).isEqualTo(2L);
}
@Test
@Order(2)
void correctSetup() {
assertThat(orderManagement.findAll(Pageable.unpaged()).stream().count()).isEqualTo(2L);
}
@Test
@Order(3)
void ordersByInterval() {
assertThat(customOrderRepository.findOrdersByInterval(
LocalDateTime.of(2023, 12, 2, 0, 0),
LocalDateTime.of(2024, 1, 1, 0, 0)
).stream().toList()).hasSize(2);
assertThat(customOrderRepository.findOrdersByInterval(
LocalDateTime.of(2023, 12, 11, 0, 0),
LocalDateTime.of(2023, 12, 11, 23, 0)
).stream().toList()).hasSize(1);
}
@Test
@Order(4)
@Disabled // because Spring does shit that I don't understand
void freeAmountInInterval() {
myProduct = (Rentable) inventory.findAll()
.filter(item -> item.getProduct().getName().equals("Kerze Rot"))
.stream().findFirst().get().getProduct();
assertThat(OrderController.findFreeAmountInInterval(
myProduct,
LocalDateTime.of(2023, 12, 11, 0, 0),
LocalDateTime.of(2023, 12, 11, 23, 0),
inventory,
customOrderRepository)
).isEqualTo(Quantity.of(7));
}
}