diff --git a/backend/app/src/main/java/eu/viandeendirect/common/NotificationService.java b/backend/app/src/main/java/eu/viandeendirect/common/NotificationService.java index 03b6d32..724468c 100644 --- a/backend/app/src/main/java/eu/viandeendirect/common/NotificationService.java +++ b/backend/app/src/main/java/eu/viandeendirect/common/NotificationService.java @@ -24,7 +24,7 @@ public interface NotificationService { String getBodyTemplatePath(); - default public void notify(T object) { + default void notify(T object) { String recipient = getRecipient(object); String subject = getSubject(object); String body = getBody(object); diff --git a/backend/app/src/main/java/eu/viandeendirect/domains/order/OrderNotificationToCustomerService.java b/backend/app/src/main/java/eu/viandeendirect/domains/order/OrderNotificationToCustomerService.java index b6b02b6..9672711 100644 --- a/backend/app/src/main/java/eu/viandeendirect/domains/order/OrderNotificationToCustomerService.java +++ b/backend/app/src/main/java/eu/viandeendirect/domains/order/OrderNotificationToCustomerService.java @@ -45,7 +45,7 @@ public Object[] getTemplateValues(Order order) { Object[] bodyTemplateValues = { order.getId(), viandeEnDirectConfiguration.getCustomerFrontendUrl(), - order.getItems().stream().mapToDouble(item -> item.getQuantity() * item.getUnitPrice()).sum(), + order.getItems().stream().mapToDouble(item -> item.getQuantity() * item.getUnitPrice() * item.getPackageLot().getNetWeight()).sum(), order.getItems().stream().mapToDouble(item -> item.getQuantity() * item.getPackageLot().getNetWeight()).sum(), sale.getDeliveryStart(), sale.getDeliveryStop(), diff --git a/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrderNotificationToProducerService_notify.java b/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrderNotificationToProducerService_notify.java index 18064b9..ae4de49 100644 --- a/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrderNotificationToProducerService_notify.java +++ b/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrderNotificationToProducerService_notify.java @@ -74,7 +74,7 @@ void should_send_a_mail_correctly() { mailBodyCaptor.capture()); String mailBody = mailBodyCaptor.getValue(); String cleanMailBody = mailBody.replaceAll("( {4})*", ""); - assertThat(cleanMailBody).isEqualTo(String.format("
La commande n° 1 a été enregistrée sur ViandeEnDirect.eu.
",viandeEnDirectConfiguration.getProducerFrontendUrl())); + assertThat(cleanMailBody).isEqualTo(String.format("
La commande n° %s a été enregistrée sur ViandeEnDirect.eu.
",order.getId(), viandeEnDirectConfiguration.getProducerFrontendUrl())); } } \ No newline at end of file diff --git a/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrder_createOrderPayment.java b/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrder_createOrderPayment.java index f7ff643..b616364 100644 --- a/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrder_createOrderPayment.java +++ b/backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrder_createOrderPayment.java @@ -3,6 +3,7 @@ import com.stripe.exception.StripeException; import eu.viandeendirect.domains.payment.StripeService; import eu.viandeendirect.domains.production.PackageLotRepository; +import eu.viandeendirect.domains.sale.SaleRepository; import eu.viandeendirect.model.*; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -16,9 +17,6 @@ import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit.jupiter.SpringExtension; -import java.util.Optional; - -import static eu.viandeendirect.model.OrderStatus.PAYMENT_ABORTED; import static eu.viandeendirect.model.OrderStatus.PAYMENT_PENDING; import static java.util.regex.Pattern.*; import static org.assertj.core.api.Assertions.assertThat; @@ -45,6 +43,9 @@ public class TestOrder_createOrderPayment { @Autowired private OrderRepository orderRepository; + @Autowired + private SaleRepository saleRepository; + @Test void should_persist_order_in_database() throws StripeException { // given @@ -58,6 +59,7 @@ void should_persist_order_in_database() throws StripeException { PackageLot honeyLotMielDeColza = orderTestService.getHoneyPackageLot(honeyProducer, "miel de colza", 5, 0); Order order = orderTestService.createOrder(beefLotSteaksVache, beefLotCoteVeau, honeyLotMielDeSapin, honeyLotMielDeColza, customer); + saleRepository.save(order.getSale()); var stripePayment = new StripePayment(); stripePayment.setCheckoutSessionId("test_success"); diff --git a/backend/app/src/test/java/eu/viandeendirect/domains/payment/TestStripeEventHandler_handleStripeAccountEvent.java b/backend/app/src/test/java/eu/viandeendirect/domains/payment/TestStripeEventHandler_handleStripeAccountEvent.java index 292ba2c..21ac939 100644 --- a/backend/app/src/test/java/eu/viandeendirect/domains/payment/TestStripeEventHandler_handleStripeAccountEvent.java +++ b/backend/app/src/test/java/eu/viandeendirect/domains/payment/TestStripeEventHandler_handleStripeAccountEvent.java @@ -5,9 +5,8 @@ import com.stripe.exception.StripeException; import com.stripe.model.Event; import com.stripe.model.checkout.Session; -import eu.viandeendirect.domains.order.OrderRepository; -import eu.viandeendirect.domains.order.OrderService; -import eu.viandeendirect.domains.order.OrderTestService; +import eu.viandeendirect.domains.order.*; +import eu.viandeendirect.domains.sale.SaleRepository; import eu.viandeendirect.model.*; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,17 +42,29 @@ public class TestStripeEventHandler_handleStripeAccountEvent { @MockBean private StripeService stripeService; + @MockBean + private OrderNotificationToCustomerService orderNotificationToCustomerService; + + @MockBean + private OrderNotificationToProducerService orderNotificationToProducerService; + @Autowired private OrderRepository orderRepository; + @Autowired + private SaleRepository saleRepository; + @Test void should_change_order_status_after_payment_is_completed() throws StripeException { // given Order order = orderTestService.createOrder(); + saleRepository.save(order.getSale()); var stripePayment = new StripePayment(); stripePayment.setCheckoutSessionId("stripe-id-success"); when(stripeService.createPayment(any())).thenReturn(stripePayment); + doNothing().when(orderNotificationToCustomerService).notify(any()); + doNothing().when(orderNotificationToProducerService).notify(any()); orderService.createOrderPayment(order); Session checkoutSession = new Session(); @@ -80,6 +91,7 @@ void should_change_order_status_after_payment_is_completed() throws StripeExcept void should_change_order_status_after_payment_is_aborted() throws StripeException { // given Order order = orderTestService.createOrder(); + saleRepository.save(order.getSale()); var stripePayment = new StripePayment(); stripePayment.setCheckoutSessionId("stripe-id-aborted");