Skip to content

Commit

Permalink
Add setup and teardown of tracking categories for region test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbanham committed Mar 8, 2017
1 parent 1828d87 commit 5f2f480
Showing 1 changed file with 63 additions and 42 deletions.
105 changes: 63 additions & 42 deletions test/accountingtests.js
Expand Up @@ -930,51 +930,72 @@ describe('regression tests', function() {
})
});

it('Uses a tracking category on an invoice - REGION', function(done) {
//Create an invoice with the sample tracking category attached to the line item on the invoice.
var invoice = currentApp.core.invoices.newInvoice({
Type: 'ACCREC',
Contact: {
Name: 'Department of Testing'
},
DueDate: new Date().toISOString().split("T")[0],
LineItems: [{
Description: 'Services',
Quantity: 2,
UnitAmount: 230,
AccountCode: '400',
Tracking: [{
TrackingCategory: {
Name: 'Region',
Option: 'North'
}
}]
}]
});
invoice.save()
.then(function(response) {
it('Uses a tracking category on an invoice - REGION', function() {
// TODO refactor this setup and teardown into hooks
// Create the tracking category

expect(response.entities).to.have.length.greaterThan(0);
expect(response.entities[0].InvoiceID).to.not.equal(undefined);
expect(response.entities[0].InvoiceID).to.not.equal("");
var trackingCategory = currentApp.core.trackingCategories.newTrackingCategory({
Name: uuid.v4()
});

response.entities[0].LineItems.forEach(function(lineItem) {
expect(lineItem.Tracking).to.have.length.greaterThan(0);
_.each(lineItem.Tracking, function(trackingCategory) {
expect(trackingCategory.TrackingCategoryID).to.not.equal(undefined);
expect(trackingCategory.TrackingCategoryID).to.not.equal("");
expect(trackingCategory.TrackingOptionID).to.not.equal(undefined);
expect(trackingCategory.TrackingOptionID).to.not.equal("");
expect(trackingCategory.Name).to.equal('Region');
expect(trackingCategory.Option).to.equal('North');
var trackingCategoryName;
var trackingCategoryID;

return trackingCategory.save()
.then(function(response) {
trackingCategoryName = response.entities[0].Name;
trackingCategoryID = response.entities[0].TrackingCategoryID;
return response.entities[0].saveTrackingOptions([
{ Name: "North" },
{ Name: "South" },
])
})
.then(function(response) {
//Create an invoice with the sample tracking category attached to the line item on the invoice.
var invoice = currentApp.core.invoices.newInvoice({
Type: 'ACCREC',
Contact: {
Name: 'Department of Testing'
},
DueDate: new Date().toISOString().split("T")[0],
LineItems: [{
Description: 'Services',
Quantity: 2,
UnitAmount: 230,
AccountCode: '400',
Tracking: [{
TrackingCategory: {
Name: trackingCategoryName,
Option: 'North'
}
}]
}]
});
return invoice.save()
.then(function(response) {

expect(response.entities).to.have.length.greaterThan(0);
expect(response.entities[0].InvoiceID).to.not.equal(undefined);
expect(response.entities[0].InvoiceID).to.not.equal("");

response.entities[0].LineItems.forEach(function(lineItem) {
//expect(lineItem.Tracking).to.have.length.greaterThan(0);
_.each(lineItem.Tracking, function(trackingCategory) {
expect(trackingCategory.TrackingCategoryID).to.not.equal(undefined);
expect(trackingCategory.TrackingCategoryID).to.not.equal("");
expect(trackingCategory.TrackingOptionID).to.not.equal(undefined);
expect(trackingCategory.TrackingOptionID).to.not.equal("");
expect(trackingCategory.Name).to.equal(trackingCategory.Name);
expect(trackingCategory.Option).to.equal('North');
});
});
});
done();
})
.fail(function(err) {
console.log(util.inspect(err, null, null));
done(wrapError(err));
})
return currentApp.core.trackingCategories.deleteTrackingCategory(trackingCategoryID)
})
.fail(function(err) {
console.log(util.inspect(err, null, null));
done(wrapError(err));
})
});
});

//unfortunately this will only work on tracking categories that have been used.
Expand Down

0 comments on commit 5f2f480

Please sign in to comment.