Skip to content

Commit

Permalink
Changes shared schema for addresses.
Browse files Browse the repository at this point in the history
Adds test for Contacts GET, CREATE and UPDATE which looks at the Addesses in a contact.

Tests DO NOT pass without the change to the schema
  • Loading branch information
philals committed Aug 28, 2017
1 parent 728cf9f commit de160df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/entities/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ var AddressDetailsSchema = Entity.SchemaObject({
AddressType: { type: String, toObject: 'always' }
})

module.exports.AddressSchema = Entity.SchemaObject({
Address: { type: AddressDetailsSchema, toObject: 'always' }
});
module.exports.AddressSchema = AddressDetailsSchema;

module.exports.PhoneSchema = Entity.SchemaObject({
PhoneNumber: { type: String, toObject: 'always' },
Expand Down
22 changes: 17 additions & 5 deletions test/core/contacts_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ describe('contacts', () => {
Name: `Johnnies Coffee ${Math.random()}`,
FirstName: 'John',
LastName: 'Smith',
Addresses: [{
AddressType: "POBOX",
AddressLine1: "P O Box 123",
City: "Wellington",
PostalCode: "6011",
AttentionTo: "Andrea"
}]
};

let contactIDsList = [];
Expand All @@ -34,6 +41,10 @@ describe('contacts', () => {
);
expect(response.entities[0].LastName).to.equal(sampleContact.LastName);

expect(response.entities[0].Addresses.filter((address) => {
return address.City == sampleContact.Addresses[0].City
}).length).to.equal(1);

sampleContact = response.entities[0];

done();
Expand Down Expand Up @@ -69,7 +80,7 @@ describe('contacts', () => {
expect(contact.ContactID).to.not.equal('');
expect(contact.ContactID).to.not.equal(undefined);

if(contactIDsList.length < 5) {
if (contactIDsList.length < 5) {
contactIDsList.push(contact.ContactID);
}
});
Expand Down Expand Up @@ -116,7 +127,7 @@ describe('contacts', () => {
done(wrapError(err));
});
});

it('get list of IDs', done => {
currentApp.core.contacts
.getContacts({
Expand All @@ -128,15 +139,15 @@ describe('contacts', () => {
contacts.forEach(contact => {
expect(contact.ContactID).to.be.oneOf(contactIDsList);
});

done();
})
.catch(err => {
console.error(util.inspect(err, null, null));
done(wrapError(err));
});
});

it('get - invalid modified date', done => {
currentApp.core.contacts
.getContacts({ modifiedAfter: 'cats' })
Expand All @@ -153,7 +164,7 @@ describe('contacts', () => {
it('create multiple contacts', done => {
const contacts = [];

for (let i = 0; i < 2; i += 1) {
for (let i = 0;i < 2;i += 1) {
contacts.push(
currentApp.core.contacts.newContact({
Name: `Johnnies Coffee ${Math.random()}`,
Expand Down Expand Up @@ -214,6 +225,7 @@ describe('contacts', () => {
})
.then(updatedContact => {
expect(updatedContact.entities[0].Name).to.equal(newName);
expect(updatedContact.entities[0].Addresses.filter((address) => {return address.City == "Melbourne"}).length).to.equal(1);
done();
})
.catch(err => {
Expand Down

0 comments on commit de160df

Please sign in to comment.