Overview
Below is a sample test class for Accounting Seed's Payable object. This class can be used to test whether your code is working as expected.
@IsTest
private class PayableExampleTest {
@IsTest
static void createPayable() {
// —— DATA PREPARATION ——
// insert 1 Account
Account acct = new Account(
Name = 'Test Account');
insert acct;
// insert 1 Accounting Period
AcctSeed__Accounting_Period__c acctPeriod = new AcctSeed__Accounting_Period__c(
Name = '1991-10',
AcctSeed__Start_Date__c = Date.newinstance(1991, 10, 1),
AcctSeed__End_Date__c = Date.newinstance(1991, 10, 31),
AcctSeed__Status__c = 'Open');
insert acctPeriod;
// 1 Cash GL-Account
AcctSeed__GL_Account__c cashGL = new AcctSeed__GL_Account__c(
Name = '1000-Cash',
AcctSeed__Active__c = true,
AcctSeed__Type__c = 'Balance Sheet',
AcctSeed__Bank__c = true,
AcctSeed__Sub_Type_1__c = 'Assets',
AcctSeed__Sub_Type_2__c = 'Cash');
insert CashGL;
// insert 4 billing formats
AcctSeed__Billing_Format__c[] PDFformats = new List<AcctSeed__Billing_Format__c>();
PDFformats.add(
new AcctSeed__Billing_Format__c(
Name = 'Default Billing Product',
AcctSeed__Visualforce_PDF_Page__c = 'BillingProductPDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__Type__c = 'Billing',
AcctSeed__Sort_Field__c = 'Name'
)
);
PDFformats.add(
new AcctSeed__Billing_Format__c(
Name = 'Default Billing Service',
AcctSeed__Visualforce_PDF_Page__c = 'BillingServicePDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__Type__c = 'Billing',
AcctSeed__Sort_Field__c = 'Name'
)
);
PDFformats.add(
new AcctSeed__Billing_Format__c (
Name = 'Billing Outstanding Statement',
AcctSeed__Visualforce_PDF_Page__c = 'BillingOutstandingStatementPDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__ReplyTo_Email__c = 'test3463464364646@gmail.com',
AcctSeed__Type__c = 'Outstanding Statement'
)
);
PDFformats.add(
new AcctSeed__Billing_Format__c (
Name = 'Billing Activity Statement',
AcctSeed__Visualforce_PDF_Page__c = 'BillingActivityStatementPDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__ReplyTo_Email__c = 'test3463464364646@gmail.com',
AcctSeed__Type__c = 'Activity Statement'
)
);
PDFformats.add(
new AcctSeed__Billing_Format__c(
Name = 'Default Purchase Order',
AcctSeed__Visualforce_PDF_Page__c = 'BillingServicePDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__Type__c = 'Purchase Order',
AcctSeed__Sort_Field__c = 'Name'
)
);
PDFformats.add(
new AcctSeed__Billing_Format__c(
Name = 'Default Packing Slip',
AcctSeed__Visualforce_PDF_Page__c = 'BillingServicePDF',
AcctSeed__Default_Email_Template__c = [Select Id, DeveloperName From EmailTemplate limit 1].DeveloperName,
AcctSeed__Type__c = 'Packing Slip',
AcctSeed__Sort_Field__c = 'Name'
)
);
insert PDFformats;
// insert 1 Ledger records
AcctSeed__Ledger__c ledger = new AcctSeed__Ledger__c(
Name = 'Actual',
AcctSeed__Type__c = 'Transactional',
AcctSeed__Default_Bank_Account__c = CashGL.id,
AcctSeed__Default_Billing_Format__c = PDFformats[0].Id,
AcctSeed__Billing_Outstanding_Statement_Format__c = PDFformats[2].Id,
AcctSeed__Billing_Activity_Statement_Format__c = PDFformats[3].Id,
AcctSeed__Default_Purchase_Order_Format__c = PDFformats[4].Id,
AcctSeed__Default_Packing_Slip_Format__c = PDFformats[5].Id);
insert ledger;
// --- START HERE ---
// Create Payable RECORD
AcctSeed__Account_Payable__c invoice = new AcctSeed__Account_Payable__c(
AcctSeed__Payee_Reference__c = '1',
AcctSeed__Vendor__c = acct.Id,
AcctSeed__Accounting_Period__c = acctPeriod.Id,
AcctSeed__Ledger__c = ledger.Id
);
insert invoice;
System.assertEquals(1, [Select count() FROM AcctSeed__Account_Payable__c WHERE Id = :invoice.Id]);
}
}
Comments
0 comments
Article is closed for comments.