Skip to content

Commit

Permalink
added support for istanbul test reporting, and completed support for …
Browse files Browse the repository at this point in the history
…public app auth
  • Loading branch information
Jordan Walsh committed Feb 21, 2017
1 parent edd51f9 commit f947ece
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 345 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@
/.idea
*.log
/cert
/coverage
.nyc_output/
5 changes: 2 additions & 3 deletions lib/application.js
Expand Up @@ -497,9 +497,8 @@ var RequireAuthorizationApplication = Application.extend({
return this.options.authorizeUrl + '?' + querystring.stringify(q);
},
setOptions: function(options) {
_.merge(this.options, options);
logger.debug(this.options);
return this.options;
this.options.accessToken = options.accessToken;
this.options.accessSecret = options.accessSecret;
}
});

Expand Down
13 changes: 7 additions & 6 deletions lib/entities/account.js
Expand Up @@ -3,23 +3,24 @@ var _ = require('lodash'),
logger = require('../logger')

var AccountSchema = new Entity.SchemaObject({
AccountID: { type: String, toObject: 'always' },
Code: { type: String, toObject: 'always' },
Name: { type: String, toObject: 'always' },
Type: { type: String, toObject: 'always' },
BankAccountNumber: { type: String, toObject: 'always' },
Status: { type: String, toObject: 'never' },
Description: { type: String, toObject: 'always' },
BankAccountType: { type: String, toObject: 'hasValue' },
CurrencyCode: { type: String, toObject: 'never' },
TaxType: { type: String, toObject: 'always' },
EnablePaymentsToAccount: { type: Boolean, toObject: 'always' },
ShowInExpenseClaims: { type: Boolean, toObject: 'always' },
AccountID: { type: String, toObject: 'always' },
Class: { type: String, toObject: 'never' },
ReportingCode: { type: String, toObject: 'never' },
Status: { type: String, toObject: 'never' },
SystemAccount: { type: String, toObject: 'never' },
BankAccountNumber: { type: String, toObject: 'always' },
CurrencyCode: { type: String, toObject: 'never' },
ReportingCode: { type: String, toObject: 'never' },
ReportingCodeName: { type: String, toObject: 'never' },
HasAttachments: { type: Boolean, toObject: 'always' }
HasAttachments: { type: Boolean, toObject: 'always' },
UpdatedDateUTC: { type: String, toObject: 'hasValue' }
});


Expand Down
34 changes: 18 additions & 16 deletions lib/entities/banktransaction.js
Expand Up @@ -6,30 +6,34 @@ var _ = require('lodash'),
LineItemSchema = require('./shared').LineItemSchema

var BankTransactionSchema = new Entity.SchemaObject({
Type: { type: String, toObject: 'always' },
Contact: { type: ContactSchema, toObject: 'always' },
Date: { type: String, toObject: 'always' },
LineAmountTypes: { type: String, toObject: 'always' },
LineItems: { type: Array, arrayType: LineItemSchema, toObject: 'always' },
SubTotal: { type: Number },
TotalTax: { type: Number },
Total: { type: Number },
UpdatedDateUTC: { type: Date },
FullyPaidOnDate: { type: Date },
BankTransactionID: { type: String },
IsReconciled: { type: Boolean, toObject: 'always' },
CurrencyCode: { type: String, toObject: 'always' },
Url: { type: String, toObject: 'always' },
Reference: { type: String, toObject: 'always' },
BankAccount: {
type: {
AccountID: { type: String, toObject: 'always' }
},
toObject: 'always'
},
Type: { type: String, toObject: 'always' }
IsReconciled: { type: Boolean, toObject: 'always' },
Date: { type: String, toObject: 'always' },
Reference: { type: String, toObject: 'always' },
CurrencyCode: { type: String, toObject: 'always' },
CurrencyRate: { type: String, toObject: 'hasValue' },
Url: { type: String, toObject: 'always' },
Status: { type: String, toObject: 'always' },
LineAmountTypes: { type: String, toObject: 'always' },
SubTotal: { type: Number },
TotalTax: { type: Number },
Total: { type: Number },
BankTransactionID: { type: String },
PrepaymentID: { type: String },
OverpaymentID: { type: String },
UpdatedDateUTC: { type: Date, toObject: 'never' },
HasAttachments: { type: Boolean, toObject: 'always' },
FullyPaidOnDate: { type: Date }
});


