Skip to content

Commit

Permalink
Montant erronné si quantité inférieure à 1kg #52
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Dec 2, 2024
1 parent e8815cb commit ca97b3b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface StripePaymentManager {
void processPaymentValidation(Order order);

default SessionCreateParams.LineItem getLineItem(OrderItem orderItem) {
long unitAmount = orderItem.getUnitPrice().longValue() * orderItem.getPackageLot().getNetWeight().longValue() * 100;
long unitAmount = getUnitAmount(orderItem);
long quantity = orderItem.getQuantity().longValue();
LOGGER.debug("creating Stripe payment's line item for order item {} x{} for {} euro-cents each", orderItem.getPackageLot().getLabel(), quantity, unitAmount);
return SessionCreateParams.LineItem.builder()
Expand All @@ -35,4 +35,8 @@ default SessionCreateParams.LineItem getLineItem(OrderItem orderItem) {
.build();
}

default long getUnitAmount(OrderItem orderItem) {
return Float.valueOf(orderItem.getUnitPrice() * orderItem.getPackageLot().getNetWeight() * 100).longValue();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package eu.viandeendirect.domains.payment;

import eu.viandeendirect.model.OrderItem;
import eu.viandeendirect.model.PackageLot;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.*;

class TestStripePaymentManager_getUnitAmount {

@Test
void testGetUnitAmount() {
// given
StripePaymentManager stripePaymentManagerImpl = Mockito.mock(StripePaymentManager.class);
Mockito.doCallRealMethod().when(stripePaymentManagerImpl).getUnitAmount(Mockito.any());
PackageLot packageLot = new PackageLot();
packageLot.setNetWeight(0.2f);
OrderItem orderItem = new OrderItem();
orderItem.setUnitPrice(0.2f);
orderItem.setPackageLot(packageLot);

// when
long unitAmount = stripePaymentManagerImpl.getUnitAmount(orderItem);

// then
Assertions.assertThat(unitAmount).isEqualTo(4);
}

}

0 comments on commit ca97b3b

Please sign in to comment.