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