Skip to content

Commit

Permalink
add new test for calculator and comply to folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sf-afoliaco committed Oct 2, 2024
1 parent 83e4f91 commit cb0fa18
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 193 deletions.
180 changes: 0 additions & 180 deletions commerce/domain/inventory/CommerceInventoryServiceSample.cls

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
public class InventoryCartCalculatorSample extends CartExtension.InventoryCartCalculator {

public InventoryCartCalculatorSample() {
super();
}

/**
* @description Constructor used by unit tests only.
* @param apexExecutor Executor which executes various calculators. Can be used to stub calculation results or delegate calculations to actual Calculator. See <<CartCalculateExecutorMock>>.
*/
public InventoryCartCalculatorSample(CartExtension.CartCalculateExecutorMock apexExecutor) {
// Must call super constructor in order for provided Executor to be used for calculations
super(apexExecutor);
}

public virtual override void calculate(CartExtension.CartCalculateCalculatorRequest request) {

CartExtension.Cart cart = request.getCart();

if (cart.getStatus() != CartExtension.CartStatusEnum.CHECKOUT) {
return;
}

removeAllCVOsOfType(cart, CartExtension.CartValidationOutputTypeEnum.INVENTORY);
super.calculate(request);

}

private void removeAllCVOsOfType(CartExtension.Cart cart, CartExtension.CartValidationOutputTypeEnum type) {
CartExtension.CartValidationOutputList cartValidationOutputList = cart.getCartValidationOutputs();
for (Integer i = (cartValidationOutputList.size() - 1); i >= 0; i--) {
CartExtension.CartValidationOutput cvo = cartValidationOutputList.get(i);
if (cvo.getType() == type) {
cartValidationOutputList.remove(cvo);
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

1 comment on commit cb0fa18

@EduPech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I have a problem in the testUpsertReservation() method, when I do a deploy the commerce_inventory.UpsertItemReservationRequest itemRequest = new commerce_inventory.UpsertItemReservationRequest(double.valueOf('10.0'), Id.valueOf('0ghSG0000000JFbYAM'), Id .valueOf('0a9SG000003AfY1YAK'), Id.valueOf('01tSG000001NNgKYAW')); has an error that says:
Undefined constructor: [commerce_inventory.UpsertItemReservationRequest].<Constructor>(Double, Id, Id, Id) (6:71)
I tried to instance different the object but I keep getting the same error.
I also get other errors when I use other methods that use objects called Request at the end.

Please sign in to comment.