-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caf38f1
commit 0204641
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
backend/app/src/main/java/eu/viandeendirect/domains/order/OrderAmountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package eu.viandeendirect.domains.order; | ||
|
||
import eu.viandeendirect.model.Order; | ||
import eu.viandeendirect.model.OrderItem; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class OrderAmountService { | ||
public float calculateTotalOrderAmount(Order order) { | ||
float totalAmount = 0; | ||
for (OrderItem orderItem : order.getItems()) { | ||
totalAmount += orderItem.getUnitPrice() * orderItem.getQuantity() * orderItem.getPackageLot().getNetWeight(); | ||
} | ||
return totalAmount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
backend/app/src/test/java/eu/viandeendirect/domains/order/TestOrderAmountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package eu.viandeendirect.domains.order; | ||
|
||
|
||
import eu.viandeendirect.model.BeefProduction; | ||
import eu.viandeendirect.model.Order; | ||
import eu.viandeendirect.model.PackageLot; | ||
import eu.viandeendirect.model.Sale; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.Map; | ||
|
||
import static eu.viandeendirect.domains.order.OrderTestUtils.*; | ||
|
||
class TestOrderAmountService { | ||
@Test | ||
void should_return_the_right_amount() { | ||
// given | ||
BeefProduction beefProduction = getBeefProduction(); | ||
PackageLot packageLot1 = getPackageLot(1, beefProduction, "Colis tradition", "Un colis avec plein de trucs délicieux", 10f); | ||
PackageLot packageLot2 = getPackageLot(2, beefProduction, "Filet", "Un colis avec plein de trucs bons", 0.5f); | ||
|
||
Sale sale = new Sale(); | ||
sale.setId(123); | ||
sale.setDeliveryStart(OffsetDateTime.parse("2021-09-30T15:30:00+01:00")); | ||
|
||
Order order = createOrder(123, createCustomer("Valentine", "DURAND", "0601020304"), Map.of(packageLot1, 1, packageLot2, 2)); | ||
OrderAmountService orderAmountService = new OrderAmountService(); | ||
|
||
// when | ||
float amount = orderAmountService.calculateTotalOrderAmount(order); | ||
|
||
// then | ||
Assertions.assertThat(amount).isEqualTo(110f); | ||
} | ||
|
||
} |