From 13e48b1ca765866782f9c5c1a65d3ada513db33a Mon Sep 17 00:00:00 2001 From: Jordan Walsh Date: Tue, 12 Sep 2017 14:32:54 +1000 Subject: [PATCH 1/2] added support for redirectOnError parameter in the config --- README.md | 7 ++-- lib/application.js | 6 ++-- lib/oauth/oauth.js | 2 -- package.json | 2 +- test/testrunner.js | 84 +++++++++++++++++++++++----------------------- 5 files changed, 52 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 6eaed3b4..68d6a2c9 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ This package can be installed via npm or yarn. | AuthorizeCallbackUrl | The callback that Xero should invoke when the authorization is successful. | False | | privateKeyPath | The filesystem path to your privatekey.pem file to sign the API calls | False | | runscopeBucketId | Your personal runscope bucket for debugging API calls | False | +| redirectOnError | Whether the Xero Auth process should redirect to your app in the event the user clicks 'Cancel' | False | --- ```javascript @@ -91,7 +92,8 @@ This package can be installed via npm or yarn. "consumerKey": "AAAAAAAAAAAAAAAAAA", "consumerSecret": "BBBBBBBBBBBBBBBBBBBB", "authorizeCallbackUrl": 'https://www.mywebsite.com/xerocallback', - "runscopeBucketId" : "xxxyyyzzzz" + "runscopeBucketId" : "xxxyyyzzzz", + "redirectOnError" : true } //Sample Partner App Config @@ -101,7 +103,8 @@ This package can be installed via npm or yarn. "consumerSecret": "BBBBBBBBBBBBBBBBBBBB", "authorizeCallbackUrl": 'https://www.mywebsite.com/xerocallback', "privateKeyPath" : "/some/path/to/partner_privatekey.pem", - "runscopeBucketId" : "xxxyyyzzzz" + "runscopeBucketId" : "xxxyyyzzzz", + "redirectOnError" : true } ``` diff --git a/lib/application.js b/lib/application.js index c4494222..2313af9a 100644 --- a/lib/application.js +++ b/lib/application.js @@ -71,6 +71,7 @@ Object.assign(Application, { coreAPIEndPointUrl: '/api.xro/2.0/', payrollAPIEndPointUrl: '/payroll.xro/1.0/', pageMaxRecords: 100, + redirectOnError: false }, }); @@ -581,7 +582,6 @@ var PrivateApplication = Application.extend({ var RequireAuthorizationApplication = Application.extend({ constructor: function(options) { - Application.call(this, options); }, init: function() { @@ -652,6 +652,9 @@ var RequireAuthorizationApplication = Application.extend({ }); }, buildAuthorizeUrl: function(requestToken, other) { + other = other || {}; + other['redirectOnError'] = this.options.redirectOnError + var q = Object.assign({}, { oauth_token: requestToken }, other); return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q); }, @@ -674,7 +677,6 @@ var RequireAuthorizationApplication = Application.extend({ var PublicApplication = RequireAuthorizationApplication.extend({ constructor: function(config) { - RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'public' })); }, init: function() { diff --git a/lib/oauth/oauth.js b/lib/oauth/oauth.js index b1d01714..8efd0c89 100644 --- a/lib/oauth/oauth.js +++ b/lib/oauth/oauth.js @@ -204,7 +204,6 @@ exports.OAuth.prototype._createSignatureBase = function(method, url, parameters) //Added to support runscope usage try { url = url.split("runscope.net")[1].replace(/^/, "https://api.xero.com"); - } catch (e) { //do nothing. This error only occurs if runscope isn't in the url. } @@ -505,7 +504,6 @@ exports.OAuth.prototype.get = function(url, oauth_token, oauth_token_secret, cal return this._performSecureRequest(oauth_token, oauth_token_secret, "GET", url, null, "", null, callback, options); } - exports.OAuth.prototype._putOrPost = function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) { var extra_params = null; if (typeof post_content_type == "function") { diff --git a/package.json b/package.json index 77234eb0..0ba154dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xero-node", - "version": "2.6.0", + "version": "2.7.0", "description": "Xero API Wrapper for all application types", "main": "lib/index.js", "directories": { diff --git a/test/testrunner.js b/test/testrunner.js index f1eb9444..06370937 100644 --- a/test/testrunner.js +++ b/test/testrunner.js @@ -23,48 +23,48 @@ describe('Accounting API Tests', () => { }); // Accounting (Core) API Tests - // importTest('organisation_tests', `${__dirname}/core/organisation_tests.js`); - // importTest('accounts_tests', `${__dirname}/core/accounts_tests.js`); - // importTest('creditnotes_tests', `${__dirname}/core/creditnotes_tests.js`); - // importTest('currencies_tests', `${__dirname}/core/currencies_tests.js`); - // importTest('report_tests', `${__dirname}/core/report_tests.js`); - // importTest( - // 'invoicereminder_tests', - // `${__dirname}/core/invoicereminder_tests.js` - // ); - // importTest('brandingtheme_tests', `${__dirname}/core/brandingtheme_tests.js`); - // importTest('taxrate_tests', `${__dirname}/core/taxrate_tests.js`); - // importTest('invoices_tests', `${__dirname}/core/invoices_tests.js`); - // importTest('payments_tests', `${__dirname}/core/payments_tests.js`); - // importTest( - // 'banktransactions_tests', - // `${__dirname}/core/banktransactions_tests.js` - // ); - // importTest('banktransfers_tests', `${__dirname}/core/banktransfers_tests.js`); - // importTest( - // 'trackingcategories_tests', - // `${__dirname}/core/trackingcategories_tests.js` - // ); - // importTest('items_tests', `${__dirname}/core/items_tests.js`); - // importTest('contacts_tests', `${__dirname}/core/contacts_tests.js`); - // importTest('journals_tests', `${__dirname}/core/journals_tests.js`); - // importTest( - // 'manualjournals_tests', - // `${__dirname}/core/manualjournal_tests.js` - // ); - // importTest('users_tests', `${__dirname}/core/users_tests.js`); - // importTest( - // 'repeatinginvoice_tests', - // `${__dirname}/core/repeatinginvoice_tests.js` - // ); - // importTest('contactgroups_tests', `${__dirname}/core/contactgroups_tests.js`); - // importTest('employees_tests', `${__dirname}/core/employees_tests.js`); - // importTest('receipts_tests', `${__dirname}/core/receipts_tests.js`); - // importTest('expenseclaims_tests', `${__dirname}/core/expenseclaims_tests.js`); - // importTest( - // 'purchaseorders_tests', - // `${__dirname}/core/purchaseorders_tests.js` - // ); + importTest('organisation_tests', `${__dirname}/core/organisation_tests.js`); + importTest('accounts_tests', `${__dirname}/core/accounts_tests.js`); + importTest('creditnotes_tests', `${__dirname}/core/creditnotes_tests.js`); + importTest('currencies_tests', `${__dirname}/core/currencies_tests.js`); + importTest('report_tests', `${__dirname}/core/report_tests.js`); + importTest( + 'invoicereminder_tests', + `${__dirname}/core/invoicereminder_tests.js` + ); + importTest('brandingtheme_tests', `${__dirname}/core/brandingtheme_tests.js`); + importTest('taxrate_tests', `${__dirname}/core/taxrate_tests.js`); + importTest('invoices_tests', `${__dirname}/core/invoices_tests.js`); + importTest('payments_tests', `${__dirname}/core/payments_tests.js`); + importTest( + 'banktransactions_tests', + `${__dirname}/core/banktransactions_tests.js` + ); + importTest('banktransfers_tests', `${__dirname}/core/banktransfers_tests.js`); + importTest( + 'trackingcategories_tests', + `${__dirname}/core/trackingcategories_tests.js` + ); + importTest('items_tests', `${__dirname}/core/items_tests.js`); + importTest('contacts_tests', `${__dirname}/core/contacts_tests.js`); + importTest('journals_tests', `${__dirname}/core/journals_tests.js`); + importTest( + 'manualjournals_tests', + `${__dirname}/core/manualjournal_tests.js` + ); + importTest('users_tests', `${__dirname}/core/users_tests.js`); + importTest( + 'repeatinginvoice_tests', + `${__dirname}/core/repeatinginvoice_tests.js` + ); + importTest('contactgroups_tests', `${__dirname}/core/contactgroups_tests.js`); + importTest('employees_tests', `${__dirname}/core/employees_tests.js`); + importTest('receipts_tests', `${__dirname}/core/receipts_tests.js`); + importTest('expenseclaims_tests', `${__dirname}/core/expenseclaims_tests.js`); + importTest( + 'purchaseorders_tests', + `${__dirname}/core/purchaseorders_tests.js` + ); importTest('attachment_tests', `${__dirname}/core/attachment_tests.js`); }); From 3b6c29147a72753991256a6a739ca1a4bbc932f3 Mon Sep 17 00:00:00 2001 From: Jordan Walsh Date: Wed, 13 Sep 2017 17:17:42 +1000 Subject: [PATCH 2/2] fixed tests --- README.md | 2 +- test/core/receipts_tests.js | 2 +- test/mocha.opts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2ee5dff..b1575d11 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ This package can be installed via npm or yarn. | userAgent | The useragent that should be used with all calls to the Xero API | True | | consumerKey | The consumer key that is required with all calls to the Xero API., | True | | consumerSecret | The secret key from the developer portal that is required to authenticate your API calls | True | -| AuthorizeCallbackUrl | The callback that Xero should invoke when the authorization is successful. | False | +| authorizeCallbackUrl | The callback that Xero should invoke when the authorization is successful. | False | | privateKeyPath | The filesystem path to your privatekey.pem file to sign the API calls | False | | runscopeBucketId | Your personal runscope bucket for debugging API calls | False | | redirectOnError | Whether the Xero Auth process should redirect to your app in the event the user clicks 'Cancel' | False | diff --git a/test/core/receipts_tests.js b/test/core/receipts_tests.js index 1934fa29..dcebaf4f 100644 --- a/test/core/receipts_tests.js +++ b/test/core/receipts_tests.js @@ -129,7 +129,7 @@ describe('Receipts', () => { it('create multiple Receipts', done => { const Receipts = []; - for (let i = 0; i < 2; i += 1) { + for (let i = 0; i < 10; i += 1) { const newReceipt = {}; Object.assign(newReceipt, sampleReceipt); newReceipt.ReceiptID = undefined; diff --git a/test/mocha.opts b/test/mocha.opts index ef42e1dc..4effd056 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1 @@ ---timeout 60000 +--timeout 120000