Developer Preview
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
ISTEST
A utility class that can be only used when writing Apex tests. It allows you to get a CartExtension.Cart Apex object, similar to the one that would be sent by the extensibility framework.
global ACCOUNT_NAME → Stringglobal CARTITEM_NAME → Stringglobal CART_NAME → Stringglobal DELIVERYGROUP_NAME → Stringglobal WEBSTORE_NAME → StringAllows you to retrieve a CartExtension.Cart Apex object from a WebCart record ID.
| Param | Description |
|---|---|
cartRecordId | ID of the WebCart record to load as a CartExtension.Cart Apex object. |
| Type | Description |
|---|---|
Cart | CartExtension.Cart |
1static void testMyCustomCalculator() {
2 // Given
3 final String accountName = 'My Test Account';
4 final String webStoreName = 'My Test WebStore';
5 final String cartName = 'My Test Cart';
6 final Id personAccountRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId();
7 Schema.Account testAccount = new Schema.Account(LastName=accountName, RecordTypeId=personAccountRecordTypeId);
8 insert testAccount;
9 Schema.WebStore testWebStore = new Schema.WebStore(Name=webStoreName);
10 insert testWebStore;
11 Schema.Account account = [SELECT Id FROM Account WHERE id=:testAccount.Id LIMIT 1];
12 Schema.WebStore webStore = [SELECT Id FROM WebStore WHERE id=:testWebStore.Id LIMIT 1];
13 Schema.WebCart testCart = new WebCart(Name=cartName, WebStoreId=webStore.Id, AccountId=account.Id);
14 insert testCart;
15 Schema.WebCart cart = [SELECT Id FROM WebCart WHERE Name=:cartName LIMIT 1];
16 CartExtension.Cart cartObject = CartExtension.CartTestUtil.getCart(cart.Id);
17 CartExtension.CartCalculateCalculatorRequest request = new CartExtension.CartCalculateCalculatorRequest(cartObject);
18 MyCustomCalculator calculator = new MyCustomCalculator();
19 // When
20 Test.startTest();
21 calculator.calculate(request);
22 Test.stopTest();
23 // Then
24 // some assertions
25}Creates the necessary Account, WebStore (type B2B), WebCart, CartDeliveryGroup, and CartItem records and returns the corresponding CartExtension.Cart Apex object.
| Type | Description |
|---|---|
Cart | CartExtension.Cart |
1static void testMyCustomCalculator() {
2 // Given
3 CartExtension.Cart cartObject = CartExtension.CartTestUtil.createCart();
4 CartExtension.CartCalculateCalculatorRequest request = new CartExtension.CartCalculateCalculatorRequest(cartObject);
5 MyCustomCalculator calculator = new MyCustomCalculator();
6 // When
7 Test.startTest();
8 calculator.calculate(request);
9 Test.stopTest();
10 // Then
11 // some assertions
12}Creates the necessary Account, WebStore, WebCart, CartDeliveryGroup, and CartItem records and returns the corresponding CartExtension.Cart Apex object.
| Param | Description |
|---|---|
webStoreType | type of the WebStore the cart will be created for |
| Type | Description |
|---|---|
Cart | CartExtension.Cart |
1static void testMyCustomCalculator() {
2 // Given
3 CartExtension.Cart cartObject = CartExtension.CartTestUtil.createCart(CartExtension.WebStoreTypeEnum.B2C);
4 CartExtension.CartCalculateCalculatorRequest request = new CartExtension.CartCalculateCalculatorRequest(cartObject);
5 MyCustomCalculator calculator = new MyCustomCalculator();
6 // When
7 Test.startTest();
8 calculator.calculate(request);
9 Test.stopTest();
10 // Then
11 // some assertions
12}Developer Preview