var BankTransaction = Entity.extend(BankTransactionSchema, {
constructor: function(application, data, options) {
logger.debug('BankTransaction::constructor');
Expand Down Expand Up @@ -68,8 +72,6 @@ var BankTransaction = Entity.extend(BankTransactionSchema, {
},
save: function(cb) {
var xml = '<BankTransactions>' + this.toXml() + '</BankTransactions>';
//console.log(xml);
//cb();
return this.application.putOrPostEntity('put', 'BankTransactions', xml, {}, cb);
}
});
Expand Down
184 changes: 97 additions & 87 deletions lib/entities/contact.js
@@ -1,78 +1,83 @@
var _ = require('lodash')
, Entity = require('./entity')
, logger = require('../logger')
, AddressSchema = require('./shared').AddressSchema
, PhoneSchema = require('./shared').PhoneSchema
, ContactPersonSchema = require('./shared').ContactPerson
, PaymentTermSchema = require('./shared').PaymentTermSchema
, dateformat = require('dateformat')
var _ = require('lodash'),
Entity = require('./entity'),
logger = require('../logger'),
AddressSchema = require('./shared').AddressSchema,
PhoneSchema = require('./shared').PhoneSchema,
ContactPersonSchema = require('./shared').ContactPerson,
PaymentTermSchema = require('./shared').PaymentTermSchema,
dateformat = require('dateformat')

var BatchPaymentSchema = new Entity.SchemaObject({
BankAccountNumber: { type: String },
BankAccountName: { type: String },
Details: { type: String }
});

var ContactSchema = new Entity.SchemaObject({
ContactID: { type: String, toObject: 'never' },
ContactNumber: {type: String, toObject: 'never'},
ContactStatus: {type: String},
Name: {type: String, toObject: 'always', validators: { required: true, maxLength: 500}},
FirstName: {type: String, toObject: 'always', validators: { maxLength: 255}},
LastName: {type: String, toObject: 'always', validators: { maxLength: 255}},
EmailAddress: {type: String},
SkypeUserName: {type: String},
ContactID: { type: String, toObject: 'hasValue' },
ContactNumber: { type: String, toObject: 'hasValue', validators: { maxLength: 50 } },
AccountNumber: { type: String, toObject: 'hasValue', validators: { maxLength: 50 } },
ContactStatus: { type: String },
Name: { type: String, toObject: 'always', validators: { required: true, maxLength: 255 } },
FirstName: { type: String, toObject: 'always', validators: { maxLength: 255 } },
LastName: { type: String, toObject: 'always', validators: { maxLength: 255 } },
EmailAddress: { type: String },
SkypeUserName: { type: String },
ContactPersons: [ContactPersonSchema],
BankAccountDetails: {type: String},
TaxNumber: {type: String},
AccountsReceivableTaxType: {type: String},
AccountsPayableTaxType: {type: String},
Addresses: {type: Array, arrayType: AddressSchema, toObject: 'always'},
Phones: {type: Array, arrayType: PhoneSchema, toObject: 'always'},
UpdatedDateUTC: {type: Date, toObject: 'never'},
ContactGroups: {type: String},
IsSupplier: {type: Boolean},
IsCustomer: {type: Boolean},
DefaultCurrency: {type: String},
Website: {type: String},
BatchPayments: {type: {
BankAccountNumber: { type: String},
BankAccountName: { type: String},
Details: { type: String}
}, toObject:'hasValue'
},
Discount: {type: String},
Balances: {type: {
AccountsReceivable: {
Outstanding: {type: Number},
Overdue: {type: Number}
BankAccountDetails: { type: String },
TaxNumber: { type: String, validators: { maxLength: 50 } },
AccountsReceivableTaxType: { type: String },
AccountsPayableTaxType: { type: String },
Addresses: { type: Array, arrayType: AddressSchema, toObject: 'always' },
Phones: { type: Array, arrayType: PhoneSchema, toObject: 'always' },
UpdatedDateUTC: { type: Date, toObject: 'never' },
IsSupplier: { type: Boolean },
IsCustomer: { type: Boolean },
DefaultCurrency: { type: String },
XeroNetworkKey: { type: String, toObject: 'never' },
SalesDefaultAccountCode: { type: String, toObject: 'never' },
PurchasesDefaultAccountCode: { type: String, toObject: 'never' },
//The following properties are only retrieved on GET requests for specific contacts or with pagination
ContactGroups: { type: String },
Website: { type: String },
BatchPayments: { type: BatchPaymentSchema, toObject: 'hasValue', readOnly: 'true' },
Discount: { type: String },
Balances: {
type: {
AccountsReceivable: {
Outstanding: { type: Number },
Overdue: { type: Number }
},
AccountsPayable: {
Outstanding: { type: Number },
Overdue: { type: Number }
}
},
AccountsPayable: {
Outstanding: {type: Number},
Overdue: {type: Number}
}}, toObject: 'never'
toObject: 'hasValue'
},
PaymentTerms: {type: {
Bills: PaymentTermSchema,
Sales: PaymentTermSchema
}, toObject: 'hasValue'
PaymentTerms: {
type: {
Bills: PaymentTermSchema,
Sales: PaymentTermSchema
},
toObject: 'hasValue'
}
});


var Contact = Entity.extend(ContactSchema, {
constructor: function (application, data, options)
{
constructor: function(application, data, options) {
logger.debug('Contact::constructor');
this.Entity.apply(this, arguments);
},
initialize: function (data, options)
{
},
changes: function (options)
{
initialize: function(data, options) {},
changes: function(options) {
return this._super(options);
},
_toObject: function (options)
{
_toObject: function(options) {
return this._super(options);
},
fromXmlObj: function (obj)
{
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'Contact', 'LineItems', 'CreditNotes'));
if (obj.Addresses) {
Expand All @@ -87,64 +92,69 @@ var Contact = Entity.extend(ContactSchema, {

return this;
},
toXml: function ()
{
var contact = _.omit(this.toObject(), 'Addresses', 'Phones', 'ContactPersons','BatchPayments','PaymentTerms');
if (!_.isEmpty(this.BatchPayments))
toXml: function() {
var contact = _.omit(this.toObject(), 'Addresses', 'Phones', 'ContactPersons', 'BatchPayments', 'PaymentTerms');


/**
* JWalsh 21-02-2017
* Updated to remove the lodash isEmpty function as the BatchPayments object was being populated with a bunch
* of data during construction and the object was never Empty. This meant that the toXML function was entering an infinite
* loop and causing the SDK to crash.
*
* Instead, I'm now just testing the individual elements within the object to see if they are populated.
*/
if (this.BatchPayments && (this.BatchPayments.BankAccountNumber || this.BatchPayments.BankAccountName || this.BatchPayments.Details))
contact.BatchPayments = this.BatchPayments;
if (!_.isEmpty(this.PaymentTerms))

if (this.PaymentTerms &&
(this.PaymentTerms.Bills && (this.PaymentTerms.Bills.Day || this.PaymentTerms.Bills.Type)) ||
(this.PaymentTerms.Sales && (this.PaymentTerms.Sales.Day || this.PaymentTerms.Sales.Type))
) {
contact.PaymentTerms = this.PaymentTerms;
}

if (!_.isEmpty(this.Addresses)) {
contact.Addresses = [];
_.forEach(this.Addresses, function (address)
{
contact.Addresses.push({Address: address.toObject()})
_.forEach(this.Addresses, function(address) {
contact.Addresses.push({ Address: address.toObject() })
})
}
if (!_.isEmpty(this.Phones)) {
contact.Phones = [];
_.forEach(this.Phones, function (phone)
{
contact.Phones.push({Phone: phone.toObject()})
_.forEach(this.Phones, function(phone) {
contact.Phones.push({ Phone: phone.toObject() })
})
}
if (!_.isEmpty(this.ContactPersons)) {
contact.ContactPersons = [];
_.forEach(this.ContactPersons, function (contactPerson)
{
contact.ContactPersons.push({ContactPerson: contactPerson.toObject()})
_.forEach(this.ContactPersons, function(contactPerson) {
contact.ContactPersons.push({ ContactPerson: contactPerson.toObject() })
})
}

return this.application.js2xml(contact, 'Contact');
},
getAttachments:function(options)
{
return this.application.core.attachments.getAttachments('Contacts/' + this.ContactID,options)
getAttachments: function(options) {
return this.application.core.attachments.getAttachments('Contacts/' + this.ContactID, options)
},
getAttachmentContent:function(fileName,options)
{
return this.application.core.attachments.getContent('Contacts/' + this.ContactID,fileName,options);
getAttachmentContent: function(fileName, options) {
return this.application.core.attachments.getContent('Contacts/' + this.ContactID, fileName, options);
},
save:function(options)
{
save: function(options) {
var xml = '<Contacts>' + this.toXml() + '</Contacts>';
var path, method;
if (this.ContactID)
{
if (this.ContactID) {
path = 'Contacts/' + this.ContactID;
method = 'post'
}
else
{
} else {
path = 'Contacts';
method = 'put'
}
return this.application.putOrPostEntity(method, path, xml)
return this.application.putOrPostEntity(method, path, xml)
}
});


module.exports = Contact;
module.exports.ContactSchema = ContactSchema;
module.exports.ContactSchema = ContactSchema;
1 change: 0 additions & 1 deletion lib/entities/shared.js
Expand Up @@ -49,7 +49,6 @@ module.exports.LineItemSchema = new Entity.SchemaObject({
TaxType: { type: String },
LineAmount: { type: Number },
Tracking: { type: String }

});

var InvoiceIDSchema = new Entity.SchemaObject({
Expand Down

0 comments on commit f947ece

Please sign in to comment.