Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TransactionTest
@isTest
private class TransactionTest{
@isTest(seeAllData=true)
static void test(){
String companyName = 'Company 1';
c2g__codaCompany__c company = [SELECT id, name FROM c2g__codaCompany__c WHERE name = :companyName];
User usr = new User(alias = 'standt',
email='standarduser@testorg.com',
emailencodingkey='UTF-8',
lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US',
profileid = [SELECT id FROM Profile WHERE name = 'System Administrator'].id,
timezonesidkey='America/Los_Angeles', c2g__APILicenseKey__c = System.label.FFAPIKey,
username='uniqueUsernameForTesting@example.org');
insert usr;
//Set our new user as belonging to a company
insert new c2g__codaUserCompany__c(
c2g__company__c = company.id,
c2g__user__c = usr.id);
System.runAs( new User(id=UserInfo.getUserId()) ){ //insert setup sObject inside runAs to avoid MIXED_DML exception
insert new groupMember(userOrGroupId = usr.id, groupId = [SELECT id FROM Group WHERE name = :'FF '+companyName].id);
}
System.runAs(usr){
c2g.CODAAPICommon_6_0.Context ctx = new c2g.CODAAPICommon_6_0.Context();
ctx.companyName = 'Company 1';
c2g__codaInvoice__c invoice = new c2g__codaInvoice__c(
c2g__Account__c = '001d000000BAdtb', //replace with one of yours!
c2g__InvoiceDate__c = Date.today(),
c2g__invoiceStatus__c = 'In Progress',
ffbilling__DerivePeriod__c = true,
ffbilling__DeriveCurrency__c = true,
ffbilling__DeriveDueDate__c = true,
ffbilling__CopyAccountValues__c = true
);
insert invoice;
// Insert Invoice line items
List<c2g__codaInvoiceLineItem__c> invoiceLines = new List<c2g__codaInvoiceLineItem__c>();
invoiceLines.add(
new c2g__codaInvoiceLineItem__c(
c2g__Invoice__c = invoice.Id,
c2g__Product__c = '01td0000001BIMc', //replace with one of yours!
c2g__Quantity__c = 10));
invoiceLines.add(
new c2g__codaInvoiceLineItem__c(
c2g__Invoice__c = invoice.Id,
c2g__Product__c = '01td0000001BIMd', //replace with one of yours!
c2g__Quantity__c = 2));
insert invoiceLines;
// Post the Invoice
c2g.CODAAPICommon.Reference ref = new c2g.CODAAPICommon.Reference();
ref.Id = invoice.Id;
// Post Invoices
c2g.CODAAPISalesInvoice_6_0.PostInvoice(ctx,ref);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment