From aadad1e7d5b98ff05cea072156261e1b931e8f9d Mon Sep 17 00:00:00 2001 From: David Banham Date: Wed, 8 Mar 2017 16:14:32 +1100 Subject: [PATCH 1/2] s/_.extend/Object.assign/g This is personal preference rather than obvious technical superiority. They both do the same thing. Modern JS supplies Object.assign, though, so we might as well use it. It's one less piece of custom API for an incoming developer to understand, and it saves confusion with the custom `extend` function being used elsewhere in the codebase. --- lib/application.js | 14 +++++++------- lib/core.js | 4 ++-- lib/entities/banktransaction.js | 4 ++-- lib/entities/banktransfer.js | 2 +- lib/entities/contact.js | 2 +- lib/entities/entity.js | 4 ++-- lib/entities/invoice.js | 4 ++-- lib/entities/journal.js | 2 +- lib/entities/organisation.js | 2 +- lib/entities/payitems.js | 2 +- lib/entities/payroll_employee.js | 4 ++-- lib/entities/timesheet.js | 4 ++-- lib/entities/trackingcategory.js | 4 ++-- lib/entity_helpers/accounts.js | 2 +- lib/entity_helpers/attachments.js | 4 ++-- lib/entity_helpers/banktransactions.js | 2 +- lib/entity_helpers/banktransfers.js | 2 +- lib/entity_helpers/contacts.js | 2 +- lib/entity_helpers/entity_helper.js | 2 +- lib/entity_helpers/invoices.js | 2 +- lib/entity_helpers/items.js | 2 +- lib/entity_helpers/organisations.js | 2 +- lib/entity_helpers/payitems.js | 4 ++-- lib/entity_helpers/payments.js | 2 +- lib/entity_helpers/payroll_employees.js | 4 ++-- lib/entity_helpers/taxrates.js | 2 +- lib/entity_helpers/timesheets.js | 6 +++--- lib/entity_helpers/trackingcategories.js | 2 +- lib/entity_helpers/users.js | 2 +- lib/logger.js | 2 +- lib/misc/extend.js | 6 +++--- lib/payroll.js | 4 ++-- lib/schemaobject/schemaobject.js | 2 +- 33 files changed, 54 insertions(+), 54 deletions(-) diff --git a/lib/application.js b/lib/application.js index 4d85dd72..c532f664 100644 --- a/lib/application.js +++ b/lib/application.js @@ -16,7 +16,7 @@ function Batch(application) { this._operations = []; } -_.extend(Batch.prototype, { +Object.assign(Batch.prototype, { get: function() { }, @@ -61,7 +61,7 @@ function Application(options) { Application.extend = extend; -_.extend(Application, { +Object.assign(Application, { defaults: { baseUrl: 'https://api.xero.com', consumerSecret: '', @@ -76,7 +76,7 @@ _.extend(Application, { } }) -_.extend(Application.prototype, { +Object.assign(Application.prototype, { init: function() { if (this.options["runscopeBucketId"] && this.options["runscopeBucketId"] !== "") { this.options.baseUrl = "https://api-xero-com-" + this.options["runscopeBucketId"] + ".runscope.net"; @@ -423,7 +423,7 @@ _.extend(Application.prototype, { var PrivateApplication = Application.extend({ constructor: function(config) { logger.debug('PrivateApplication::constructor'); - Application.call(this, _.extend({}, config, { type: 'private' })); + Application.call(this, Object.assign({}, config, { type: 'private' })); }, init: function() { Application.prototype.init.apply(this, arguments); @@ -485,7 +485,7 @@ var RequireAuthorizationApplication = Application.extend({ }); }, buildAuthorizeUrl: function(requestToken, other) { - var q = _.extend({}, { oauth_token: requestToken }, other); + var q = Object.assign({}, { oauth_token: requestToken }, other); return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q); }, setOptions: function(options) { @@ -498,7 +498,7 @@ var RequireAuthorizationApplication = Application.extend({ var PublicApplication = RequireAuthorizationApplication.extend({ constructor: function(config) { logger.debug('PublicApplication::constructor'); - RequireAuthorizationApplication.call(this, _.extend({}, config, { type: 'public' })); + RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'public' })); }, init: function() { RequireAuthorizationApplication.prototype.init.apply(this, arguments); @@ -518,7 +518,7 @@ var PublicApplication = RequireAuthorizationApplication.extend({ var PartnerApplication = RequireAuthorizationApplication.extend({ constructor: function(config) { logger.debug('PartnerApplication::constructor'); - RequireAuthorizationApplication.call(this, _.extend({}, config, { type: 'partner' })); + RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'partner' })); }, init: function() { diff --git a/lib/core.js b/lib/core.js index a8100e02..400d66fd 100644 --- a/lib/core.js +++ b/lib/core.js @@ -31,12 +31,12 @@ function Core(application, options) { } // Static -_.extend(Core, { +Object.assign(Core, { }) // Instance -_.extend(Core.prototype, { +Object.assign(Core.prototype, { }) diff --git a/lib/entities/banktransaction.js b/lib/entities/banktransaction.js index 5aebae67..c0677458 100644 --- a/lib/entities/banktransaction.js +++ b/lib/entities/banktransaction.js @@ -48,7 +48,7 @@ var BankTransaction = Entity.extend(BankTransactionSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'LineItems', 'Contact')); + Object.assign(self, _.omit(obj, 'LineItems', 'Contact')); if (obj.LineItems) { var lineItems = this.application.asArray(obj.LineItems.LineItem); _.each(lineItems, function(lineItem) { @@ -56,7 +56,7 @@ var BankTransaction = Entity.extend(BankTransactionSchema, { }) } if (obj.Contact) - _.extend(self.Contact, new Contact(self.application).fromXmlObj(obj.Contact)) + Object.assign(self.Contact, new Contact(self.application).fromXmlObj(obj.Contact)) return this; }, diff --git a/lib/entities/banktransfer.js b/lib/entities/banktransfer.js index 26737381..ceb175b1 100644 --- a/lib/entities/banktransfer.js +++ b/lib/entities/banktransfer.js @@ -45,7 +45,7 @@ var BankTransfer = Entity.extend(BankTransferSchema, { return this._super(options); }, fromXmlObj: function(obj) { - _.extend(this, obj); + Object.assign(this, obj); return this; }, toXml: function() { diff --git a/lib/entities/contact.js b/lib/entities/contact.js index 5b2ac444..8e740224 100644 --- a/lib/entities/contact.js +++ b/lib/entities/contact.js @@ -79,7 +79,7 @@ var Contact = Entity.extend(ContactSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'Contact', 'LineItems', 'CreditNotes')); + Object.assign(self, _.omit(obj, 'Contact', 'LineItems', 'CreditNotes')); if (obj.Addresses) { this.extractArray(obj.Addresses.Address, this.Addresses); } diff --git a/lib/entities/entity.js b/lib/entities/entity.js index af629a8d..b0a32045 100644 --- a/lib/entities/entity.js +++ b/lib/entities/entity.js @@ -34,7 +34,7 @@ module.exports.extend = function(schema, classProps, staticProps) { return _.clone(this.tracking._changes); }, fromXmlObj: function(obj) { - return _.extend(this, obj); + return Object.assign(this, obj); }, extractArray: function(src, dest) { var items = this.application.asArray(src); @@ -45,7 +45,7 @@ module.exports.extend = function(schema, classProps, staticProps) { } }) - return Entity.extend(_.extend(classProps, { Entity: Entity }), staticProps); + return Entity.extend(Object.assign(classProps, { Entity: Entity }), staticProps); } diff --git a/lib/entities/invoice.js b/lib/entities/invoice.js index a088a43e..fd8900ab 100644 --- a/lib/entities/invoice.js +++ b/lib/entities/invoice.js @@ -76,7 +76,7 @@ var Invoice = Entity.extend(InvoiceSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'LineItems', 'Payments')); + Object.assign(self, _.omit(obj, 'LineItems', 'Payments')); if (obj.LineItems) { this.extractArray(obj.LineItems.LineItem, this.LineItems); } @@ -89,7 +89,7 @@ var Invoice = Entity.extend(InvoiceSchema, { }, toXml: function() { var invoice = _.omit(this.toObject(), 'LineItems', 'Payments', 'CreditNotes', 'InvoiceID', 'HasAttachments', 'AmountDue', 'AmountPaid', 'FullyPaidOnDate', 'AmountCredited', 'UpdatedDateUTC'); - _.extend(invoice, { LineItems: { LineItem: [] } }); + Object.assign(invoice, { LineItems: { LineItem: [] } }); _.forEach(this.LineItems, function(lineItem) { invoice.LineItems.LineItem.push(lineItem.toObject()); }); diff --git a/lib/entities/journal.js b/lib/entities/journal.js index bd2c16aa..19ff7b6d 100644 --- a/lib/entities/journal.js +++ b/lib/entities/journal.js @@ -48,7 +48,7 @@ var Journal = Entity.extend(JournalSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'JournalLines')); + Object.assign(self, _.omit(obj, 'JournalLines')); if (obj.JournalLines) { var journalLines = this.application.asArray(obj.JournalLines.JournalLine); _.each(journalLines, function(journalLine) { diff --git a/lib/entities/organisation.js b/lib/entities/organisation.js index e8b96562..7261be4e 100644 --- a/lib/entities/organisation.js +++ b/lib/entities/organisation.js @@ -56,7 +56,7 @@ var Organisation = Entity.extend(OrganisationSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'Addresses', 'Phones', 'ExternalLinks')); + Object.assign(self, _.omit(obj, 'Addresses', 'Phones', 'ExternalLinks')); if (obj.Addresses) { _.each(obj.Addresses.Address, function(address) { self.Addresses.push(address); diff --git a/lib/entities/payitems.js b/lib/entities/payitems.js index b6204545..efef58e6 100644 --- a/lib/entities/payitems.js +++ b/lib/entities/payitems.js @@ -76,7 +76,7 @@ var PayItems = Entity.extend(PayItemsSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'BenefitTypes', 'EarningsTypes', 'ReimbursementTypes', 'DeductionTypes', 'TimeOffTypes')); + Object.assign(self, _.omit(obj, 'BenefitTypes', 'EarningsTypes', 'ReimbursementTypes', 'DeductionTypes', 'TimeOffTypes')); if (obj.BenefitTypes) { this.extractArray(obj.BenefitTypes.BenefitType, this.BenefitTypes); } diff --git a/lib/entities/payroll_employee.js b/lib/entities/payroll_employee.js index 8200216d..1a54f333 100644 --- a/lib/entities/payroll_employee.js +++ b/lib/entities/payroll_employee.js @@ -145,14 +145,14 @@ var Employee = Entity.extend(EmployeeSchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations', 'PaymentMethod', 'PayTemplate', 'OpeningBalances')); + Object.assign(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations', 'PaymentMethod', 'PayTemplate', 'OpeningBalances')); if (obj.SalaryAndWages) this.extractArray(obj.SalaryAndWages.SalaryAndWage, this.SalaryAndWages); if (obj.WorkLocations) this.extractArray(obj.WorkLocations.WorkLocation, this.WorkLocations); if (obj.PaymentMethod) { - _.extend(this.PaymentMethod, _.pick(obj.PaymentMethod, 'PaymentMethodType')); + Object.assign(this.PaymentMethod, _.pick(obj.PaymentMethod, 'PaymentMethodType')); if (obj.PaymentMethod.BankAccounts) this.extractArray(obj.PaymentMethod.BankAccounts, this.PaymentMethod.BankAccounts); } diff --git a/lib/entities/timesheet.js b/lib/entities/timesheet.js index 55b3747e..37f32430 100644 --- a/lib/entities/timesheet.js +++ b/lib/entities/timesheet.js @@ -39,7 +39,7 @@ var Timesheet = Entity.extend(TimesheetSchema, { fromXmlObj: function (obj) { var self = this; - _.extend(self, _.omit(obj, 'TimesheetLines')); + Object.assign(self, _.omit(obj, 'TimesheetLines')); if (obj.TimesheetLines) { var items = this.application.asArray(obj.TimesheetLines.TimesheetLine); _.each(items,function(item) @@ -60,7 +60,7 @@ var Timesheet = Entity.extend(TimesheetSchema, { toXml: function () { var timesheet = _.omit(this.toObject(), 'TimesheetLines'); - _.extend(timesheet, { TimesheetLines: []}); + Object.assign(timesheet, { TimesheetLines: []}); _.forEach(this.TimesheetLines, function(timesheetline) { timesheet.TimesheetLines.push({ TimesheetLine: _.pick(timesheetline.toObject(),'EarningsTypeID','TrackingItemID')}); diff --git a/lib/entities/trackingcategory.js b/lib/entities/trackingcategory.js index a21990eb..06996135 100644 --- a/lib/entities/trackingcategory.js +++ b/lib/entities/trackingcategory.js @@ -24,7 +24,7 @@ var TrackingCategory = Entity.extend(TrackingCategorySchema, { }, fromXmlObj: function(obj) { var self = this; - _.extend(self, _.omit(obj, 'Options')); + Object.assign(self, _.omit(obj, 'Options')); if (obj.Options) { _.each(this.application.asArray(obj.Options.Option), function(option) { self.Options.push(option); @@ -36,7 +36,7 @@ var TrackingCategory = Entity.extend(TrackingCategorySchema, { toXml: function() { var trackingCategory = _.omit(this.toObject(), 'Options'); // Options cannot be saved using this endpoint, they must use the specific /options endpoint - // _.extend(trackingCategory, { Options: [] }); + // Object.assign(trackingCategory, { Options: [] }); // _.forEach(this.Options, function(option) { // trackingCategory.Options.push({ Option: option.toObject() }) // }) diff --git a/lib/entity_helpers/accounts.js b/lib/entity_helpers/accounts.js index 6a0404e2..7389ff7d 100644 --- a/lib/entity_helpers/accounts.js +++ b/lib/entity_helpers/accounts.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Accounts = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Account', entityPlural: 'Accounts' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Account', entityPlural: 'Accounts' }, options)); }, newAccount: function(data, options) { return new Account(this.application, data, options) diff --git a/lib/entity_helpers/attachments.js b/lib/entity_helpers/attachments.js index 68a48a90..f6e8d9f8 100644 --- a/lib/entity_helpers/attachments.js +++ b/lib/entity_helpers/attachments.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Attachments = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Attachment', entityPlural: 'Attachments' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Attachment', entityPlural: 'Attachments' }, options)); }, newAttachment: function(data, options) { return new Attachment(this.application, data, options) @@ -19,7 +19,7 @@ var Attachments = EntityHelper.extend({ }) }, getAttachments: function(ownerPath, options) { - var clonedOptions = _.extend({}, options, { path: ownerPath + '/Attachments' }); + var clonedOptions = Object.assign({}, options, { path: ownerPath + '/Attachments' }); clonedOptions.entityConstructor = function(data) { return self.newAttachment(data) }; return this.getEntities(clonedOptions); } diff --git a/lib/entity_helpers/banktransactions.js b/lib/entity_helpers/banktransactions.js index 00b821ad..e8d046eb 100644 --- a/lib/entity_helpers/banktransactions.js +++ b/lib/entity_helpers/banktransactions.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var BankTransactions = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'BankTransaction', entityPlural: 'BankTransactions' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransaction', entityPlural: 'BankTransactions' }, options)); }, newBankTransaction: function(data, options) { return new BankTransaction(this.application, data, options) diff --git a/lib/entity_helpers/banktransfers.js b/lib/entity_helpers/banktransfers.js index a8d5f033..9f8da4ab 100644 --- a/lib/entity_helpers/banktransfers.js +++ b/lib/entity_helpers/banktransfers.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var BankTransfers = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options)); }, newBankTransfer: function(data, options) { return new BankTransfer(this.application, data, options) diff --git a/lib/entity_helpers/contacts.js b/lib/entity_helpers/contacts.js index bb902ee2..d12b677a 100644 --- a/lib/entity_helpers/contacts.js +++ b/lib/entity_helpers/contacts.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Contacts = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Contact', entityPlural: 'Contacts' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Contact', entityPlural: 'Contacts' }, options)); }, newContact: function(data, options) { return new Contact(this.application, data, options) diff --git a/lib/entity_helpers/entity_helper.js b/lib/entity_helpers/entity_helper.js index f7e9ffcf..eec7b0a4 100644 --- a/lib/entity_helpers/entity_helper.js +++ b/lib/entity_helpers/entity_helper.js @@ -18,7 +18,7 @@ function EntityHelper(application, options) { } EntityHelper.extend = extend; -_.extend(EntityHelper.prototype, { +Object.assign(EntityHelper.prototype, { saveEntities: function(entities, options) { logger.debug('EntityHelper::saveEntities'); options = options || {}; diff --git a/lib/entity_helpers/invoices.js b/lib/entity_helpers/invoices.js index 4224bd16..ddf82c24 100644 --- a/lib/entity_helpers/invoices.js +++ b/lib/entity_helpers/invoices.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Invoices = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Invoice', entityPlural: 'Invoices' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Invoice', entityPlural: 'Invoices' }, options)); }, newInvoice: function(data, options) { return new Invoice(this.application, data, options) diff --git a/lib/entity_helpers/items.js b/lib/entity_helpers/items.js index f14fc361..3f1f3b5d 100644 --- a/lib/entity_helpers/items.js +++ b/lib/entity_helpers/items.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Items = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Item', entityPlural: 'Items' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Item', entityPlural: 'Items' }, options)); }, newItem: function(data, options) { return new Item(this.application, data, options) diff --git a/lib/entity_helpers/organisations.js b/lib/entity_helpers/organisations.js index 536027ce..c643114b 100644 --- a/lib/entity_helpers/organisations.js +++ b/lib/entity_helpers/organisations.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Organisations = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Organisation', entityPlural: 'Organisations' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Organisation', entityPlural: 'Organisations' }, options)); }, getOrganisations: function(options, callback) { var self = this; diff --git a/lib/entity_helpers/payitems.js b/lib/entity_helpers/payitems.js index aa136b30..e88ac005 100644 --- a/lib/entity_helpers/payitems.js +++ b/lib/entity_helpers/payitems.js @@ -12,7 +12,7 @@ var _ = require('lodash') var PayItems = EntityHelper.extend({ constructor: function (application, options) { - EntityHelper.call(this, application, _.extend({ + EntityHelper.call(this, application, Object.assign({ entityPlural: 'PayItems', path: 'Payitems'}, options)); }, newPayItems: function(data, options) @@ -42,7 +42,7 @@ var PayItems = EntityHelper.extend({ getPayItems: function (options) { var self = this; - var clonedOptions = _.extend({},options, { api: 'payroll'}); + var clonedOptions = Object.assign({},options, { api: 'payroll'}); clonedOptions.entityConstructor = function(data) { return self.newPayItems(data)}; return this.getEntities(clonedOptions) } diff --git a/lib/entity_helpers/payments.js b/lib/entity_helpers/payments.js index 73ae93f1..10f93256 100644 --- a/lib/entity_helpers/payments.js +++ b/lib/entity_helpers/payments.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Payments = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Payment', entityPlural: 'Payments' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Payment', entityPlural: 'Payments' }, options)); }, createPayment: function(data, options) { return new Payment(this.application, data, options); diff --git a/lib/entity_helpers/payroll_employees.js b/lib/entity_helpers/payroll_employees.js index 4660d6e8..648a3471 100644 --- a/lib/entity_helpers/payroll_employees.js +++ b/lib/entity_helpers/payroll_employees.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Employees = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'Employee', entityPlural: 'Employees' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'Employee', entityPlural: 'Employees' }, options)); }, newEmployee: function(data, options) { return new Employee(this.application, data, options) @@ -23,7 +23,7 @@ var Employees = EntityHelper.extend({ }, getEmployees: function(options) { var self = this; - var clonedOptions = _.extend({}, options, { api: 'payroll' }); + var clonedOptions = Object.assign({}, options, { api: 'payroll' }); clonedOptions.entityConstructor = function(data) { return self.newEmployee(data) }; return this.getEntities(clonedOptions) } diff --git a/lib/entity_helpers/taxrates.js b/lib/entity_helpers/taxrates.js index 84b3edd6..41a727ef 100644 --- a/lib/entity_helpers/taxrates.js +++ b/lib/entity_helpers/taxrates.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var TaxRates = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'TaxRate', entityPlural: 'TaxRates' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'TaxRate', entityPlural: 'TaxRates' }, options)); }, newTaxRate: function(data, options) { return new TaxRate(this.application, data, options); diff --git a/lib/entity_helpers/timesheets.js b/lib/entity_helpers/timesheets.js index 27caa26b..9aa4dec6 100644 --- a/lib/entity_helpers/timesheets.js +++ b/lib/entity_helpers/timesheets.js @@ -7,7 +7,7 @@ var _ = require('lodash') var Timesheets = EntityHelper.extend({ constructor: function (application, options) { - EntityHelper.call(this, application, _.extend({ entityName:'Timesheet', entityPlural:'Timesheets'}, options)); + EntityHelper.call(this, application, Object.assign({ entityName:'Timesheet', entityPlural:'Timesheets'}, options)); }, newTimesheet: function (data, options) { @@ -23,12 +23,12 @@ var Timesheets = EntityHelper.extend({ }, saveTimesheets: function (timesheets, options) { - return this.saveEntities(timesheets, _.extend({},options,{ method: 'post',api: 'payroll'})); + return this.saveEntities(timesheets, Object.assign({},options,{ method: 'post',api: 'payroll'})); }, getTimesheets: function (options) { var self = this; - var clonedOptions = _.extend({},options, { api: 'payroll'}); + var clonedOptions = Object.assign({},options, { api: 'payroll'}); clonedOptions.entityConstructor = function(data) { return self.newTimesheet(data)}; return this.getEntities(clonedOptions) } diff --git a/lib/entity_helpers/trackingcategories.js b/lib/entity_helpers/trackingcategories.js index c659e8c9..412d0930 100644 --- a/lib/entity_helpers/trackingcategories.js +++ b/lib/entity_helpers/trackingcategories.js @@ -7,7 +7,7 @@ var _ = require('lodash'), var TrackingCategories = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'TrackingCategory', entityPlural: 'TrackingCategories' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'TrackingCategory', entityPlural: 'TrackingCategories' }, options)); }, newTrackingCategory: function(data, options) { return new TrackingCategory(this.application, data, options) diff --git a/lib/entity_helpers/users.js b/lib/entity_helpers/users.js index 6b2d3caa..414f59ff 100644 --- a/lib/entity_helpers/users.js +++ b/lib/entity_helpers/users.js @@ -6,7 +6,7 @@ var _ = require('lodash'), var Users = EntityHelper.extend({ constructor: function(application, options) { - EntityHelper.call(this, application, _.extend({ entityName: 'User', entityPlural: 'Users' }, options)); + EntityHelper.call(this, application, Object.assign({ entityName: 'User', entityPlural: 'Users' }, options)); }, newUser: function(data, options) { return new User(this.application, data, options) diff --git a/lib/logger.js b/lib/logger.js index fd128da2..1dec5dd7 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -33,7 +33,7 @@ Logger.prototype = { } log4js.configure({ appenders: appenders, replaceConsole: false }); this.setLevel(settings.level);*/ - _.extend(this.settings, settings); + Object.assign(this.settings, settings); }, init: function(settings) { diff --git a/lib/misc/extend.js b/lib/misc/extend.js index 700f94fb..7ab3b6e0 100644 --- a/lib/misc/extend.js +++ b/lib/misc/extend.js @@ -19,7 +19,7 @@ module.exports = function (protoProps, staticProps) } // Inherit class (static) properties from parent. - _.extend(child, parent); + Object.assign(child, parent); // Set the prototype chain to inherit from `parent`, without calling // `parent`'s constructor function. @@ -30,7 +30,7 @@ module.exports = function (protoProps, staticProps) // if supplied. if (protoProps) { - _.extend(child.prototype, protoProps); + Object.assign(child.prototype, protoProps); // Copy the properties over onto the new prototype for (var name in protoProps) @@ -75,7 +75,7 @@ module.exports = function (protoProps, staticProps) } // Add static properties to the constructor function, if supplied. - if (staticProps) _.extend(child, staticProps); + if (staticProps) Object.assign(child, staticProps); // Correctly set child's `prototype.constructor`. child.prototype.constructor = child; diff --git a/lib/payroll.js b/lib/payroll.js index a9f74b08..4f930f04 100644 --- a/lib/payroll.js +++ b/lib/payroll.js @@ -23,12 +23,12 @@ function Payroll(application, options) } // Static -_.extend(Payroll, { +Object.assign(Payroll, { }) // Instance -_.extend(Payroll.prototype, { +Object.assign(Payroll.prototype, { }) diff --git a/lib/schemaobject/schemaobject.js b/lib/schemaobject/schemaobject.js index 14c46a7a..14cec91e 100644 --- a/lib/schemaobject/schemaobject.js +++ b/lib/schemaobject/schemaobject.js @@ -611,7 +611,7 @@ var Tracking = function(instance) { this._instance = instance; } -_.extend(Tracking.prototype, { +Object.assign(Tracking.prototype, { clear: function() { var self = this; _.each(this._instance._schema, function(properties, index) { From 560950b4b8bfd8d4301cb5607e592269e8f380a9 Mon Sep 17 00:00:00 2001 From: Jordan Walsh Date: Wed, 8 Mar 2017 17:14:00 +1100 Subject: [PATCH 2/2] migrated config files to their own directories --- .gitignore | 1 + sample_app/config/example_config.json | 15 ++ sample_app/sample_app.js | 2 +- test/accountingtests.js | 220 +++++++++--------- .../config/example_testing_config.json | 8 +- 5 files changed, 133 insertions(+), 113 deletions(-) create mode 100644 sample_app/config/example_config.json rename example_testing_config.json => test/config/example_testing_config.json (78%) diff --git a/.gitignore b/.gitignore index af228d90..4616fa53 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ .DS_Store .vscode testing_config.json +sample_app/config/config.json \ No newline at end of file diff --git a/sample_app/config/example_config.json b/sample_app/config/example_config.json new file mode 100644 index 00000000..68f17b2e --- /dev/null +++ b/sample_app/config/example_config.json @@ -0,0 +1,15 @@ +{ + "APPTYPE": "PARTNER", + "partner": { + "authorizeCallbackUrl": "https://example.com/xerocallback", + "consumerKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "privateKeyPath": "/some/path/to/privatekey.pem", + "userAgent": "Tester (PARTNER) - Application for testing Xero" + }, + "public": { + "authorizeCallbackUrl": "https://example.com/xerocallback", + "consumerKey": "AAAAAAAAAAAAAAAAAA", + "consumerSecret": "BBBBBBBBBBBBBBBBBBBB", + "userAgent": "Tester (PUBLIC) - Application for testing Xero" + } +} \ No newline at end of file diff --git a/sample_app/sample_app.js b/sample_app/sample_app.js index a5767ad3..be1ed3b0 100644 --- a/sample_app/sample_app.js +++ b/sample_app/sample_app.js @@ -4,7 +4,7 @@ var express = require('express'), LRU = require('lru-cache'), fs = require('fs'), nodemailer = require('nodemailer'), - metaConfig = require('../testing_config.json'); + metaConfig = require('./config/config.json'); function getXeroApp(session) { var APPTYPE = metaConfig.APPTYPE; diff --git a/test/accountingtests.js b/test/accountingtests.js index d78d253b..94958d4e 100644 --- a/test/accountingtests.js +++ b/test/accountingtests.js @@ -7,7 +7,7 @@ var chai = require('chai'), Browser = require('zombie'), uuid = require('uuid'), fs = require('fs'), - metaConfig = require('../testing_config.json'); + metaConfig = require('./config/testing_config.json'); process.on('uncaughtException', function(err) { console.log('uncaught', err) @@ -97,8 +97,8 @@ describe('get access for public or partner application', function() { describe('submits form', function() { var options = { - XeroUsername: config.xeroUsername, - XeroPassword: config.xeroPassword + XeroUsername: config.xeroUsername, + XeroPassword: config.xeroPassword }; it('should login', function(done) { @@ -182,47 +182,47 @@ describe('regression tests', function() { var bankAccounts = []; before('create a bank account', function() { - const randomString = uuid.v4(); - - var testAccountData = { - Code: randomString.replace(/-/g,'').substring(0, 10), - Name: 'Test account from Node SDK ' + randomString, - Type: 'BANK', - BankAccountNumber: '062-021-0000000', - }; - - var account = currentApp.core.accounts.newAccount(testAccountData); - - return account.save() - .then(function(response) { - var account = response.entities[0]; - bankAccounts.push({ - account: account, - id: account.AccountID - }); - }); + const randomString = uuid.v4(); + + var testAccountData = { + Code: randomString.replace(/-/g, '').substring(0, 10), + Name: 'Test account from Node SDK ' + randomString, + Type: 'BANK', + BankAccountNumber: '062-021-0000000', + }; + + var account = currentApp.core.accounts.newAccount(testAccountData); + + return account.save() + .then(function(response) { + var account = response.entities[0]; + bankAccounts.push({ + account: account, + id: account.AccountID + }); + }); }); before('create another bank account', function() { - const randomString = uuid.v4(); - - var testAccountData = { - Code: randomString.replace(/-/g,'').substring(0, 10), - Name: 'Test account from Node SDK ' + randomString, - Type: 'BANK', - BankAccountNumber: '062-021-0000000', - }; - - var account = currentApp.core.accounts.newAccount(testAccountData); - - return account.save() - .then(function(response) { - var account = response.entities[0]; - bankAccounts.push({ - account: account, - id: account.AccountID - }); - }); + const randomString = uuid.v4(); + + var testAccountData = { + Code: randomString.replace(/-/g, '').substring(0, 10), + Name: 'Test account from Node SDK ' + randomString, + Type: 'BANK', + BankAccountNumber: '062-021-0000000', + }; + + var account = currentApp.core.accounts.newAccount(testAccountData); + + return account.save() + .then(function(response) { + var account = response.entities[0]; + bankAccounts.push({ + account: account, + id: account.AccountID + }); + }); }); // There appears to be no way to archive a bank account via the API @@ -387,7 +387,7 @@ describe('regression tests', function() { var testAccountId = ""; var testAccountData = { - Code: randomString.replace(/-/g,'').substring(0, 10), + Code: randomString.replace(/-/g, '').substring(0, 10), Name: 'Test account from Node SDK ' + randomString, Type: 'EXPENSE' }; @@ -586,25 +586,25 @@ describe('regression tests', function() { var testAccount; before('create an account to pay into', function() { - const randomString = uuid.v4(); + const randomString = uuid.v4(); - var testAccountData = { - Code: randomString.replace(/-/g,'').substring(0, 10), - Name: 'Test account from Node SDK ' + randomString, - Type: 'SALES', - EnablePaymentsToAccount: true - }; + var testAccountData = { + Code: randomString.replace(/-/g, '').substring(0, 10), + Name: 'Test account from Node SDK ' + randomString, + Type: 'SALES', + EnablePaymentsToAccount: true + }; - testAccountCode = testAccountData.Code; + testAccountCode = testAccountData.Code; - var account = currentApp.core.accounts.newAccount(testAccountData); + var account = currentApp.core.accounts.newAccount(testAccountData); - return account.save() - .then(function(response) { - var account = response.entities[0]; - testAccountId = account.AccountID; - testAccount = account; - }); + return account.save() + .then(function(response) { + var account = response.entities[0]; + testAccountId = account.AccountID; + testAccount = account; + }); }); after('archive the test account', function() { @@ -922,60 +922,60 @@ describe('regression tests', function() { 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' - } + .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'); + }); + 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'); + }); }); - }); - return currentApp.core.trackingCategories.deleteTrackingCategory(trackingCategoryID) - }) - .catch(function(err) { - console.log(util.inspect(err, null, null)); - done(wrapError(err)); - }) - }); + return currentApp.core.trackingCategories.deleteTrackingCategory(trackingCategoryID) + }) + .catch(function(err) { + console.log(util.inspect(err, null, null)); + done(wrapError(err)); + }) + }); }); //unfortunately this will only work on tracking categories that have been used. @@ -1428,4 +1428,4 @@ function wrapError(err) { return err; else if (err.statusCode) return new Error(err.statusCode + ': ' + err.exception.Message); -} +} \ No newline at end of file diff --git a/example_testing_config.json b/test/config/example_testing_config.json similarity index 78% rename from example_testing_config.json rename to test/config/example_testing_config.json index 2c0e81b3..275a725c 100644 --- a/example_testing_config.json +++ b/test/config/example_testing_config.json @@ -5,6 +5,7 @@ "consumerKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "privateKeyPath": "/some/path/to/privatekey.pem", "userAgent": "Tester (PARTNER) - Application for testing Xero", + //Only used for test purposes, not required for general usage. "xeroPassword": "XXXXXXXXXX", "xeroUsername": "foo@example.com" }, @@ -18,6 +19,9 @@ "authorizeCallbackUrl": "https://example.com/xerocallback", "consumerKey": "AAAAAAAAAAAAAAAAAA", "consumerSecret": "BBBBBBBBBBBBBBBBBBBB", - "userAgent": "Tester (PUBLIC) - Application for testing Xero" + "userAgent": "Tester (PUBLIC) - Application for testing Xero", + //Only used for test purposes, not required for general usage. + "xeroPassword": "XXXXXXXXXX", + "xeroUsername": "foo@example.com" } -} +} \ No newline at end of file