Skip to content

Commit

Permalink
added support for Partner application types
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Feb 28, 2017
1 parent 57066c8 commit 8a310f2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 67 deletions.
13 changes: 5 additions & 8 deletions lib/application.js
Expand Up @@ -427,7 +427,8 @@ populateOptions = function(configFilePath) {
options["consumerKey"] = config.ConsumerKey;
options["consumerSecret"] = config.ConsumerSecret;
options["privateKeyPath"] = config.PrivateKeyPath;
options["userAgent"] = config.UserAgent || "Xero Node.js SDK";
options["sslCertPath"] = config.SSLCertPath;
options["userAgent"] = config.UserAgent || "Xero - Node.js SDK";
options["runscopeBucketId"] = config.RunscopeBucketId;

if (options["runscopeBucketId"] && options["runscopeBucketId"] !== "") {
Expand Down Expand Up @@ -531,17 +532,13 @@ var PublicApplication = RequireAuthorizationApplication.extend({
"HMAC-SHA1",
null, { 'User-Agent': this.options.userAgent }
);

}
});

var PartnerApplication = RequireAuthorizationApplication.extend({
constructor: function(options) {
constructor: function(configFilePath) {
logger.debug('PartnerApplication::constructor');
options = options || {};
//options.coreAPIEndPointUrl = 'https://api-partner.network.xero.com/api.xro/2.0/';

RequireAuthorizationApplication.call(this, _.extend({}, options, { type: 'partner' }));
RequireAuthorizationApplication.call(this, _.extend({}, populateOptions(configFilePath), { type: 'partner' }));
},

init: function() {
Expand All @@ -558,7 +555,7 @@ var PartnerApplication = RequireAuthorizationApplication.extend({
null, { 'User-Agent': this.options.userAgent }
);
//use SSL certificate
var keyCert = fs.readFileSync(this.options.sslKeyPath);
var keyCert = fs.readFileSync(this.options.privateKeyPath);
var cert = fs.readFileSync(this.options.sslCertPath);
this.oa._createClient = function(port, hostname, method, path, headers, sslEnabled) {
var options = {
Expand Down
110 changes: 51 additions & 59 deletions test/accountingtests.js
Expand Up @@ -13,35 +13,25 @@ process.on('uncaughtException', function(err) {
var currentApp;
var organisationCountry = "";

var APPTYPE = "PUBLIC";
var APPTYPE = "PRIVATE";
var privateConfigFile = "/Users/jordan.walsh/.xero/private_app_config.json";
var publicConfigFile = "/Users/jordan.walsh/.xero/public_app_config.json";
var configFile = "";

switch (APPTYPE) {
case "PUBLIC":
configFile = publicConfigFile;
break;

case "PRIVATE":
configFile = privateConfigFile;
break;

default:
throw "No Config File Selected!!"
}
var partnerConfigFile = "/Users/jordan.walsh/.xero/partner_app_config.json";

describe('create application', function() {
describe('create instance', function() {
it('init instance and set options', function(done) {
//This constructor looks in ~/.xero/config.json for settings

switch (APPTYPE) {
case "PRIVATE":
currentApp = new xero.PrivateApplication(privateConfigFile);
break;
case "PUBLIC":
currentApp = new xero.PublicApplication(configFile);
currentApp = new xero.PublicApplication(publicConfigFile);
break;
case "PRIVATE":
currentApp = new xero.PrivateApplication(configFile);
case "PARTNER":
currentApp = new xero.PartnerApplication(partnerConfigFile);
break;
default:
throw "No App Type Set!!"
Expand All @@ -52,24 +42,16 @@ describe('create application', function() {
});
});

describe('get access for public application', function() {

beforeEach(function() {
if (APPTYPE !== "PUBLIC") {
this.skip();
}
});

describe('create instance', function() {
it('init instance and set options', function(done) {
//This constructor looks in ~/.xero/config.json for settings
currentApp = new xero.PublicApplication(configFile);
done();
})
});
describe('get access for public or partner application', function() {

describe('Get tokens', function() {

beforeEach(function() {
if (APPTYPE === "PRIVATE") {
this.skip();
}
});

var authoriseUrl = "";
var requestToken = "";
var requestSecret = "";
Expand Down Expand Up @@ -111,10 +93,11 @@ describe('get access for public application', function() {
//browser.debug();

before(function(done) {
if (APPTYPE === "PUBLIC")
browser.visit(authoriseUrl, done);
else
if (APPTYPE === "PRIVATE") {
this.skip();
}

browser.visit(authoriseUrl, done);
});

describe('submits form', function() {
Expand All @@ -123,22 +106,24 @@ describe('get access for public application', function() {
var options = {};

before(function(done) {
if (APPTYPE !== "PUBLIC") {

if (APPTYPE === "PRIVATE") {
this.skip();
} else {
try {
console.log('configFile: ' + configFile);
}

var config = require(configFile);
options["XeroUsername"] = config.XeroUsername;
options["XeroPassword"] = config.XeroPassword;
done();
} catch (e) {
var err = 'Couldn\'t read config.json from [' + configFile + ']. Exiting...';
console.log(err);
throw e;
}
try {
console.log('configFile: ' + configFile);

var config = require(configFile);
options["XeroUsername"] = config.XeroUsername;
options["XeroPassword"] = config.XeroPassword;
done();
} catch (e) {
var err = 'Couldn\'t read config.json from [' + configFile + ']. Exiting...';
console.log(err);
throw e;
}

});

it('should login', function(done) {
Expand Down Expand Up @@ -168,7 +153,14 @@ describe('get access for public application', function() {
//console.log(browser.document.documentElement.innerHTML);
browser.assert.text('title', 'Xero | Authorise Application');
browser.select('select', 'MWE5NzdkMDItZTAyNC00NGJkLTlmMGQtNjFiOGI4OWY2YTI4-ecmd9rxRfsM=');
browser.pressButton("Allow access for 30 mins");

if (APPTYPE === "PUBLIC") {
browser.pressButton("Allow access for 30 mins");
} else {
//It must be a partner app
browser.pressButton("Allow access");
}

browser.wait().then(function() {
// just dump some debug data to see if we're on the right page
//console.log(browser.document.documentElement.innerHTML);
Expand Down Expand Up @@ -432,7 +424,7 @@ describe('regression tests', function() {

});

describe('invoices', function() {
describe.skip('invoices', function() {

it('create invoice', function(done) {
this.timeout(10000);
Expand Down Expand Up @@ -532,7 +524,7 @@ describe('regression tests', function() {
})
});

describe('payments', function() {
describe.skip('payments', function() {
/* Please note that this test pays an invoice created in the previous tests */
this.timeout(10000);
it('Create Payment', function(done) {
Expand Down Expand Up @@ -620,7 +612,7 @@ describe('regression tests', function() {

});

describe('bank transactions', function() {
describe.skip('bank transactions', function() {

var sharedTransaction;

Expand Down Expand Up @@ -687,7 +679,7 @@ describe('regression tests', function() {
});
});

describe('bank transfers', function() {
describe.skip('bank transfers', function() {

this.timeout(20000);

Expand Down Expand Up @@ -752,7 +744,7 @@ describe('regression tests', function() {

});

describe('tracking categories', function() {
describe.skip('tracking categories', function() {
this.timeout(20000);

var sampleTrackingCategory = {
Expand Down Expand Up @@ -911,7 +903,7 @@ describe('regression tests', function() {
});
});

describe('items', function() {
describe.skip('items', function() {
this.timeout(10000);

var sampleItem = {
Expand Down Expand Up @@ -1020,7 +1012,7 @@ describe('regression tests', function() {
});
});

describe('contacts', function() {
describe.skip('contacts', function() {
var sampleContact = {
Name: 'Johnnies Coffee' + Math.random(),
FirstName: 'John',
Expand Down Expand Up @@ -1209,7 +1201,7 @@ describe('regression tests', function() {
});
})

describe('journals', function() {
describe.skip('journals', function() {
this.timeout(10000);

var sampleJournalId = "";
Expand Down Expand Up @@ -1291,7 +1283,7 @@ describe('regression tests', function() {
});
});

describe('users', function() {
describe.skip('users', function() {
this.timeout(20000);

it('retrieves a list of users', function(done) {
Expand Down

0 comments on commit 8a310f2

Please sign in to comment.