From fa4ed825995e8fdbfb2e257a72f34696ce5d91fe Mon Sep 17 00:00:00 2001 From: Jordan Walsh Date: Wed, 15 Feb 2017 20:12:52 +1100 Subject: [PATCH] updated tests to check each field of an account --- lib/entities/account.js | 3 +- package.json | 4 +- test/tests.js | 131 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 131 insertions(+), 7 deletions(-) diff --git a/lib/entities/account.js b/lib/entities/account.js index 60b81ca0..165f5440 100644 --- a/lib/entities/account.js +++ b/lib/entities/account.js @@ -18,7 +18,8 @@ var AccountSchema = new Entity.SchemaObject({ BankAccountNumber: { type: String, toObject: 'never' }, CurrencyCode: { type: String, toObject: 'never' }, ReportingCode: { type: String, toObject: 'never' }, - ReportingCodeName: { type: String, toObject: 'never' } + ReportingCodeName: { type: String, toObject: 'never' }, + HasAttachments: { type: Boolean, toObject: 'always' } }); diff --git a/package.json b/package.json index ff156e46..344f4e81 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "mocha" + "test": "mocha --recursive" }, "keywords": [ "xero", @@ -24,7 +24,7 @@ }, "readmeFilename": "README.md", "devDependencies": { - "should": "*", + "chai": "^3.5.0", "mocha": "*", "swig": "^1.4.2", "express": "3.4.8", diff --git a/test/tests.js b/test/tests.js index b5618bdc..a74c39c5 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,4 +1,6 @@ -var should = require('should'), +var chai = require('chai'), + should = chai.should(), + expect = chai.expect, _ = require('lodash'), xero = require('..'), util = require('util') @@ -9,21 +11,51 @@ process.on('uncaughtException', function(err) { var currentApp; -describe('private application', function() { +/** + * Private Application Tests + * + * Accounting API Tests covered: + * - Accounts (GET, POST, PUT, DELETE) + * - Attachments (GET, POST, PUT) + * - BankTransactions (GET, POST, PUT) + * - BankTransfers (GET, PUT) + * - Contacts (GET, PUT, POST) + * - Invoices (GET, PUT, POST) + * - Items (GET, PUT, POST, DELETE) + * - Journals (GET) + * - Organisations (GET) + * - Tracking Categories (GET, PUT, POST, DELETE) + * - Users (GET) + * + * Payroll Tests Covered + * - Pay Items (GET, POST) + * - Payroll Employees (GET, POST) + * - Timesheets (GET, POST) + */ + +var organisationCountry = ""; +describe('private application', function() { describe('create instance', function() { it('init instance and set options', function() { //This constructor looks in ~/.xero/config.json for settings currentApp = new xero.PrivateApplication(); }) - }) + }); describe('organisations', function() { it('get', function(done) { this.timeout(10000); currentApp.core.organisations.getOrganisation() .then(function(ret) { - (ret.toObject().Name).should.not.be.empty(); + + var orgVersions = ["AU", "NZ", "GLOBAL", "UK", "US"]; + expect(ret.Name).to.not.equal(""); + expect(ret.Version).to.not.equal(""); + expect(ret.Version).to.be.oneOf(orgVersions); + + organisationCountry = ret.Version; + done(); }) .fail(function(err) { @@ -32,6 +64,97 @@ describe('private application', function() { }) }) + + describe('accounts', function() { + it('GET', function(done) { + this.timeout(10000); + currentApp.core.accounts.getAccounts() + .then(function(accounts) { + + var accountClasses = ["ASSET", "EQUITY", "EXPENSE", "LIABILITY", "REVENUE"]; + var accountTypes = ["BANK", "CURRENT", "CURRLIAB", "DEPRECIATN", "DIRECTCOSTS", "EQUITY", "EXPENSE", "FIXED", "INVENTORY", "LIABILITY", "NONCURRENT", "OTHERINCOME", "OVERHEADS", "PREPAYMENT", "REVENUE", "SALES", "TERMLIAB", "PAYGLIABILITY", "SUPERANNUATIONEXPENSE", "SUPERANNUATIONLIABILITY", "WAGESEXPENSE", "WAGESPAYABLELIABILITY"]; + var accountStatusCodes = ["ACTIVE", "ARCHIVED"]; + var bankAccountTypes = ["BANK", "CREDITCARD", "PAYPAL"]; + + accounts.forEach(function(account) { + + //Fields required for POST / PUT + + expect(account.Code).to.be.a('string'); + expect(account.Code).to.have.length.below(11); + + expect(account.Name).to.not.equal(""); + expect(account.Name).to.be.a('string'); + + expect(account.Type).to.not.equal(""); + expect(account.Type).to.be.oneOf(accountTypes); + + if (account.Type === "BANK") { + expect(account.BankAccountType).to.be.a('string'); + expect(account.BankAccountType).to.be.oneOf(bankAccountTypes); + + expect(account.BankAccountNumber).to.be.a('string'); + expect(account.BankAccountNumber).to.not.equal(""); + + if (account.CurrencyCode) { + expect(account.CurrencyCode).to.be.a('string'); + expect(account.CurrencyCode).to.not.equal(""); + } + } + + expect(account.Status).to.be.a('string'); + expect(account.Status).to.be.oneOf(accountStatusCodes); + + //Description is an optional field, when not provided it should be undefined. + if (account.Description) { + expect(account.Description).to.be.a('string'); + expect(account.Description).to.have.length.below(4001); + } else { + expect(account.Description).to.be.undefined; + } + + expect(account.TaxType).to.be.a('string'); + expect(account.TaxType).to.not.equal(""); + + expect(account.EnablePaymentsToAccount).to.be.a('boolean'); + expect(account.EnablePaymentsToAccount).to.not.be.undefined; + + expect(account.ShowInExpenseClaims).to.be.a('boolean'); + expect(account.ShowInExpenseClaims).to.not.be.undefined; + + //Fields returned in the GET + expect(account.AccountID).to.not.equal(""); + expect(account.Class).to.be.oneOf(accountClasses); + + if (account.SystemAccount) { + expect(account.SystemAccount).to.not.equal(""); + expect(account.SystemAccount).to.be.a('string'); + } + + if (account.ReportingCode) { + expect(account.ReportingCode).to.not.equal(""); + expect(account.ReportingCode).to.be.a('string'); + } + + if (account.ReportingCodeName) { + expect(account.ReportingCodeName).to.not.equal(""); + expect(account.ReportingCodeName).to.be.a('string'); + } + + expect(account.HasAttachments).to.be.a('boolean'); + expect(account.HasAttachments).to.not.be.undefined; + + expect(account.UpdatedDateUTC).to.not.equal(""); + expect(account.UpdatedDateUTC).to.be.a('string'); + }); + done(); + }) + .fail(function(err) { + done(wrapError(err)); + }); + }); + }); + describe.skip('invoices', function() { var InvoiceID = "";