Skip to content

Commit

Permalink
added initial reports functionality... tests currently broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 14, 2017
1 parent 3edb1d0 commit 1661b87
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,4 @@ var PartnerApplication = RequireAuthorizationApplication.extend({
module.exports.PrivateApplication = PrivateApplication;
module.exports.PublicApplication = PublicApplication;
module.exports.PartnerApplication = PartnerApplication;
module.exports.Application = Application;
module.exports.Application = Application;
3 changes: 2 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var HELPERS = {
trackingCategories: { file: 'trackingcategories' },
users: { file: 'users' },
payments: { file: 'payments' },
taxrates: { file: 'taxrates' }
taxrates: { file: 'taxrates' },
reports: { file: 'reports' }
};

function Core(application, options) {
Expand Down
58 changes: 58 additions & 0 deletions lib/entities/accounting/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var _ = require('lodash'),
Entity = require('../entity'),
logger = require('../../logger');

var ReportSchema = new Entity.SchemaObject({
ReportID: { type: String, toObject: 'always' },
ReportName: { type: String, toObject: 'always' },
ReportType: { type: String, toObject: 'always' },
ReportTitles: [ReportTitleSchema],
ReportDate: { type: String, toObject: 'always' },
UpdatedDateUTC: { type: String, toObject: 'always' },
Rows: [ReportRowSchema]
});

var ReportTitleSchema = new Entity.SchemaObject({
ReportTitle: { type: String, toObject: 'always' }
});

var ReportRowSchema = new Entity.SchemaObject({
RowType: { type: String, toObject: 'always' },
Title: { type: String, toObject: 'always' },
Cells: [ReportCellSchema]
});

var ReportCellSchema = new Entity.SchemaObject({
Value: { type: String, toObject: 'always' },
Attributes: [ReportAttributeSchema]
});

var ReportAttributeSchema = new Entity.SchemaObject({
Value: { type: String, toObject: 'always' },
Id: { type: String, toObject: 'always' }
});

var Report = Entity.extend(ReportSchema, {
constructor: function(application, data, options) {
logger.debug('Report::constructor');
this.Entity.apply(this, arguments);
},
initialize: function(data, options) {},
fromXmlObj: function(obj) {
var self = this;
Object.assign(self, _.omit(obj, 'Rows', 'Cells'));
if (obj.Rows) {
_.each(obj.Rows.Row, function(row) {
_.each(row.Cells.Cell, function(cell) {
console.log(cell);
});
self.Rows.push(row);
});
}

return this;
}
});

module.exports = Report;
module.exports.ItemSchema = ReportSchema;
25 changes: 25 additions & 0 deletions lib/entity_helpers/accounting/reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var _ = require('lodash'),
logger = require('../../logger'),
EntityHelper = require('../entity_helper'),
Report = require('../../entities/accounting/report'),
util = require('util')

var Reports = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, Object.assign({ entityName: 'Report', entityPlural: 'Reports' }, options));
},
create: function(data, options) {
return new Report(this.application, data, options)
},
generateReport: function(options) {
var self = this;
var clonedOptions = _.clone(options || {});
clonedOptions.entityConstructor = function(data) { return self.create(data) };
return this.getEntities(clonedOptions)
.then(function(reports) {
return _.first(reports);
});
}
})

module.exports = Reports;
30 changes: 27 additions & 3 deletions test/accountingtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('get access for public or partner application', function() {
console.log("URL: " + authoriseUrl);
console.log("token: " + requestToken);
console.log("secret: " + requestSecret);
});
});
});

describe('gets the request token from the url', function() {
Expand Down Expand Up @@ -149,15 +149,38 @@ describe('get access for public or partner application', function() {
describe('swaps the request token for an access token', function() {
it('calls the access token method and sets the options', function() {
return currentApp.getAccessToken(requestToken, requestSecret, verifier)
.then(function({token, secret}) {
.then(function({ token, secret }) {
currentApp.setOptions({ accessToken: token, accessSecret: secret });
});
});
});
});
});

describe('regression tests', function() {
describe('reporting tests', function() {
this.timeout(10000);
it('generates a Balance Sheet', function(done) {
currentApp.core.reports.generateReport({ id: 'BalanceSheet' })
.then(function(report) {
expect(report.ReportType).to.equal('BalanceSheet');
expect(report.ReportName).to.equal('Balance Sheet');
expect(report.Rows).to.have.length.greaterThan(0);
report.Rows.forEach(function(row) {
expect(row.RowType).to.be.oneOf(['Header', 'Section', 'Row', 'SummaryRow']);
expect(row.Cells).to.have.length.greaterThan(0);
});
done();
})
.catch(function(err) {
console.log(err);
done(wrapError(err));
})

});

})

describe.skip('regression tests', function() {

var InvoiceID = "";
var PaymentID = "";
Expand Down Expand Up @@ -230,6 +253,7 @@ describe('regression tests', function() {
done();
})
.catch(function(err) {
console.log(err);
done(wrapError(err));
})
})
Expand Down

0 comments on commit 1661b87

Please sign in to comment.