diff --git a/lib/application.js b/lib/application.js
index bc6677df..be1c5353 100644
--- a/lib/application.js
+++ b/lib/application.js
@@ -43,8 +43,6 @@ function Application(options) {
logger.debug('Application::constructor');
this.options = _.merge(_.clone(Application.defaults), options);
- console.log(this.options);
-
this.init();
var core = new Core(this);
diff --git a/lib/entities/contact.js b/lib/entities/contact.js
index 1290025b..5b2ac444 100644
--- a/lib/entities/contact.js
+++ b/lib/entities/contact.js
@@ -140,7 +140,8 @@ var Contact = Entity.extend(ContactSchema, {
getAttachmentContent: function(fileName, options) {
return this.application.core.attachments.getContent('Contacts/' + this.ContactID, fileName, options);
},
- save: function(options) {
+ save: function() {
+ var self = this;
var xml = '' + this.toXml() + '';
var path, method;
if (this.ContactID) {
@@ -150,7 +151,8 @@ var Contact = Entity.extend(ContactSchema, {
path = 'Contacts';
method = 'put'
}
- return this.application.putOrPostEntity(method, path, xml)
+
+ return this.application.putOrPostEntity(method, path, xml, { entityPath: 'Contacts.Contact', entityConstructor: function(data) { return self.application.core.contacts.newContact(data) } })
}
});
diff --git a/lib/entities/payroll_employee.js b/lib/entities/payroll_employee.js
index 5493fe31..8200216d 100644
--- a/lib/entities/payroll_employee.js
+++ b/lib/entities/payroll_employee.js
@@ -1,96 +1,96 @@
-var _ = require('lodash')
- , Entity = require('./entity')
- , logger = require('../logger')
- , ExternalLinkSchema = require('./shared').ExternalLinkSchema
+var _ = require('lodash'),
+ Entity = require('./entity'),
+ logger = require('../logger'),
+ ExternalLinkSchema = require('./shared').ExternalLinkSchema
var AddressSchema = new Entity.SchemaObject({
- StreetAddress: { type: String},
- SuiteOrAptOrUnit: { type: String},
- City: { type: String},
- State: { type: String},
- Zip: { type: String},
- Lattitude: { type: String},
- Longitude: { type: String}
+ StreetAddress: { type: String },
+ SuiteOrAptOrUnit: { type: String },
+ City: { type: String },
+ State: { type: String },
+ Zip: { type: String },
+ Lattitude: { type: String },
+ Longitude: { type: String }
});
var SalaryAndWageSchema = new Entity.SchemaObject({
- SalaryAndWageId: { type: String},
- EarningsTypeId: { type: String},
- SalaryWagesType: { type: String},
- HourlyRate: { type: Number},
- AnnualSalary: { type: Number},
- StandardHoursPerWeek: { type: Number}
+ SalaryAndWageId: { type: String },
+ EarningsTypeId: { type: String },
+ SalaryWagesType: { type: String },
+ HourlyRate: { type: Number },
+ AnnualSalary: { type: Number },
+ StandardHoursPerWeek: { type: Number }
});
var WorkLocationSchema = new Entity.SchemaObject({
- WorkLocationID: { type: String},
- IsPrimary: { type: Boolean}
+ WorkLocationID: { type: String },
+ IsPrimary: { type: Boolean }
});
var BankAccountSchema = new Entity.SchemaObject({
- AccountHolderName: { type: String},
- StatementText: {type: String},
- AccountType: {type: String},
- RoutingNumber: {type: String},
- AccountNumber: {type: String},
- Amount: {type: Number},
- Remainder: {type: Boolean}
+ AccountHolderName: { type: String },
+ StatementText: { type: String },
+ AccountType: { type: String },
+ RoutingNumber: { type: String },
+ AccountNumber: { type: String },
+ Amount: { type: Number },
+ Remainder: { type: Boolean }
});
var EarningsLineSchema = new Entity.SchemaObject({
- EarningsTypeID: { type: String},
- UnitsOrHours: {type: Number},
- RatePerUnit: {type: Number},
- Amount: {type: Number}
+ EarningsTypeID: { type: String },
+ UnitsOrHours: { type: Number },
+ RatePerUnit: { type: Number },
+ Amount: { type: Number }
});
var DeductionLineSchema = new Entity.SchemaObject({
- DeductionTypeID: { type: String},
- CalculationType: {type: String},
- EmployeeMax: {type: Number},
- Percentage: {type: Number},
- Amount: {type: Number}
+ DeductionTypeID: { type: String },
+ CalculationType: { type: String },
+ EmployeeMax: { type: Number },
+ Percentage: { type: Number },
+ Amount: { type: Number }
});
var ReimbursementLineSchema = new Entity.SchemaObject({
- ReimbursementTypeID: { type: String},
- Description: {type: String},
- Amount: {type: Number}
+ ReimbursementTypeID: { type: String },
+ Description: { type: String },
+ Amount: { type: Number }
});
var BenefitLineSchema = new Entity.SchemaObject({
- BenefitTypeID: { type: String},
- CalculationType: {type: String},
- Amount: {type: Number}
+ BenefitTypeID: { type: String },
+ CalculationType: { type: String },
+ Amount: { type: Number }
});
var PayTemplateSchema = Entity.SchemaObject({
- EarningsLines: { type: Array, arrayType: EarningsLineSchema, toObject: 'always'},
- DeductionLines: { type: Array, arrayType: DeductionLineSchema, toObject: 'always'},
- ReimbursementLines: { type: Array, arrayType: ReimbursementLineSchema, toObject: 'always'},
- BenefitLines: { type: Array, arrayType: BenefitLineSchema, toObject: 'always'}
+ EarningsLines: { type: Array, arrayType: EarningsLineSchema, toObject: 'always' },
+ DeductionLines: { type: Array, arrayType: DeductionLineSchema, toObject: 'always' },
+ ReimbursementLines: { type: Array, arrayType: ReimbursementLineSchema, toObject: 'always' },
+ BenefitLines: { type: Array, arrayType: BenefitLineSchema, toObject: 'always' }
});
var PaymentMethodSchema = new Entity.SchemaObject({
- PaymentMethodType: { type: String},
- BankAccounts: {type: Array, arrayType: BankAccountSchema, toObject: 'always'}
+ PaymentMethodType: { type: String },
+ BankAccounts: { type: Array, arrayType: BankAccountSchema, toObject: 'always' }
});
var OpeningBalanceEarningsLineSchema = Entity.SchemaObject({
- EarningsTypeID: { type: String},
- Amount: { type: Number}
+ EarningsTypeID: { type: String },
+ Amount: { type: Number }
});
var OpeningBalanceBenefitLineSchema = Entity.SchemaObject({
- BenefitLineID: { type: String},
- Amount: { type: Number}
+ BenefitLineID: { type: String },
+ Amount: { type: Number }
});
var OpeningBalanceDeductionLineSchema = Entity.SchemaObject({
- DeductionTypeID: { type: String},
- Amount: { type: Number}
+ DeductionTypeID: { type: String },
+ Amount: { type: Number }
});
var OpeningBalanceReimbursementLineSchema = Entity.SchemaObject({
- ReimbursementTypeID: { type: String},
- Amount: { type: Number}
+ ReimbursementTypeID: { type: String },
+ Amount: { type: Number }
});
var OpeningBalancesSchema = Entity.SchemaObject({
@@ -103,64 +103,56 @@ var OpeningBalancesSchema = Entity.SchemaObject({
var EmployeeSchema = new Entity.SchemaObject({
EmployeeID: { type: String },
Status: { type: String },
- UpdatedDateUTC: { type: Date},
+ UpdatedDateUTC: { type: Date },
FirstName: { type: String },
LastName: { type: String },
DateOfBirth: { type: String },
- HomeAddress: { type: AddressSchema},
- MiddleNames: { type: String},
- JobTitle: { type: String},
- Email: { type: String},
- Gender: { type: String},
- MailingAddress: { type: AddressSchema},
- Phone: { type: String},
- EmployeeNumber: { type: String},
- SocialSecurityNumber: { type: String},
- StartDate: { type: String},
- PayScheduleID: { type: String},
- EmployeeGroupName: { type: String},
- EmploymentBasis: { type: String},
- HolidayGroupID: { type: String},
- IsAuthorisedToApproveTimeOff: { type: Boolean},
- IsAuthorisedToApproveTimesheets: { type: Boolean},
+ HomeAddress: { type: AddressSchema },
+ MiddleNames: { type: String },
+ JobTitle: { type: String },
+ Email: { type: String },
+ Gender: { type: String },
+ MailingAddress: { type: AddressSchema },
+ Phone: { type: String },
+ EmployeeNumber: { type: String },
+ SocialSecurityNumber: { type: String },
+ StartDate: { type: String },
+ PayScheduleID: { type: String },
+ EmployeeGroupName: { type: String },
+ EmploymentBasis: { type: String },
+ HolidayGroupID: { type: String },
+ IsAuthorisedToApproveTimeOff: { type: Boolean },
+ IsAuthorisedToApproveTimesheets: { type: Boolean },
SalaryAndWages: { type: Array, arrayType: SalaryAndWageSchema, toObject: 'always' },
WorkLocations: { type: Array, arrayType: WorkLocationSchema, toObject: 'always' },
- PaymentMethod: { type: PaymentMethodSchema, toObject: 'always'},
+ PaymentMethod: { type: PaymentMethodSchema, toObject: 'always' },
PayTemplate: { type: PayTemplateSchema, toObject: 'always' },
OpeningBalances: { type: Array, arrayType: OpeningBalancesSchema, toObject: 'always' }
});
var Employee = Entity.extend(EmployeeSchema, {
- constructor: function (application, data, options)
- {
+ constructor: function(application, data, options) {
logger.debug('Employee::constructor');
- this.Entity.call(this, application,data,options);
+ this.Entity.call(this, application, data, options);
},
- initialize: function (data, options)
- {
- },
- changes: function (options)
- {
+ initialize: function(data, options) {},
+ changes: function(options) {
return this._super(options);
},
- _toObject: function (options)
- {
+ _toObject: function(options) {
return this._super(options);
},
- fromXmlObj: function (obj)
- {
- console.log(obj);
+ fromXmlObj: function(obj) {
var self = this;
- _.extend(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations','PaymentMethod', 'PayTemplate','OpeningBalances'));
+ _.extend(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations', 'PaymentMethod', 'PayTemplate', 'OpeningBalances'));
if (obj.SalaryAndWages)
this.extractArray(obj.SalaryAndWages.SalaryAndWage, this.SalaryAndWages);
if (obj.WorkLocations)
this.extractArray(obj.WorkLocations.WorkLocation, this.WorkLocations);
- if (obj.PaymentMethod)
- {
- _.extend(this.PaymentMethod, _.pick(obj.PaymentMethod,'PaymentMethodType'));
+ if (obj.PaymentMethod) {
+ _.extend(this.PaymentMethod, _.pick(obj.PaymentMethod, 'PaymentMethodType'));
if (obj.PaymentMethod.BankAccounts)
this.extractArray(obj.PaymentMethod.BankAccounts, this.PaymentMethod.BankAccounts);
}
@@ -184,33 +176,28 @@ var Employee = Entity.extend(EmployeeSchema, {
if (obj.OpeningBalances.ReimbursementLines)
this.extractArray(obj.OpeningBalances.ReimbursementLines.ReimbursementLine, this.OpeningBalances.ReimbursementLines);
}
-
+
return this;
},
- toXml: function ()
- {
+ toXml: function() {
// TO-DO
var employee = _.omit(this.toObject());
return this.application.js2xml(employee, 'Employee');
},
- save:function(options)
- {
+ save: function(options) {
var xml = '' + this.toXml() + '';
var path, method;
- if (this.EmployeeId)
- {
+ if (this.EmployeeId) {
path = 'Employees/' + this.EmployeeID;
method = 'post'
- }
- else
- {
+ } else {
path = 'Employees';
method = 'put'
}
- return this.application.putOrPostEntity(method, path, xml, { api: 'payroll'});
+ return this.application.putOrPostEntity(method, path, xml, { api: 'payroll' });
}
});
module.exports = Employee;
-module.exports.EmployeeSchema = EmployeeSchema;
+module.exports.EmployeeSchema = EmployeeSchema;
\ No newline at end of file
diff --git a/lib/entity_helpers/contacts.js b/lib/entity_helpers/contacts.js
index 12069803..40c6fb2e 100644
--- a/lib/entity_helpers/contacts.js
+++ b/lib/entity_helpers/contacts.js
@@ -1,39 +1,36 @@
-var _ = require('lodash')
- , logger = require('../logger')
- , EntityHelper = require('./entity_helper')
- , Contact = require('../entities/contact')
- , p = require('../misc/promise')
- , util = require('util')
+var _ = require('lodash'),
+ logger = require('../logger'),
+ EntityHelper = require('./entity_helper'),
+ Contact = require('../entities/contact'),
+ p = require('../misc/promise'),
+ util = require('util')
var Contacts = EntityHelper.extend({
- constructor: function (application, options)
- {
- EntityHelper.call(this, application, _.extend({ entityName:'Contact', entityPlural:'Contacts'}, options));
+ constructor: function(application, options) {
+ EntityHelper.call(this, application, _.extend({ entityName: 'Contact', entityPlural: 'Contacts' }, options));
},
- newContact: function (data, options)
- {
+ newContact: function(data, options) {
return new Contact(this.application, data, options)
},
- getContact: function (id, modifiedAfter)
- {
- return this.getContacts({ id: id, modifiedAfter: modifiedAfter})
- .then(function (contacts)
- {
+ getContact: function(id, modifiedAfter) {
+ return this.getContacts({ id: id, modifiedAfter: modifiedAfter })
+ .then(function(contacts) {
return _.first(contacts);
})
},
- saveContacts: function (contacts, options)
- {
- return this.saveEntities(contacts, options)
+ saveContacts: function(contacts, options) {
+ return this.saveEntities(contacts, this.setupOptions(options));
},
- getContacts: function (options)
- {
+ getContacts: function(options) {
+ return this.getEntities(this.setupOptions(options));
+ },
+ setupOptions: function(options) {
var self = this;
var clonedOptions = _.clone(options || {});
- clonedOptions.entityConstructor = function(data) { return self.newContact(data)};
- return this.getEntities(clonedOptions)
+ clonedOptions.entityPath = 'Contacts.Contact';
+ clonedOptions.entityConstructor = function(data) { return self.newContact(data) };
+ return clonedOptions;
}
})
-module.exports = Contacts;
-
+module.exports = Contacts;
\ No newline at end of file
diff --git a/test/accountingtests.js b/test/accountingtests.js
index 727f3391..a272ccdc 100644
--- a/test/accountingtests.js
+++ b/test/accountingtests.js
@@ -259,7 +259,7 @@ describe('regression tests', function() {
})
})
- describe('accounts', function() {
+ describe.skip('accounts', function() {
//Accounts supporting data
var accountClasses = ["ASSET", "EQUITY", "EXPENSE", "LIABILITY", "REVENUE"];
@@ -867,8 +867,34 @@ describe('regression tests', function() {
});
});
- describe.skip('contacts', function() {
- var sampleContactID;
+ describe('contacts', function() {
+ var sampleContact = {
+ Name: 'Johnnies Coffee' + Math.random(),
+ FirstName: 'John',
+ LastName: 'Smith'
+ };
+
+ it('create single contact', function(done) {
+ this.timeout(10000);
+ var contact = currentApp.core.contacts.newContact(sampleContact);
+ contact.save()
+ .then(function(response) {
+ expect(response.entities).to.have.length.greaterThan(0);
+ expect(response.entities[0].ContactID).to.not.equal("");
+ expect(response.entities[0].ContactID).to.not.equal(undefined);
+ expect(response.entities[0].Name).to.equal(sampleContact.Name);
+ expect(response.entities[0].FirstName).to.equal(sampleContact.FirstName);
+ expect(response.entities[0].LastName).to.equal(sampleContact.LastName);
+
+ sampleContact = response.entities[0];
+
+ done();
+ })
+ .fail(function(err) {
+ console.log(err)
+ done(wrapError(err));
+ })
+ })
it('get (no paging)', function(done) {
this.timeout(10000);
@@ -876,11 +902,12 @@ describe('regression tests', function() {
.then(function(contacts) {
_.each(contacts, function(contact) {
expect(contact.ContactID).to.not.equal("");
- sampleContactID = contact.ContactID;
+ expect(contact.ContactID).to.not.equal(undefined);
});
done();
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
@@ -888,17 +915,22 @@ describe('regression tests', function() {
this.timeout(10000);
currentApp.core.contacts.getContacts({ pager: { start: 1, callback: onContacts } })
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
function onContacts(err, response, cb) {
cb();
try {
- // response.data.length.should.equal(7,'Unexpected number of contacts returned');
+ _.each(response.data, function(contact) {
+ expect(contact.ContactID).to.not.equal("");
+ expect(contact.ContactID).to.not.equal(undefined);
+ });
+
if (response.finished)
done();
} catch (ex) {
-
+ console.log(util.inspect(err, null, null));
done(ex);
return;
}
@@ -908,12 +940,13 @@ describe('regression tests', function() {
it('get by id', function(done) {
this.timeout(10000);
- currentApp.core.contacts.getContact(sampleContactID)
+ currentApp.core.contacts.getContact(sampleContact.ContactID)
.then(function(contact) {
- expect(contact.ContactID).to.equal(sampleContactID);
+ expect(contact.ContactID).to.equal(sampleContact.ContactID);
done();
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
@@ -924,49 +957,44 @@ describe('regression tests', function() {
.then(function(contacts) {
_.each(contacts, function(contact) {
expect(contact.UpdatedDateUTC).to.not.equal("");
+ expect(contact.UpdatedDateUTC).to.not.equal(undefined);
})
done();
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
- it('create single contact', function(done) {
- this.timeout(10000);
- var contact = currentApp.core.contacts.newContact({ Name: 'xemware' + Math.random(), FirstName: 'Tim', LastName: 'Shnaider' });
- contact.save()
- .then(function(ret) {
- done();
- })
- .fail(function(err) {
- console.log(err)
- done(wrapError(err));
- })
- })
+
it('create multiple contacts', function(done) {
this.timeout(10000);
var contacts = [];
- contacts.push(currentApp.core.contacts.newContact({ Name: 'xemware' + Math.random(), FirstName: 'Tim' + Math.random(), LastName: 'Shnaider' }));
- contacts.push(currentApp.core.contacts.newContact({ Name: 'xemware' + Math.random(), FirstName: 'Tim' + Math.random(), LastName: 'Shnaider' }));
+ contacts.push(currentApp.core.contacts.newContact({ Name: 'Johnnies Coffee' + Math.random(), FirstName: 'John' + Math.random(), LastName: 'Smith' }));
+ contacts.push(currentApp.core.contacts.newContact({ Name: 'Johnnies Coffee' + Math.random(), FirstName: 'John' + Math.random(), LastName: 'Smith' }));
currentApp.core.contacts.saveContacts(contacts)
- .then(function(ret) {
+ .then(function(response) {
+ expect(response.entities).to.have.length.greaterThan(0);
+ _.each(response.entities, function(contact) {
+ expect(contact.ContactID).to.not.equal("");
+ expect(contact.ContactID).to.not.equal(undefined);
+ });
done();
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
- //these two functions need a 'contact' to be defined.
-
it('update contact', function(done) {
this.timeout(10000);
- currentApp.core.contacts.getContact(sampleContactID)
+ currentApp.core.contacts.getContact(sampleContact.ContactID)
.then(function(contact) {
- expect(contact.ContactID).to.equal(sampleContactID);
+ expect(contact.ContactID).to.equal(sampleContact.ContactID);
var newName = "Updated" + Math.random();
@@ -996,31 +1024,33 @@ describe('regression tests', function() {
done();
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
.fail(function(err) {
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
it('get attachments for contacts', function(done) {
this.timeout(100000);
- currentApp.core.contacts.getContact(sampleContactID)
+ currentApp.core.contacts.getContact(sampleContact.ContactID)
.then(function(contact) {
- expect(contact.ContactID).to.equal(sampleContactID);
+ expect(contact.ContactID).to.equal(sampleContact.ContactID);
contact.getAttachments()
.then(function(attachments) {
console.log(attachments);
done();
})
.fail(function(err) {
- console.log(err);
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
})
})
.fail(function(err) {
- console.log(err);
+ console.log(util.inspect(err, null, null));
done(wrapError(err));
});
});