xero-node
Advanced tools
Comparing version 2.10.1 to 2.11.0
@@ -19,3 +19,3 @@ The following examples explain the Bank Transactions section of the SDK. The API documentation on Bank Transactions can be found [here](https://developer.xero.com/documentation/api/banktransactions). | ||
* `newBankTransaction(data[, options])` | ||
* `newBankTransactions(data)` | ||
* `saveBankTransactions(data)` | ||
* `getBankTransaction(id[, modifiedAfter])` | ||
@@ -101,3 +101,3 @@ * `getBankTransactions([options])` | ||
xeroClient.core.bankTransactions.newBankTransactions(bankTransactions) | ||
xeroClient.core.bankTransactions.saveBankTransactions(bankTransactions) | ||
.then(function(response) { | ||
@@ -180,2 +180,2 @@ //Bank Transactions have been created | ||
}) | ||
``` | ||
``` |
@@ -30,11 +30,9 @@ The following examples explain the Employees section of the SDK. The API documentation on Employees can be found [here](https://developer.xero.com/documentation/api/employees). | ||
var sampleEmployee = { | ||
var employee = xeroClient.core.employees.newEmployee({ | ||
Status: 'ACTIVE', | ||
FirstName: 'John', | ||
LastName: 'Smith' | ||
}; | ||
}); | ||
var employeeObj = xeroClient.core.employees.newEmployee(sampleEmployee); | ||
employeeObj.save() | ||
employee.save() | ||
.then(function(employees) { | ||
@@ -178,2 +176,2 @@ //Employee has been created | ||
}); | ||
``` | ||
``` |
@@ -33,3 +33,3 @@ ## Welcome to the Xero-Node Docs! | ||
* [Prepayments](./Prepayments.md) | ||
* [Purchase Orders] (./Purchase-Orders.md) | ||
* [Purchase Orders](./Purchase-Orders.md) | ||
* [Receipts](./Receipts.md) | ||
@@ -53,2 +53,2 @@ * [Repeating Invoices](./Repeating-Invoices.md) | ||
If you need further support, please raise an issue in Github. | ||
If you need further support, please raise an issue in Github. |
@@ -97,3 +97,3 @@ The following examples explain the Receipts section of the SDK. The API documentation on Receipts can be found [here](https://developer.xero.com/documentation/api/receipts). | ||
}, | ||
Reference: 'Services 1, | ||
Reference: 'Services 1', | ||
LineItems: [{ | ||
@@ -213,2 +213,2 @@ Description: 'Services', | ||
}); | ||
``` | ||
``` |
@@ -74,17 +74,2 @@ The following examples explain the Tax Rates section of the SDK. The API documentation on Tax Rates can be found [here](https://developer.xero.com/documentation/api/tax-rates). | ||
### Retrieving Tax Rate by ID | ||
This example shows how to retrieve an tax rate using the Xero supplied GUID. | ||
```javascript | ||
var myTaxRateID = '288762e4-67a9-442d-9956-9a14e9d8826e'; | ||
xeroClient.core.taxRates.getTaxRate(myTaxRateID) | ||
.then(function(taxrate) { | ||
//We've got the tax rate so do something useful | ||
console.log(taxrate.Name); | ||
}); | ||
``` | ||
### Retrieving Tax Rates with filters | ||
@@ -134,5 +119,5 @@ | ||
var someTaxRateID = '75520d2e-e19d-4f36-b19b-e3b9000b2daa'; | ||
var someTaxRateName = 'tax001'; | ||
xeroClient.core.taxRates.getTaxRate(someTaxRateID) | ||
xeroClient.core.taxRates.getTaxRate(someTaxRateName) | ||
.then(function(taxrate) { | ||
@@ -148,2 +133,2 @@ //We've got the tax rate so now let's change Name | ||
}); | ||
``` | ||
``` |
@@ -240,3 +240,3 @@ 'use strict'; | ||
var errObj = new Error('DELETE call failed with: ' + err.statusCode); | ||
errObj.data = data; | ||
errObj.data = err.data; | ||
reject(errObj); | ||
@@ -282,3 +282,3 @@ callback && callback(errObj); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = data; | ||
errObj.data = err.data; | ||
reject(errObj); | ||
@@ -311,2 +311,6 @@ callback && callback(errObj); | ||
if (options.unitdp) { | ||
params.unitdp = options.unitdp; | ||
} | ||
if (!_.isEmpty(params)) { | ||
@@ -384,3 +388,3 @@ url += '?' + querystring.stringify(params); | ||
var errObj = new Error('GET call failed with: ' + err.statusCode); | ||
errObj.data = data; | ||
errObj.data = err.data; | ||
reject(errObj); | ||
@@ -387,0 +391,0 @@ callback && callback(errObj); |
@@ -42,3 +42,3 @@ 'use strict'; | ||
_.each(HELPERS, function(entityHelper, id) { | ||
_.each(HELPERS, (entityHelper, id) => { | ||
const instance = new (require(`./entity_helpers/accounting/${entityHelper.file}`))( | ||
@@ -45,0 +45,0 @@ application |
@@ -41,2 +41,3 @@ var _ = require('lodash'), | ||
CreditNoteNumber: { type: String, toObject: 'hasValue' }, | ||
Reference: { type: String, toObject: 'hasValue' }, | ||
CurrencyRate: { type: Number, toObject: 'hasValue' }, | ||
@@ -43,0 +44,0 @@ RemainingCredit: { type: Number, toObject: 'hasValue' }, |
@@ -69,8 +69,8 @@ 'use strict'; | ||
}, | ||
save: function() { | ||
save: function(opts) { | ||
const self = this; | ||
let path; | ||
let method; | ||
if (this.JournalID) { | ||
path = `ManualJournals/${this.JournalID}`; | ||
if (this.ManualJournalID) { | ||
path = `ManualJournals/${this.ManualJournalID}`; | ||
method = 'post'; | ||
@@ -82,2 +82,8 @@ } else { | ||
const options = opts || {}; | ||
options.entityPath = 'ManualJournals'; | ||
options.entityConstructor = function(data) { | ||
return self.application.core.manualjournals.newManualJournal(data); | ||
}; | ||
return this.application.putOrPostEntity( | ||
@@ -87,7 +93,3 @@ method, | ||
JSON.stringify(self), | ||
{ | ||
entityPath: 'ManualJournals', | ||
entityConstructor: data => | ||
self.application.core.manualjournals.newManualJournal(data), | ||
} | ||
options | ||
); | ||
@@ -94,0 +96,0 @@ }, |
@@ -23,3 +23,4 @@ var _ = require('lodash'), | ||
//Hacked to string as the framework doesn't recursively translate nested objects | ||
IsCompound: { type: String, toObject: 'hasValue' } | ||
IsCompound: { type: String, toObject: 'hasValue' }, | ||
IsNonRecoverable: { type: String, toObject: 'hasValue' } | ||
}); | ||
@@ -26,0 +27,0 @@ |
@@ -10,11 +10,15 @@ 'use strict'; | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Accounts' }, options)); | ||
EntityHelper.call( | ||
this, | ||
application, | ||
Object.assign({ entityPlural: 'Accounts' }, options) | ||
); | ||
}, | ||
newAccount: function(data, options) { | ||
return new Account(this.application, data, options) | ||
return new Account(this.application, data, options); | ||
}, | ||
getAccount: function(id, modifiedAfter) { | ||
return this.getAccounts({ id, modifiedAfter }).then(function(accounts) { | ||
return _.first(accounts); | ||
}) | ||
return this.getAccounts({ id, modifiedAfter }).then(accounts => | ||
_.first(accounts) | ||
); | ||
}, | ||
@@ -31,9 +35,11 @@ deleteAccount: function(id) { | ||
getAccounts: function(options) { | ||
let self = this; | ||
let clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newAccount(data) }; | ||
return this.getEntities(clonedOptions) | ||
} | ||
const self = this; | ||
const clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { | ||
return self.newAccount(data); | ||
}; | ||
return this.getEntities(clonedOptions); | ||
}, | ||
}); | ||
module.exports = Accounts; |
@@ -16,4 +16,4 @@ var _ = require('lodash'), | ||
}, | ||
getInvoice: function(id, modifiedAfter, where, order) { | ||
return this.getInvoices({ id: id, modifiedAfter: modifiedAfter, where: where, order: order }) | ||
getInvoice: function(id, modifiedAfter, where, order, unitdp) { | ||
return this.getInvoices({ id: id, modifiedAfter: modifiedAfter, where: where, order: order, unitdp: unitdp }) | ||
.then(function(invoices) { | ||
@@ -20,0 +20,0 @@ return _.first(invoices); |
@@ -8,3 +8,3 @@ var _ = require('lodash'), | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Employee', entityPlural: 'Employees' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Employees' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ newEmployee: function(data, options) { |
@@ -8,3 +8,3 @@ var _ = require('lodash'), | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, Object.assign({ entityName: 'Timesheet', entityPlural: 'Timesheets' }, options)); | ||
EntityHelper.call(this, application, Object.assign({ entityPlural: 'Timesheets' }, options)); | ||
}, | ||
@@ -11,0 +11,0 @@ newTimesheet: function(data, options) { |
{ | ||
"name": "xero-node", | ||
"version": "2.10.1", | ||
"version": "2.11.0", | ||
"description": "Xero API Wrapper for all application types", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -211,3 +211,3 @@ xero-node (alpha) | ||
yarn test | ||
`yarn test` | ||
@@ -231,2 +231,13 @@ ## Roadmap | ||
* 2.13.0 | ||
- Merged Fixed Payroll Timesheet Entity Helper #148 | ||
- Merged Fixed bug in Payroll Employee Entity #147 | ||
- Merged Fix error references #145 | ||
- Merged Reference field added to creditnote schema #143 | ||
- Merged Added unitdp to GetInvoice #142 | ||
* 2.12.0 | ||
- Merged #139 - Options on Manual Journals and using ManualJournalID | ||
* 2.11.0 | ||
- Merged #149 - Add IsNonRecoverable property to TaxComponent | ||
- Merged #128 - First pass fixes for eslint errors | ||
* 2.10.1 | ||
@@ -233,0 +244,0 @@ - Merged [PR#109](https://github.com/XeroAPI/xero-node/pull/109) - Fix undefined data on checkExpiry failure |
@@ -139,6 +139,14 @@ 'use strict'; | ||
expect(contact.ContactID).to.equal(sampleContact.ContactID); | ||
expect(contact.SalesTrackingCategories[0].TrackingCategoryName).to.be.a('String'); | ||
expect(contact.SalesTrackingCategories[0].TrackingOptionName).to.be.a('String'); | ||
expect(contact.PurchasesTrackingCategories[0].TrackingCategoryName).to.be.a('String'); | ||
expect(contact.PurchasesTrackingCategories[0].TrackingOptionName).to.be.a('String'); | ||
expect(contact.SalesTrackingCategories[0].TrackingCategoryName).to.be.a( | ||
'String' | ||
); | ||
expect(contact.SalesTrackingCategories[0].TrackingOptionName).to.be.a( | ||
'String' | ||
); | ||
expect( | ||
contact.PurchasesTrackingCategories[0].TrackingCategoryName | ||
).to.be.a('String'); | ||
expect( | ||
contact.PurchasesTrackingCategories[0].TrackingOptionName | ||
).to.be.a('String'); | ||
done(); | ||
@@ -145,0 +153,0 @@ }) |
@@ -148,2 +148,6 @@ 'use strict'; | ||
} | ||
if (creditNote.Reference) { | ||
expect(creditNote.Reference).to.be.a('String'); | ||
} | ||
}); | ||
@@ -309,2 +313,6 @@ done(); | ||
} | ||
if (creditNote.Reference) { | ||
expect(creditNote.Reference).to.be.a('String'); | ||
} | ||
done(); | ||
@@ -368,2 +376,4 @@ }) | ||
expect(thisNote.Reference).to.equal(creditNoteData.Reference); | ||
done(); | ||
@@ -370,0 +380,0 @@ }) |
@@ -165,3 +165,4 @@ 'use strict'; | ||
expect(linkedTransactions.entities.length).to.be.greaterThan(0); | ||
linkedTransactionID = linkedTransactions.entities[0].LinkedTransactionID; | ||
linkedTransactionID = | ||
linkedTransactions.entities[0].LinkedTransactionID; | ||
done(); | ||
@@ -168,0 +169,0 @@ }) |
@@ -39,2 +39,3 @@ 'use strict'; | ||
expect(taxComponent.IsCompound).to.be.a('Boolean'); | ||
expect(taxComponent.IsNonRecoverable).to.be.a('Boolean'); | ||
}); | ||
@@ -103,2 +104,3 @@ }); | ||
); | ||
expect(taxComponent.IsNonRecoverable).to.equal(false); | ||
}); | ||
@@ -105,0 +107,0 @@ done(); |
@@ -1,189 +0,192 @@ | ||
const common = require("../common/common"), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid | ||
const common = require('../common/common'), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid; | ||
let currentApp = common.currentApp | ||
const currentApp = common.currentApp; | ||
describe('deduction types', function() { | ||
describe('deduction types', () => { | ||
let expenseAccountID = '', | ||
expenseAccountCode = '', | ||
deductionTypeID = ''; | ||
let expenseAccountID = '', | ||
expenseAccountCode = '', | ||
deductionTypeID = '' | ||
before('create an expense account for testing', () => { | ||
const randomString = uuid.v4(); | ||
before('create an expense account for testing', function() { | ||
const randomString = uuid.v4() | ||
const testAccountData = { | ||
Code: randomString.replace(/-/g, '').substring(0, 10), | ||
Name: `Test expense from Node SDK ${randomString}`, | ||
Type: 'EXPENSE', | ||
Status: 'ACTIVE', | ||
}; | ||
var testAccountData = { | ||
Code: randomString.replace(/-/g, '').substring(0, 10), | ||
Name: 'Test expense from Node SDK ' + randomString, | ||
Type: 'EXPENSE', | ||
Status: 'ACTIVE' | ||
} | ||
const account = currentApp.core.accounts.newAccount(testAccountData); | ||
var account = currentApp.core.accounts.newAccount(testAccountData) | ||
return account.save().then(response => { | ||
expenseAccountID = response.entities[0].AccountID; | ||
expenseAccountCode = response.entities[0].Code; | ||
}); | ||
}); | ||
return account.save() | ||
.then(function(response) { | ||
expenseAccountID = response.entities[0].AccountID | ||
expenseAccountCode = response.entities[0].Code | ||
}) | ||
}) | ||
after('archive the account for testing', () => { | ||
currentApp.core.accounts.getAccount(expenseAccountID).then(account => { | ||
account.Status = 'ARCHIVED'; | ||
return account.save(); | ||
}); | ||
}); | ||
after('archive the account for testing', function() { | ||
currentApp.core.accounts.getAccount(expenseAccountID) | ||
.then(function(account) { | ||
account.Status = 'ARCHIVED' | ||
return account.save() | ||
}) | ||
}) | ||
it('get deduction types', done => { | ||
currentApp.payroll.payitems | ||
.getDeductionTypes() | ||
.then(deductionTypes => { | ||
expect(deductionTypes.length).to.be.at.least(1); | ||
it('get deduction types', function(done) { | ||
currentApp.payroll.payitems.getDeductionTypes() | ||
.then(function(deductionTypes) { | ||
expect(deductionTypes.length).to.be.at.least(1) | ||
deductionTypes.forEach(deductionType => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined); | ||
expect(deductionType.DeductionTypeID).to.not.equal(''); | ||
deductionTypes.forEach((deductionType) => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined) | ||
expect(deductionType.DeductionTypeID).to.not.equal('') | ||
expect(deductionType.Name).to.not.equal(undefined); | ||
expect(deductionType.Name).to.not.equal(''); | ||
expect(deductionType.Name).to.not.equal(undefined) | ||
expect(deductionType.Name).to.not.equal('') | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined); | ||
expect(deductionType.DeductionCategory).to.not.equal(''); | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined) | ||
expect(deductionType.DeductionCategory).to.not.equal('') | ||
expect(deductionType.AccountCode).to.not.equal(undefined); | ||
expect(deductionType.AccountCode).to.not.equal(''); | ||
expect(deductionType.AccountCode).to.not.equal(undefined) | ||
expect(deductionType.AccountCode).to.not.equal('') | ||
expect(deductionType.ReducesTax).to.be.a('Boolean'); | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean'); | ||
}); | ||
expect(deductionType.ReducesTax).to.be.a('Boolean') | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean') | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}) | ||
it('creates a new deduction type', done => { | ||
const sampleDeductionType = { | ||
Name: 'Super Duper Deduction', | ||
AccountCode: expenseAccountCode, | ||
ReducesTax: false, | ||
ReducesSuper: false, | ||
}; | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
const deductionType = currentApp.payroll.payitems.newDeductionType( | ||
sampleDeductionType | ||
); | ||
it('creates a new deduction type', function(done) { | ||
let sampleDeductionType = { | ||
Name: 'Super Duper Deduction', | ||
AccountCode: expenseAccountCode, | ||
ReducesTax: false, | ||
ReducesSuper: false | ||
} | ||
deductionType | ||
.save() | ||
.then(deductionTypes => { | ||
expect(deductionTypes.entities.length).to.be.at.least(1); | ||
let deductionType = currentApp.payroll.payitems.newDeductionType(sampleDeductionType); | ||
deductionTypes.entities.forEach(deductionType => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined); | ||
expect(deductionType.DeductionTypeID).to.not.equal(''); | ||
deductionType.save() | ||
.then(function(deductionTypes) { | ||
expect(deductionTypes.entities.length).to.be.at.least(1) | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined); | ||
expect(deductionType.DeductionCategory).to.not.equal(''); | ||
deductionTypes.entities.forEach((deductionType) => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined) | ||
expect(deductionType.DeductionTypeID).to.not.equal('') | ||
deductionTypeID = deductionType.DeductionTypeID; | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined) | ||
expect(deductionType.DeductionCategory).to.not.equal('') | ||
expect(deductionType.Name).to.not.equal(undefined); | ||
expect(deductionType.Name).to.not.equal(''); | ||
deductionTypeID = deductionType.DeductionTypeID | ||
expect(deductionType.AccountCode).to.not.equal(undefined); | ||
expect(deductionType.AccountCode).to.not.equal(''); | ||
expect(deductionType.Name).to.not.equal(undefined) | ||
expect(deductionType.Name).to.not.equal('') | ||
expect(deductionType.ReducesTax).to.be.a('Boolean'); | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean'); | ||
}); | ||
expect(deductionType.AccountCode).to.not.equal(undefined) | ||
expect(deductionType.AccountCode).to.not.equal('') | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
expect(deductionType.ReducesTax).to.be.a('Boolean') | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean') | ||
}) | ||
it('gets a single deduction type', done => { | ||
currentApp.payroll.payitems | ||
.getDeductionType(deductionTypeID) | ||
.then(deductionType => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined); | ||
expect(deductionType.DeductionTypeID).to.not.equal(''); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
expect(deductionType.Name).to.not.equal(undefined); | ||
expect(deductionType.Name).to.not.equal(''); | ||
it('gets a single deduction type', function(done) { | ||
currentApp.payroll.payitems.getDeductionType(deductionTypeID) | ||
.then(function(deductionType) { | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined); | ||
expect(deductionType.DeductionCategory).to.not.equal(''); | ||
expect(deductionType.DeductionTypeID).to.not.equal(undefined) | ||
expect(deductionType.DeductionTypeID).to.not.equal('') | ||
expect(deductionType.AccountCode).to.not.equal(undefined); | ||
expect(deductionType.AccountCode).to.not.equal(''); | ||
expect(deductionType.Name).to.not.equal(undefined) | ||
expect(deductionType.Name).to.not.equal('') | ||
expect(deductionType.ReducesTax).to.be.a('Boolean'); | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean'); | ||
expect(deductionType.DeductionCategory).to.not.equal(undefined) | ||
expect(deductionType.DeductionCategory).to.not.equal('') | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
expect(deductionType.AccountCode).to.not.equal(undefined) | ||
expect(deductionType.AccountCode).to.not.equal('') | ||
it('updates a deduction type', done => { | ||
currentApp.payroll.payitems | ||
.getDeductionType(deductionTypeID) | ||
.then(deductionType => { | ||
// earningsRate.EarningsRateID should contain some value | ||
const updatedID = deductionType.DeductionTypeID; | ||
const updatedName = 'UPDATED!!!'; | ||
expect(deductionType.ReducesTax).to.be.a('Boolean') | ||
expect(deductionType.ReducesSuper).to.be.a('Boolean') | ||
deductionType.Name = updatedName; | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
// We use the new method for both new and updated objects | ||
const updatedDeductionType = currentApp.payroll.payitems.newDeductionType( | ||
deductionType | ||
); | ||
it('updates a deduction type', function(done) { | ||
currentApp.payroll.payitems.getDeductionType(deductionTypeID) | ||
.then(function(deductionType) { | ||
updatedDeductionType | ||
.save() | ||
.then(deductionTypes => { | ||
expect(deductionTypes.entities.length).to.be.at.least(1); | ||
//earningsRate.EarningsRateID should contain some value | ||
var updatedID = deductionType.DeductionTypeID | ||
var updatedName = "UPDATED!!!" | ||
deductionTypes.entities.forEach(deductionType => { | ||
if (deductionType.DeductionTypeID === updatedID) { | ||
expect(deductionType.Name).to.equal(updatedName); | ||
} | ||
}); | ||
deductionType.Name = updatedName | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
//We use the new method for both new and updated objects | ||
let updatedDeductionType = currentApp.payroll.payitems.newDeductionType(deductionType); | ||
it('deletes a deduction type', done => { | ||
currentApp.payroll.payitems | ||
.deleteDeductionType(deductionTypeID) | ||
.then(deductionTypes => { | ||
expect(deductionTypes.entities.length).to.be.at.least(1); | ||
updatedDeductionType.save() | ||
.then(function(deductionTypes) { | ||
expect(deductionTypes.entities.length).to.be.at.least(1) | ||
deductionTypes.entities.forEach(deductionType => { | ||
expect(deductionType.DeductionTypeID).to.not.equal(deductionTypeID); | ||
}); | ||
deductionTypes.entities.forEach(function(deductionType) { | ||
if (deductionType.DeductionTypeID === updatedID) { | ||
expect(deductionType.Name).to.equal(updatedName) | ||
} | ||
}) | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('deletes a deduction type', function(done) { | ||
currentApp.payroll.payitems.deleteDeductionType(deductionTypeID) | ||
.then(function(deductionTypes) { | ||
expect(deductionTypes.entities.length).to.be.at.least(1) | ||
deductionTypes.entities.forEach(function(deductionType) { | ||
expect(deductionType.DeductionTypeID).to.not.equal(deductionTypeID) | ||
}) | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
}) | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); |
@@ -1,251 +0,293 @@ | ||
const common = require("../common/common"), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid | ||
const common = require('../common/common'), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid; | ||
let currentApp = common.currentApp | ||
const currentApp = common.currentApp; | ||
describe('earningsrates', function() { | ||
describe('earningsrates', () => { | ||
let expenseAccountID = '', | ||
expenseAccountCode = '', | ||
earningsRateID = ''; | ||
let expenseAccountID = '', | ||
expenseAccountCode = '', | ||
earningsRateID = '' | ||
before('create an expense account for testing', () => { | ||
const randomString = uuid.v4(); | ||
before('create an expense account for testing', function() { | ||
const randomString = uuid.v4() | ||
const testAccountData = { | ||
Code: randomString.replace(/-/g, '').substring(0, 10), | ||
Name: `Test expense from Node SDK ${randomString}`, | ||
Type: 'EXPENSE', | ||
Status: 'ACTIVE', | ||
}; | ||
var testAccountData = { | ||
Code: randomString.replace(/-/g, '').substring(0, 10), | ||
Name: 'Test expense from Node SDK ' + randomString, | ||
Type: 'EXPENSE', | ||
Status: 'ACTIVE' | ||
} | ||
const account = currentApp.core.accounts.newAccount(testAccountData); | ||
var account = currentApp.core.accounts.newAccount(testAccountData) | ||
return account.save().then(response => { | ||
expenseAccountID = response.entities[0].AccountID; | ||
expenseAccountCode = response.entities[0].Code; | ||
}); | ||
}); | ||
return account.save() | ||
.then(function(response) { | ||
expenseAccountID = response.entities[0].AccountID | ||
expenseAccountCode = response.entities[0].Code | ||
}) | ||
}) | ||
after('archive the account for testing', () => { | ||
currentApp.core.accounts.getAccount(expenseAccountID).then(account => { | ||
account.Status = 'ARCHIVED'; | ||
return account.save(); | ||
}); | ||
}); | ||
after('archive the account for testing', function() { | ||
currentApp.core.accounts.getAccount(expenseAccountID) | ||
.then(function(account) { | ||
account.Status = 'ARCHIVED' | ||
return account.save() | ||
}) | ||
}) | ||
it('get earnings rates', done => { | ||
currentApp.payroll.payitems | ||
.getEarningsRates() | ||
.then(earningsRates => { | ||
expect(earningsRates.length).to.be.at.least(1); | ||
it('get earnings rates', function(done) { | ||
currentApp.payroll.payitems.getEarningsRates() | ||
.then(function(earningsRates) { | ||
expect(earningsRates.length).to.be.at.least(1) | ||
earningsRates.forEach(earningsRate => { | ||
expect(earningsRate.EarningsRateID).to.not.equal(undefined); | ||
expect(earningsRate.EarningsRateID).to.not.equal(''); | ||
earningsRates.forEach((earningsRate) => { | ||
expect(earningsRate.EarningsRateID).to.not.equal(undefined) | ||
expect(earningsRate.EarningsRateID).to.not.equal('') | ||
expect(earningsRate.Name).to.not.equal(undefined); | ||
expect(earningsRate.Name).to.not.equal(''); | ||
expect(earningsRate.Name).to.not.equal(undefined) | ||
expect(earningsRate.Name).to.not.equal('') | ||
expect(earningsRate.AccountCode).to.not.equal(undefined); | ||
expect(earningsRate.AccountCode).to.not.equal(''); | ||
expect(earningsRate.AccountCode).to.not.equal(undefined) | ||
expect(earningsRate.AccountCode).to.not.equal('') | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean'); | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean'); | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean') | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean') | ||
const earningsTypes = [ | ||
'FIXED', | ||
'ORDINARYTIMEEARNINGS', | ||
'OVERTIMEEARNINGS', | ||
'ALLOWANCE', | ||
'LUMPSUMD', | ||
]; | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes); | ||
const earningsTypes = ['FIXED', 'ORDINARYTIMEEARNINGS', 'OVERTIMEEARNINGS', 'ALLOWANCE', 'LUMPSUMD'] | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes) | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT']; | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes); | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT'] | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes) | ||
if ( | ||
earningsRate.RateType === rateTypes[2] && | ||
earningsRate.RatePerUnit | ||
) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String'); | ||
} | ||
if (earningsRate.RateType === rateTypes[2] && earningsRate.RatePerUnit) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String') | ||
} | ||
if ( | ||
earningsRate.RateType === rateTypes[1] && | ||
earningsRate.Multiplier | ||
) { | ||
expect(earningsRate.Multiplier).to.be.a('Number'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.Multiplier) { | ||
expect(earningsRate.Multiplier).to.be.a('Number') | ||
} | ||
if ( | ||
earningsRate.RateType === rateTypes[1] && | ||
earningsRate.AccrueLeave | ||
) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.AccrueLeave) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean') | ||
} | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number'); | ||
} | ||
}); | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number') | ||
} | ||
}) | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('create new earnings rate', done => { | ||
const sampleEarningsRate = { | ||
Name: 'Super Duper Time', | ||
AccountCode: expenseAccountCode, | ||
EarningsType: 'ORDINARYTIMEEARNINGS', | ||
RateType: 'RATEPERUNIT', | ||
IsExemptFromTax: false, | ||
IsExemptFromSuper: false, | ||
TypeOfUnits: 'Hours', | ||
}; | ||
it('create new earnings rate', function(done) { | ||
let sampleEarningsRate = { | ||
Name: 'Super Duper Time', | ||
AccountCode: expenseAccountCode, | ||
EarningsType: 'ORDINARYTIMEEARNINGS', | ||
RateType: 'RATEPERUNIT', | ||
IsExemptFromTax: false, | ||
IsExemptFromSuper: false, | ||
TypeOfUnits: 'Hours' | ||
} | ||
const earningsRate = currentApp.payroll.payitems.newEarningsRate( | ||
sampleEarningsRate | ||
); | ||
let earningsRate = currentApp.payroll.payitems.newEarningsRate(sampleEarningsRate); | ||
earningsRate | ||
.save() | ||
.then(earningsRates => { | ||
expect(earningsRates.entities.length).to.be.at.least(1); | ||
earningsRate.save() | ||
.then(function(earningsRates) { | ||
expect(earningsRates.entities.length).to.be.at.least(1) | ||
earningsRates.entities.forEach(earningsRate => { | ||
expect(earningsRate.EarningsRateID).to.not.equal(undefined); | ||
expect(earningsRate.EarningsRateID).to.not.equal(''); | ||
earningsRates.entities.forEach((earningsRate) => { | ||
expect(earningsRate.EarningsRateID).to.not.equal(undefined) | ||
expect(earningsRate.EarningsRateID).to.not.equal('') | ||
earningsRateID = earningsRate.EarningsRateID; | ||
earningsRateID = earningsRate.EarningsRateID | ||
expect(earningsRate.Name).to.not.equal(undefined); | ||
expect(earningsRate.Name).to.not.equal(''); | ||
expect(earningsRate.Name).to.not.equal(undefined) | ||
expect(earningsRate.Name).to.not.equal('') | ||
expect(earningsRate.AccountCode).to.not.equal(undefined); | ||
expect(earningsRate.AccountCode).to.not.equal(''); | ||
expect(earningsRate.AccountCode).to.not.equal(undefined) | ||
expect(earningsRate.AccountCode).to.not.equal('') | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean'); | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean'); | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean') | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean') | ||
const earningsTypes = [ | ||
'FIXED', | ||
'ORDINARYTIMEEARNINGS', | ||
'OVERTIMEEARNINGS', | ||
'ALLOWANCE', | ||
'LUMPSUMD', | ||
]; | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes); | ||
const earningsTypes = ['FIXED', 'ORDINARYTIMEEARNINGS', 'OVERTIMEEARNINGS', 'ALLOWANCE', 'LUMPSUMD'] | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes) | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT']; | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes); | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT'] | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes) | ||
if ( | ||
earningsRate.RateType === rateTypes[2] && | ||
earningsRate.RatePerUnit | ||
) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String'); | ||
} | ||
if (earningsRate.RateType === rateTypes[2] && earningsRate.RatePerUnit) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String') | ||
} | ||
if ( | ||
earningsRate.RateType === rateTypes[1] && | ||
earningsRate.Multiplier | ||
) { | ||
expect(earningsRate.Multiplier).to.be.a('Number'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.Multiplier) { | ||
expect(earningsRate.Multiplier).to.be.a('Number') | ||
} | ||
if ( | ||
earningsRate.RateType === rateTypes[1] && | ||
earningsRate.AccrueLeave | ||
) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.AccrueLeave) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean') | ||
} | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number'); | ||
} | ||
}); | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number') | ||
} | ||
}) | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('get a single earnings rate', done => { | ||
currentApp.payroll.payitems | ||
.getEarningsRate(earningsRateID) | ||
.then(earningsRate => { | ||
expect(earningsRate.EarningsRateID).to.equal(earningsRateID); | ||
it('get a single earnings rate', function(done) { | ||
currentApp.payroll.payitems.getEarningsRate(earningsRateID) | ||
.then(function(earningsRate) { | ||
expect(earningsRate.Name).to.not.equal(undefined); | ||
expect(earningsRate.Name).to.not.equal(''); | ||
expect(earningsRate.EarningsRateID).to.equal(earningsRateID) | ||
expect(earningsRate.AccountCode).to.not.equal(undefined); | ||
expect(earningsRate.AccountCode).to.not.equal(''); | ||
expect(earningsRate.Name).to.not.equal(undefined) | ||
expect(earningsRate.Name).to.not.equal('') | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean'); | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean'); | ||
expect(earningsRate.AccountCode).to.not.equal(undefined) | ||
expect(earningsRate.AccountCode).to.not.equal('') | ||
const earningsTypes = [ | ||
'FIXED', | ||
'ORDINARYTIMEEARNINGS', | ||
'OVERTIMEEARNINGS', | ||
'ALLOWANCE', | ||
'LUMPSUMD', | ||
]; | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes); | ||
expect(earningsRate.IsExemptFromTax).to.be.a('Boolean') | ||
expect(earningsRate.IsExemptFromSuper).to.be.a('Boolean') | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT']; | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes); | ||
const earningsTypes = ['FIXED', 'ORDINARYTIMEEARNINGS', 'OVERTIMEEARNINGS', 'ALLOWANCE', 'LUMPSUMD'] | ||
expect(earningsRate.EarningsType).to.be.oneOf(earningsTypes) | ||
if ( | ||
earningsRate.RateType === rateTypes[2] && | ||
earningsRate.RatePerUnit | ||
) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String'); | ||
} | ||
const rateTypes = ['FIXEDAMOUNT', 'MULTIPLE', 'RATEPERUNIT'] | ||
expect(earningsRate.RateType).to.be.oneOf(rateTypes) | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.Multiplier) { | ||
expect(earningsRate.Multiplier).to.be.a('Number'); | ||
} | ||
if (earningsRate.RateType === rateTypes[2] && earningsRate.RatePerUnit) { | ||
expect(earningsRate.RatePerUnit).to.be.a('String') | ||
} | ||
if ( | ||
earningsRate.RateType === rateTypes[1] && | ||
earningsRate.AccrueLeave | ||
) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.Multiplier) { | ||
expect(earningsRate.Multiplier).to.be.a('Number') | ||
} | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number'); | ||
} | ||
if (earningsRate.RateType === rateTypes[1] && earningsRate.AccrueLeave) { | ||
expect(earningsRate.AccrueLeave).to.be.a('Boolean') | ||
} | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
if (earningsRate.RateType === rateTypes[0] && earningsRate.Amount) { | ||
expect(earningsRate.Amount).to.be.a('Number') | ||
} | ||
it('update an earnings rate', done => { | ||
currentApp.payroll.payitems | ||
.getEarningsRate(earningsRateID) | ||
.then(earningsRate => { | ||
// earningsRate.EarningsRateID should contain some value | ||
const updatedID = earningsRate.EarningsRateID; | ||
const updatedName = 'UPDATED!!!'; | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
earningsRate.Name = updatedName; | ||
it('update an earnings rate', function(done) { | ||
currentApp.payroll.payitems.getEarningsRate(earningsRateID) | ||
.then(function(earningsRate) { | ||
// We use the new method for both new and updated objects | ||
const updatedEarningsRate = currentApp.payroll.payitems.newEarningsRate( | ||
earningsRate | ||
); | ||
//earningsRate.EarningsRateID should contain some value | ||
var updatedID = earningsRate.EarningsRateID | ||
var updatedName = "UPDATED!!!" | ||
updatedEarningsRate | ||
.save() | ||
.then(earningsRates => { | ||
expect(earningsRates.entities.length).to.be.at.least(1); | ||
earningsRate.Name = updatedName | ||
earningsRates.entities.forEach(earningsRate => { | ||
if (earningsRate.EarningsRateID === updatedID) { | ||
expect(earningsRate.Name).to.equal(updatedName); | ||
} | ||
}); | ||
//We use the new method for both new and updated objects | ||
let updatedEarningsRate = currentApp.payroll.payitems.newEarningsRate(earningsRate); | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
updatedEarningsRate.save() | ||
.then(function(earningsRates) { | ||
expect(earningsRates.entities.length).to.be.at.least(1) | ||
it('deletes an earnings rate', done => { | ||
currentApp.payroll.payitems | ||
.deleteEarningsRate(earningsRateID) | ||
.then(earningsRates => { | ||
expect(earningsRates.entities.length).to.be.at.least(1); | ||
earningsRates.entities.forEach(function(earningsRate) { | ||
if (earningsRate.EarningsRateID === updatedID) { | ||
expect(earningsRate.Name).to.equal(updatedName) | ||
} | ||
}) | ||
earningsRates.entities.forEach(earningsRate => { | ||
expect(earningsRate.EarningsRateID).to.not.equal(earningsRateID); | ||
}); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('deletes an earnings rate', function(done) { | ||
currentApp.payroll.payitems.deleteEarningsRate(earningsRateID) | ||
.then(function(earningsRates) { | ||
expect(earningsRates.entities.length).to.be.at.least(1) | ||
earningsRates.entities.forEach(function(earningsRate) { | ||
expect(earningsRate.EarningsRateID).to.not.equal(earningsRateID) | ||
}) | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
}) | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); |
@@ -1,53 +0,52 @@ | ||
const common = require("../common/common"), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid, | ||
util = common.util | ||
const common = require('../common/common'), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid, | ||
util = common.util; | ||
let currentApp = common.currentApp | ||
const currentApp = common.currentApp; | ||
describe('employees', function() { | ||
it('get (no paging)', function(done) { | ||
currentApp.payroll.employees.getEmployees() | ||
.then(function(employees) { | ||
employees.forEach(function(employee) { | ||
expect(employee.EmployeeID).to.not.equal('') | ||
expect(employee.EmployeeID).to.not.equal(undefined) | ||
describe('employees', () => { | ||
it('get (no paging)', done => { | ||
currentApp.payroll.employees | ||
.getEmployees() | ||
.then(employees => { | ||
employees.forEach(employee => { | ||
expect(employee.EmployeeID).to.not.equal(''); | ||
expect(employee.EmployeeID).to.not.equal(undefined); | ||
expect(employee.FirstName).to.not.equal('') | ||
expect(employee.FirstName).to.not.equal(undefined) | ||
expect(employee.FirstName).to.not.equal(''); | ||
expect(employee.FirstName).to.not.equal(undefined); | ||
expect(employee.LastName).to.not.equal('') | ||
expect(employee.LastName).to.not.equal(undefined) | ||
expect(employee.LastName).to.not.equal(''); | ||
expect(employee.LastName).to.not.equal(undefined); | ||
console.log(employee.FirstName + " " + employee.LastName) | ||
console.log(`${employee.FirstName} ${employee.LastName}`); | ||
expect(employee.Status).to.not.equal('') | ||
expect(employee.Status).to.not.equal(undefined) | ||
expect(employee.Status).to.not.equal(''); | ||
expect(employee.Status).to.not.equal(undefined); | ||
expect(employee.Email).to.not.equal('') | ||
expect(employee.Email).to.not.equal(undefined) | ||
expect(employee.Email).to.not.equal(''); | ||
expect(employee.Email).to.not.equal(undefined); | ||
expect(employee.DateOfBirth).to.not.equal('') | ||
expect(employee.DateOfBirth).to.not.equal(undefined) | ||
expect(employee.DateOfBirth).to.not.equal(''); | ||
expect(employee.DateOfBirth).to.not.equal(undefined); | ||
console.log(employee) | ||
console.log(employee); | ||
if (employee.HomeAddress) { | ||
//console.log(employee.HomeAddress) | ||
expect(employee.HomeAddress.AddressLine1).to.not.equal('') | ||
expect(employee.HomeAddress.AddressLine1).to.not.equal(undefined) | ||
} | ||
}) | ||
done() | ||
}) | ||
.catch(function(err) { | ||
console.log(util.inspect(err, null, null)) | ||
done(wrapError(err)) | ||
}) | ||
}) | ||
}) | ||
if (employee.HomeAddress) { | ||
// console.log(employee.HomeAddress) | ||
expect(employee.HomeAddress.AddressLine1).to.not.equal(''); | ||
expect(employee.HomeAddress.AddressLine1).to.not.equal(undefined); | ||
} | ||
}); | ||
done(); | ||
}) | ||
.catch(err => { | ||
console.log(util.inspect(err, null, null)); | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); |
@@ -1,153 +0,156 @@ | ||
const common = require("../common/common"), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid | ||
const common = require('../common/common'), | ||
mocha = common.mocha, | ||
expect = common.expect, | ||
xero = common.xero, | ||
wrapError = common.wrapError, | ||
uuid = common.uuid; | ||
let currentApp = common.currentApp | ||
const currentApp = common.currentApp; | ||
describe('leave types', function() { | ||
describe('leave types', () => { | ||
let leaveTypeID = ''; | ||
let leaveTypeID = '' | ||
it('get leave types', done => { | ||
currentApp.payroll.payitems | ||
.getLeaveTypes() | ||
.then(leaveTypes => { | ||
expect(leaveTypes.length).to.be.at.least(1); | ||
it('get leave types', function(done) { | ||
currentApp.payroll.payitems.getLeaveTypes() | ||
.then(function(leaveTypes) { | ||
expect(leaveTypes.length).to.be.at.least(1) | ||
leaveTypes.forEach(leaveType => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined); | ||
expect(leaveType.LeaveTypeID).to.not.equal(''); | ||
leaveTypes.forEach((leaveType) => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined) | ||
expect(leaveType.LeaveTypeID).to.not.equal('') | ||
expect(leaveType.Name).to.not.equal(undefined); | ||
expect(leaveType.Name).to.not.equal(''); | ||
expect(leaveType.Name).to.not.equal(undefined) | ||
expect(leaveType.Name).to.not.equal('') | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined); | ||
expect(leaveType.TypeOfUnits).to.not.equal(''); | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined) | ||
expect(leaveType.TypeOfUnits).to.not.equal('') | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean'); | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean') | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean'); | ||
}); | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean') | ||
}) | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('creates a new leave type', done => { | ||
const sampleLeaveType = { | ||
Name: 'Super Duper Leave', | ||
TypeOfUnits: 'Hours', | ||
IsPaidLeave: true, | ||
ShowOnPayslip: true, | ||
}; | ||
it('creates a new leave type', function(done) { | ||
let sampleLeaveType = { | ||
Name: 'Super Duper Leave', | ||
TypeOfUnits: 'Hours', | ||
IsPaidLeave: true, | ||
ShowOnPayslip: true | ||
} | ||
const leaveType = currentApp.payroll.payitems.newLeaveType(sampleLeaveType); | ||
let leaveType = currentApp.payroll.payitems.newLeaveType(sampleLeaveType); | ||
leaveType | ||
.save() | ||
.then(leaveTypes => { | ||
expect(leaveTypes.entities.length).to.be.at.least(1); | ||
leaveType.save() | ||
.then(function(leaveTypes) { | ||
expect(leaveTypes.entities.length).to.be.at.least(1) | ||
leaveTypes.entities.forEach(leaveType => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined); | ||
expect(leaveType.LeaveTypeID).to.not.equal(''); | ||
leaveTypes.entities.forEach((leaveType) => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined) | ||
expect(leaveType.LeaveTypeID).to.not.equal('') | ||
expect(leaveType.Name).to.not.equal(undefined); | ||
expect(leaveType.Name).to.not.equal(''); | ||
expect(leaveType.Name).to.not.equal(undefined) | ||
expect(leaveType.Name).to.not.equal('') | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined); | ||
expect(leaveType.TypeOfUnits).to.not.equal(''); | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined) | ||
expect(leaveType.TypeOfUnits).to.not.equal('') | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean'); | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean') | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean'); | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean') | ||
leaveTypeID = leaveType.LeaveTypeID; | ||
}); | ||
leaveTypeID = leaveType.LeaveTypeID | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}) | ||
it('gets a single leave type', done => { | ||
currentApp.payroll.payitems | ||
.getLeaveType(leaveTypeID) | ||
.then(leaveType => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined); | ||
expect(leaveType.LeaveTypeID).to.not.equal(''); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
expect(leaveType.Name).to.not.equal(undefined); | ||
expect(leaveType.Name).to.not.equal(''); | ||
it('gets a single leave type', function(done) { | ||
currentApp.payroll.payitems.getLeaveType(leaveTypeID) | ||
.then(function(leaveType) { | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined); | ||
expect(leaveType.TypeOfUnits).to.not.equal(''); | ||
expect(leaveType.LeaveTypeID).to.not.equal(undefined) | ||
expect(leaveType.LeaveTypeID).to.not.equal('') | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean'); | ||
expect(leaveType.Name).to.not.equal(undefined) | ||
expect(leaveType.Name).to.not.equal('') | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean'); | ||
expect(leaveType.TypeOfUnits).to.not.equal(undefined) | ||
expect(leaveType.TypeOfUnits).to.not.equal('') | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
expect(leaveType.IsPaidLeave).to.be.a('Boolean') | ||
it('updates a leave type', done => { | ||
currentApp.payroll.payitems | ||
.getLeaveType(leaveTypeID) | ||
.then(leaveType => { | ||
// earningsRate.EarningsRateID should contain some value | ||
const updatedID = leaveType.LeaveTypeID; | ||
const updatedName = 'UPDATED!!!'; | ||
expect(leaveType.ShowOnPayslip).to.be.a('Boolean') | ||
leaveType.Name = updatedName; | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
// We use the new method for both new and updated objects | ||
const updatedLeaveType = currentApp.payroll.payitems.newLeaveType( | ||
leaveType | ||
); | ||
it('updates a leave type', function(done) { | ||
currentApp.payroll.payitems.getLeaveType(leaveTypeID) | ||
.then(function(leaveType) { | ||
updatedLeaveType | ||
.save() | ||
.then(leaveTypes => { | ||
expect(leaveTypes.entities.length).to.be.at.least(1); | ||
//earningsRate.EarningsRateID should contain some value | ||
var updatedID = leaveType.LeaveTypeID | ||
var updatedName = "UPDATED!!!" | ||
leaveTypes.entities.forEach(leaveType => { | ||
if (leaveType.LeaveTypeID === updatedID) { | ||
expect(leaveType.Name).to.equal(updatedName); | ||
} | ||
}); | ||
leaveType.Name = updatedName | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
//We use the new method for both new and updated objects | ||
let updatedLeaveType = currentApp.payroll.payitems.newLeaveType(leaveType); | ||
it('deletes a leave type', done => { | ||
currentApp.payroll.payitems | ||
.deleteLeaveType(leaveTypeID) | ||
.then(leaveTypes => { | ||
expect(leaveTypes.entities.length).to.be.at.least(1); | ||
updatedLeaveType.save() | ||
.then(function(leaveTypes) { | ||
expect(leaveTypes.entities.length).to.be.at.least(1) | ||
leaveTypes.entities.forEach(function(leaveType) { | ||
if (leaveType.LeaveTypeID === updatedID) { | ||
expect(leaveType.Name).to.equal(updatedName) | ||
} | ||
}) | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it('deletes a leave type', function(done) { | ||
currentApp.payroll.payitems.deleteLeaveType(leaveTypeID) | ||
.then(function(leaveTypes) { | ||
expect(leaveTypes.entities.length).to.be.at.least(1) | ||
leaveTypes.entities.forEach(function(leaveType) { | ||
expect(leaveType.LeaveTypeID).to.not.equal(leaveTypeID) | ||
}) | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
}) | ||
leaveTypes.entities.forEach(leaveType => { | ||
expect(leaveType.LeaveTypeID).to.not.equal(leaveTypeID); | ||
}); | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); |
@@ -1,60 +0,63 @@ | ||
describe.skip('timesheets', function() { | ||
it('create timesheet', function(done) { | ||
var timesheet = currentApp.payroll.timesheets.newTimesheet({ | ||
EmployeeID: '065a115c-ba9c-4c03-b8e3-44c551ed8f21', | ||
StartDate: new Date(2014, 8, 23), | ||
EndDate: new Date(2014, 8, 29), | ||
Status: 'Draft', | ||
TimesheetLines: [{ | ||
EarningsRateID: 'a9ab82bf-c421-4840-b245-1df307c2127a', | ||
NumberOfUnits: [5, 0, 0, 0, 0, 0, 0] | ||
}] | ||
}); | ||
timesheet.save() | ||
.then(function() { | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
describe.skip('timesheets', () => { | ||
it('create timesheet', done => { | ||
const timesheet = currentApp.payroll.timesheets.newTimesheet({ | ||
EmployeeID: '065a115c-ba9c-4c03-b8e3-44c551ed8f21', | ||
StartDate: new Date(2014, 8, 23), | ||
EndDate: new Date(2014, 8, 29), | ||
Status: 'Draft', | ||
TimesheetLines: [ | ||
{ | ||
EarningsRateID: 'a9ab82bf-c421-4840-b245-1df307c2127a', | ||
NumberOfUnits: [5, 0, 0, 0, 0, 0, 0], | ||
}, | ||
], | ||
}); | ||
timesheet | ||
.save() | ||
.then(() => { | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
it.skip('get timesheets', done => { | ||
currentApp.payroll.timesheets | ||
.getTimesheets() | ||
.then(timesheets => { | ||
if (!_.isEmpty(timesheets)) | ||
console.log(util.inspect(timesheets[0].toObject(), null, null)); | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); | ||
}) | ||
it.skip('get timesheets', function(done) { | ||
currentApp.payroll.timesheets.getTimesheets() | ||
.then(function(timesheets) { | ||
if (!_.isEmpty(timesheets)) | ||
console.log(util.inspect(timesheets[0].toObject(), null, null)); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
}) | ||
describe.skip('employees', function() { | ||
var employee; | ||
it('get (no paging)', function(done) { | ||
currentApp.payroll.employees.getEmployees() | ||
.then(function(ret) { | ||
console.log(ret[0].toObject()); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
it.skip('get by id', function(done) { | ||
currentApp.payroll.employees.getEmployee('065a115c-ba9c-4c03-b8e3-44c551ed8f21') | ||
.then(function(ret) { | ||
employee = ret; | ||
console.log(employee.toObject()); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(wrapError(err)); | ||
}) | ||
}) | ||
}) | ||
describe.skip('employees', () => { | ||
let employee; | ||
it('get (no paging)', done => { | ||
currentApp.payroll.employees | ||
.getEmployees() | ||
.then(ret => { | ||
console.log(ret[0].toObject()); | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
it.skip('get by id', done => { | ||
currentApp.payroll.employees | ||
.getEmployee('065a115c-ba9c-4c03-b8e3-44c551ed8f21') | ||
.then(ret => { | ||
employee = ret; | ||
console.log(employee.toObject()); | ||
done(); | ||
}) | ||
.catch(err => { | ||
done(wrapError(err)); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11863
482
736361
162