- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-04-2019
11:20 PM
03-04-2019
11:20 PM
Hi,
Does anyone has written test class for SelectBillingAccount plugin code? There seems to be no such examples found in the forum.
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-05-2019
03:48 PM
03-05-2019
03:48 PM
I use these helper methods private static zqu.JSRemoteController.BillingAccountObjects createBillingAccountObjectsForTest(){ zqu.JSRemoteController.BillingAccountObjects bao = new zqu.JSRemoteController.BillingAccountObjects(); bao.billingAccountTypes = new List<String>{'new', 'existing'}; bao.defaultBillingAccountId = null; bao.defaultBillingAccountType = 'existing'; bao.opportunityId = sObjectHelper_Test.getFakeSFId('Opportunity'); bao.sfdcAccountId = sObjectHelper_Test.getFakeSFId('Account'); bao.billingAccounts = new zqu.JsRemoteController.ListData(); bao.billingAccounts.success=true; bao.billingAccounts.dataObjects = new List<Map<String,Object>>(); system.debug(bao); return bao; } private static zqu.JSRemoteController.QuoteTypeObjects createQuoteTypeObjectsForTest(){ zqu.JSRemoteController.QuoteTypeObjects qto = new zqu.JSRemoteController.QuoteTypeObjects(); qto.billingAccountId = null; qto.defaultQuoteType = 'new'; qto.quoteTypes= new List<String>{'new', 'amend', 'renew', 'cancel'}; system.debug(qto); return qto; } // these field names need to be lower case private static Map<String,Object> createBillingAccountForBrand(String customValue, String batch){ return new Map<String,Object>{'zuora__status__c'=>'Active', 'a_custom_field__c'=> customValue, 'zuora__batch__c' => batch }; }
Here is an excerpt from a test - i left in some of my functionality that won't exist in your code to give you an idea of what I do. I have tests around all of the methods - this should get you started. // And there exists one matching billing account zqu.JSRemoteController.BillingAccountObjects billingAccountObject = createBillingAccountObjectsForTest(); billingAccountObject.billingAccounts.dataObjects.add(createBillingAccountForBrand('value1', badBatch)); billingAccountObject.billingAccounts.dataObjects.add(createBillingAccountForBrand('value2', goodBatch)); // And user is an Admin User User adminUser = Test_User_Factory.getUserWithRole('Administrator'); System.debug('### adminUser ' + adminUser); System.runas(adminUser){ // When the quote Wizard Process starts SelectBillingAccountPlugin sbap = new SelectBillingAccountPlugin(); // And calls plugin method to filter billing accounts zqu.JSRemoteController.BillingAccountObjects filteredBillingAccountObject = sbap.getAvailableBillingAccounts(billingAccountObject); // Then the default account type should be existing System.assertEquals('existing', filteredBillingAccountObject.defaultBillingAccountType); System.assertEquals(2, filteredBillingAccountObject.billingAccountTypes.size()); System.assertEquals(1, filteredBillingAccountObject.billingAccounts.dataObjects.size()); } ExceptionMonitor.assertNoExceptions();
Maggie Longshore
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-05-2019
03:48 PM
03-05-2019
03:48 PM
I use these helper methods private static zqu.JSRemoteController.BillingAccountObjects createBillingAccountObjectsForTest(){ zqu.JSRemoteController.BillingAccountObjects bao = new zqu.JSRemoteController.BillingAccountObjects(); bao.billingAccountTypes = new List<String>{'new', 'existing'}; bao.defaultBillingAccountId = null; bao.defaultBillingAccountType = 'existing'; bao.opportunityId = sObjectHelper_Test.getFakeSFId('Opportunity'); bao.sfdcAccountId = sObjectHelper_Test.getFakeSFId('Account'); bao.billingAccounts = new zqu.JsRemoteController.ListData(); bao.billingAccounts.success=true; bao.billingAccounts.dataObjects = new List<Map<String,Object>>(); system.debug(bao); return bao; } private static zqu.JSRemoteController.QuoteTypeObjects createQuoteTypeObjectsForTest(){ zqu.JSRemoteController.QuoteTypeObjects qto = new zqu.JSRemoteController.QuoteTypeObjects(); qto.billingAccountId = null; qto.defaultQuoteType = 'new'; qto.quoteTypes= new List<String>{'new', 'amend', 'renew', 'cancel'}; system.debug(qto); return qto; } // these field names need to be lower case private static Map<String,Object> createBillingAccountForBrand(String customValue, String batch){ return new Map<String,Object>{'zuora__status__c'=>'Active', 'a_custom_field__c'=> customValue, 'zuora__batch__c' => batch }; }
Here is an excerpt from a test - i left in some of my functionality that won't exist in your code to give you an idea of what I do. I have tests around all of the methods - this should get you started. // And there exists one matching billing account zqu.JSRemoteController.BillingAccountObjects billingAccountObject = createBillingAccountObjectsForTest(); billingAccountObject.billingAccounts.dataObjects.add(createBillingAccountForBrand('value1', badBatch)); billingAccountObject.billingAccounts.dataObjects.add(createBillingAccountForBrand('value2', goodBatch)); // And user is an Admin User User adminUser = Test_User_Factory.getUserWithRole('Administrator'); System.debug('### adminUser ' + adminUser); System.runas(adminUser){ // When the quote Wizard Process starts SelectBillingAccountPlugin sbap = new SelectBillingAccountPlugin(); // And calls plugin method to filter billing accounts zqu.JSRemoteController.BillingAccountObjects filteredBillingAccountObject = sbap.getAvailableBillingAccounts(billingAccountObject); // Then the default account type should be existing System.assertEquals('existing', filteredBillingAccountObject.defaultBillingAccountType); System.assertEquals(2, filteredBillingAccountObject.billingAccountTypes.size()); System.assertEquals(1, filteredBillingAccountObject.billingAccounts.dataObjects.size()); } ExceptionMonitor.assertNoExceptions();
Maggie Longshore
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-05-2019
04:46 PM
03-05-2019
04:46 PM
Re: SelectBillingAccount plugin Test Class
Thank you @MaggieL, really appreciate your help.