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.
Fields
Name of the records created by the createCart() method.
global ACCOUNT_NAME → String
global CARTITEM_NAME → String
global CART_NAME → String
global DELIVERYGROUP_NAME → String
global WEBSTORE_NAME → String
Methods
global static Cart getCart(ID cartRecordId)
Allows you to retrieve a CartExtension.Cart Apex object from a WebCart record ID.
1static void testMyCustomCalculator(){2 // Given3 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 // When20 Test.startTest();21 calculator.calculate(request);22 Test.stopTest();23 // Then24 // some assertions25}
global static Cart createCart()
Creates the necessary Account, WebStore (type B2B), WebCart, CartDeliveryGroup, and CartItem records and returns the corresponding CartExtension.Cart Apex object.
1static void testMyCustomCalculator(){2 // Given3 CartExtension.Cart cartObject = CartExtension.CartTestUtil.createCart();4 CartExtension.CartCalculateCalculatorRequest request = new CartExtension.CartCalculateCalculatorRequest(cartObject);5 MyCustomCalculator calculator = new MyCustomCalculator();6 // When7 Test.startTest();8 calculator.calculate(request);9 Test.stopTest();10 // Then11 // some assertions12}
global static Cart createCart(WebStoreTypeEnum webStoreType)
Creates the necessary Account, WebStore, WebCart, CartDeliveryGroup, and CartItem records and returns the corresponding CartExtension.Cart Apex object.