Write a test class for the below code public class ZuoraApplyInvoiceQueue implements…
- User
Write a test class for the below code public class ZuoraApplyInvoiceQueue implements Queueable,Database.AllowsCallouts {
public ZuoraApplyInvoiceQueue(string invoiceId,decimal paymentAmount,string paymentId,Date invoiceTargetDate){ this.invoiceId = invoiceId; this.paymentAmount = paymentAmount; this.paymentId = paymentId; this.invoiceTargetDate = invoiceTargetDate; } public void execute(QueueableContext context) { PaymentCenterConfigurations__c paymentCenterConfig = PaymentCenterConfigurations__c.getInstance(‘Payment Center Configurations’); Zuora.zObject inv = new Zuora.zObject(‘Invoice’); inv.setValue(‘Id’,invoiceId); inv.setValue(‘Status’,‘Posted’); List<Zuora.zApi.SaveResult> updResult; if(!Test.isrunningTest()){ updResult = zApi.zupdate(new List < Zuora.zObject > {inv}); } System.debug(updResult); }
- Assistant
@isTest public class ZuoraApplyInvoiceQueueTest {
codestatic testMethod void testExecute() { //Create test data PaymentCenterConfigurations__c paymentCenterConfig = new PaymentCenterConfigurations__c( Name = 'Payment Center Configurations', Setting1__c = 'Test Setting 1', Setting2__c = 'Test Setting 2' ); insert paymentCenterConfig; Date testTargetDate = Date.newInstance(2022, 1, 1); Invoice__c testInvoice = new Invoice__c( Name = 'Test Invoice', Target_Date__c = testTargetDate, Status__c = 'Draft' ); insert testInvoice; //Instantiate and call the queueable job ZuoraApplyInvoiceQueue job = new ZuoraApplyInvoiceQueue( testInvoice.Id, 100.00, 'Test Payment Id', testTargetDate ); Test.startTest(); System.enqueueJob(job); Test.stopTest(); //Assert that the invoice was updated testInvoice = [SELECT Id, Status__c FROM Invoice__c WHERE Id=:testInvoice.Id]; System.assertEquals('Posted', testInvoice.Status__c); }