UNPKG

openapi-node

Version:

A Node library to interact with the Wix Hive (RESTful API)

963 lines (887 loc) 79.7 kB
/** * Created by Karen_Cohen on 8/25/14. */ var should = require('should'); var assert = require('assert'); var expect = require('expect.js'); var config = require("./config.js"); var APP_SECRET = config.appSecret; var APP_KEY = config.appKey; var INSTANCE_ID = config.instanceId; describe('Contact', function() { this.timeout(10000); var wixLib = require( '../lib/WixClient.js' ); var api = wixLib.getAPI(APP_SECRET,APP_KEY, INSTANCE_ID); describe('Properties', function() { describe('Name', function() { it('should ignore an attempt to be set null', function(done) { var contact = api.Contacts.newContact(); contact.name({first: 'Karen', last: 'Meep'}); contact.name(null); contact.name().first().should.be.eql('Karen'); contact.name().last().should.be.eql('Meep'); done(); }); it('should allow setters', function(done) { var contact = api.Contacts.newContact(); contact.name({first: 'Karen', last: 'Meep'}); contact.name().prefix('Sir'); contact.name().first('Mix'); contact.name().middle('A'); contact.name().last('Lot'); contact.name().suffix('The III'); contact.name().prefix().should.be.eql('Sir'); contact.name().first().should.be.eql('Mix'); contact.name().middle().should.be.eql('A'); contact.name().last().should.be.eql('Lot'); contact.name().suffix().should.be.eql('The III'); done(); }); }); describe('Emails', function() { it('should allow edit', function(done) { var contact = api.Contacts.newContact(); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); contact.addEmail({tag: 'work', email: 'karen@home.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); var emails = contact.emails(); emails[1].tag('home'); contact.emails()[1].tag().should.be.eql('home'); done(); }); it('should throw exception with creating email without email property', function(done) { var contact = api.Contacts.newContact(); expect(contact.addEmail).withArgs({tag: 'wix', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}).to.throwException(); done(); }); it('should throw exception with creating email without tag property', function(done) { var contact = api.Contacts.newContact(); expect(contact.addEmail).withArgs({email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}).to.throwException(); done(); }); it('should throw exception with creating email without email status property', function(done) { var contact = api.Contacts.newContact(); expect(contact.addEmail).withArgs({email: 'karenc@wix.com', tag:'home'}).to.throwException(); done(); }); it('should ignore when setting tag property as null', function(done) { var contact = api.Contacts.newContact(); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); var email = contact.emails()[0]; email.tag(null); email.tag().should.be.eql('work'); done(); }); it('should ignore when setting email property as null', function(done) { var contact = api.Contacts.newContact(); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); var email = contact.emails()[0]; email.email(null); email.email().should.be.eql('karenc@wix.com'); done(); }); }); }); describe('Methods', function() { describe('Update Contact', function() { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.name({first: 'Karen', last: 'Meep'}); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); expect(contact.update).to.throwException(); done(); }); it('should edit contact information', function (done) { throw 'pending HAPI-3'; var contact = api.Contacts.newContact(api); contact.name().prefix('Sir'); contact.name().first('Mix'); contact.name().middle('A'); contact.name().last('Lot'); contact.name().suffix('The III'); contact.company({role: 'MyRole', name: 'MyName'}); contact.picture('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); contact.addAddress( { tag: 'work', address: '500 Terry A Francois', city: 'San Francisco', neighborhood: 'Wixville', region: 'CA', country: 'USA', postalCode: '94158' }); contact.addDate({ tag: 'work', date: '1994-11-05T13:15:30Z'}); contact.addUrl({ tag: 'work', url: 'http://www.wix.com/'}); createAndGet(api,contact).then( function (contact) { contact.update().then( function(contact){ contact.name().prefix().should.be.eql('Sir'); contact.name().first().should.be.eql('Mix'); contact.name().middle().should.be.eql('A'); contact.name().last().should.be.eql('Lot'); contact.name().suffix().should.be.eql('The III'); contact.picture().should.be.eql('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); contact.company().role().should.be.eql('MyRole'); contact.company().name().should.be.eql('MyName'); var email = contact.emails()[0]; email.id().should.be.a.Number; email.id().should.not.be.eql(undefined); email.email().should.be.eql('karenc@wix.com'); email.emailStatus().should.be.eql(api.Contacts.EMAIL_STATUS_TYPES.RECURRING); email.tag().should.be.eql('work'); var address = contact.addresses()[0]; address.id().should.be.a.Number; address.id().should.not.be.eql(undefined); address.tag().should.be.eql('work'); address.address().should.be.eql('500 Terry A Francois'); address.neighborhood().should.be.eql('Wixville'); address.city().should.be.eql('San Francisco'); address.region().should.be.eql('CA'); address.country().should.be.eql('USA'); address.postalCode().should.be.eql('94158'); var phone = contact.phones()[0]; phone.id().should.be.a.Number; phone.id().should.not.be.eql(undefined); phone.tag().should.be.eql('work'); phone.phone().should.be.eql('+1-415-639-5555'); var url = contact.urls()[0]; url.id().should.be.a.Number; url.id().should.not.be.eql(undefined); url.tag().should.be.eql('work'); url.url().should.be.eql('http://www.wix.com/'); var date = contact.dates()[0]; date.id().should.be.a.Number; date.id().should.not.be.eql(undefined); date.tag().should.be.eql('work'); var dExpected = new Date('1994-11-05T13:15:30Z').toString(); var dActual = new Date(date.date().toString()).toString(); dExpected.should.be.eql(dActual); done(); }, function(error){ done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should ignore delete of information', function (done) { throw 'pending HAPI-3'; var contact = api.Contacts.newContact(api); contact.name().prefix('Sir'); contact.name().first('Mix'); contact.name().middle('A'); contact.name().last('Lot'); contact.name().suffix('The III'); contact.company({role: 'MyRole', name: 'MyName'}); contact.picture('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); contact.addAddress( { tag: 'work', address: '500 Terry A Francois', city: 'San Francisco', neighborhood: 'Wixville', region: 'CA', country: 'USA', postalCode: '94158' }); contact.addDate({ tag: 'work', date: '1994-11-05T13:15:30Z'}); contact.addUrl({ tag: 'work', url: 'http://www.wix.com/'}); createAndGet(api,contact).then( function (contact) { delete contact.phones()[0]; delete contact.emails()[0]; delete contact.addresses()[0]; contact.update().then( function(contact){ contact.name().prefix().should.be.eql('Sir'); contact.name().first().should.be.eql('Mix'); contact.name().middle().should.be.eql('A'); contact.name().last().should.be.eql('Lot'); contact.name().suffix().should.be.eql('The III'); contact.picture().should.be.eql('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); contact.company().role().should.be.eql('MyRole'); contact.company().name().should.be.eql('MyName'); var email = contact.emails()[0]; email.id().should.be.a.Number; email.id().should.not.be.eql(undefined); email.email().should.be.eql('karenc@wix.com'); email.emailStatus().should.be.eql(api.Contacts.EMAIL_STATUS_TYPES.RECURRING); email.tag().should.be.eql('work'); var address = contact.addresses()[0]; address.id().should.be.a.Number; address.id().should.not.be.eql(undefined); address.tag().should.be.eql('work'); address.address().should.be.eql('500 Terry A Francois'); address.neighborhood().should.be.eql('Wixville'); address.city().should.be.eql('San Francisco'); address.region().should.be.eql('CA'); address.country().should.be.eql('USA'); address.postalCode().should.be.eql('94158'); var phone = contact.phones()[0]; phone.id().should.be.a.Number; phone.id().should.not.be.eql(undefined); phone.tag().should.be.eql('work'); phone.phone().should.be.eql('+1-415-639-5555'); var url = contact.urls()[0]; url.id().should.be.a.Number; url.id().should.not.be.eql(undefined); url.tag().should.be.eql('work'); url.url().should.be.eql('http://www.wix.com/'); var date = contact.dates()[0]; date.id().should.be.a.Number; date.id().should.not.be.eql(undefined); date.tag().should.be.eql('work'); var dExpected = new Date('1994-11-05T13:15:30Z').toString(); var dActual = new Date(date.date().toString()).toString(); dExpected.should.be.eql(dActual); done(); }, function(error){ done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('UpdateFields', function() { describe('updateName', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.name({first: 'Karen', last: 'Meep'}); expect(contact.updateName).to.throwException(); done(); }); it('should edit name', function (done) { var contact = api.Contacts.newContact(); contact.name({first: 'Karen', last: 'Meep'}); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.name().prefix('Sir'); contact.name().first('Mix'); contact.name().middle('A'); contact.name().last('Lot'); contact.name().suffix('The III'); contact.updateName().then( function (contact) { contact.name().prefix().should.be.eql('Sir'); contact.name().first().should.be.eql('Mix'); contact.name().middle().should.be.eql('A'); contact.name().last().should.be.eql('Lot'); contact.name().suffix().should.be.eql('The III'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updatePicture', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.picture('http://elcaminodeamanda.files.wordpress.com/2011/03/mc_hammer.png'); expect(contact.updatePicture).to.throwException(); done(); }); it('should edit picture', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.picture('http://elcaminodeamanda.files.wordpress.com/2011/03/mc_hammer.png'); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.picture('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); contact.updatePicture().then( function (contact) { contact.picture().should.be.eql('http://assets.objectiface.com/hashed_silo_content/silo_content/6506/resized/mchammer.jpg'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateCompany', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.company({role: 'MyRole', name: 'MyName'}); expect(contact.updateCompany).to.throwException(); done(); }); it('should edit company', function (done) { var contact = api.Contacts.newContact(); contact.company({role: 'MyRole', name: 'MyName'}); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.company({role: 'MyRole1', name: 'MyName1'}); contact.updateCompany().then( function (contact) { contact.company().role().should.be.eql('MyRole1'); contact.company().name().should.be.eql('MyName1'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateEmail', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); var email = contact.emails()[0]; expect(contact.updateEmail).withArgs(email).to.throwException(); done(); }); it('should throw error when not given an email', function (done) { var contact = api.Contacts.newContact(); expect(contact.updateEmail).to.throwException(); done(); }); it('should throw error when given an unsaved Email', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); expect(contact.updateEmail).withArgs(contact.emails()[0]).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit email for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addEmail({tag: 'work', email: 'karenc@wix.com', emailStatus: api.Contacts.EMAIL_STATUS_TYPES.RECURRING}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { var email = contact.emails()[0]; email.email('karen@home.com'); email.tag('home'); email.emailStatus(api.Contacts.EMAIL_STATUS_TYPES.OPT_OUT); contact.updateEmail(email).then( function (contact) { var email = contact.emails()[0]; email.email().should.be.eql('karen@home.com'); email.tag().should.be.eql('home'); email.emailStatus().should.be.eql(api.Contacts.EMAIL_STATUS_TYPES.OPT_OUT); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateAddress', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addAddress( { tag: 'work', address: '500 Terry A Francois', city: 'San Francisco', neighborhood: 'Wixville', region: 'CA', country: 'USA', postalCode: '94158' }); var address = contact.addresses()[0]; expect(contact.updateAddress).withArgs(address).to.throwException(); done(); }); it('should throw error when not given an address', function (done) { var contact = api.Contacts.newContact(); expect(contact.updateAddress).to.throwException(); done(); }); it('should throw error when given an unsaved Address', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addAddress( { tag: 'work', address: '500 Terry A Francois', city: 'San Francisco', neighborhood: 'Wixville', region: 'CA', country: 'USA', postalCode: '94158' }); var address = contact.addresses()[0]; expect(contact.updateAddress).withArgs(address).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit address for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addAddress( { tag: 'work', address: '500 Terry A Francois', city: 'San Francisco', neighborhood: 'Awesomeville', region: 'CA', country: 'USA', postalCode: '94158' }); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { var address = contact.addresses()[0]; address.id().should.be.a.Number; address.address('235 W 23rd St'); address.city('NYC'); address.neighborhood('Wixville'); address.region('NY'); address.postalCode('10011'); address.tag('Wix NYC Lounge'); contact.updateAddress(address).then( function (contact) { var address = contact.addresses()[0]; should.exist(address.id()); address.id().should.be.a.Number; should.exist(address.address()); address.address().should.be.eql('235 W 23rd St'); should.exist(address.city()); address.city().should.be.eql('NYC'); address.neighborhood().should.be.eql('Wixville'); address.region().should.be.eql('NY'); address.postalCode().should.be.eql('10011'); address.tag().should.be.eql('Wix NYC Lounge'); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updatePhone', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); var phone = contact.phones()[0]; expect(contact.updatePhone).withArgs(phone).to.throwException(); done(); }); it('should throw error when not given an phone', function (done) { var contact = api.Contacts.newContact(); expect(contact.updatePhone).to.throwException(); done(); }); it('should throw error when given an unsaved Phone', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); var phone = contact.phones()[0]; expect(contact.updatePhone).withArgs(phone).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit phone for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { var phone = contact.phones()[0]; phone.id().should.be.a.Number; phone.phone('+1 646-862-0833'); phone.tag('Wix NYC Lounge'); contact.updatePhone(phone).then( function (contact) { var phone = contact.phones()[0]; phone.id().should.be.a.Number; phone.phone().should.be.eql('+1 646-862-0833'); phone.tag().should.be.eql('Wix NYC Lounge'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateUrl', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addUrl({ tag: 'work', url: 'http://www.wix.com/'}); var url = contact.urls()[0]; expect(contact.updateUrl).withArgs(url).to.throwException(); done(); }); it('should throw error when not given an url', function (done) { var contact = api.Contacts.newContact(); expect(contact.updateUrl).to.throwException(); done(); }); it('should throw error when given an unsaved Url', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addUrl({ tag: 'work', url: 'http://www.wix.com/'}); var url = contact.urls()[0]; expect(contact.updateUrl).withArgs(url).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit url for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addUrl({ tag: 'work', url: 'http://www.wix.com/'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { var url = contact.urls()[0]; url.id().should.be.a.Number; url.url('http://www.wixlounge.com/'); url.tag('Wix NYC Lounge'); contact.updateUrl(url).then( function (contact) { var url = contact.urls()[0]; url.id().should.be.a.Number; url.url().should.be.eql('http://www.wixlounge.com/'); url.tag().should.be.eql('Wix NYC Lounge'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateDate', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addDate({ tag: 'work', date: '1994-11-05T13:15:30Z'}); var date = contact.dates()[0]; expect(contact.updateDate).withArgs(date).to.throwException(); done(); }); it('should throw error when not given an date', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); expect(contact.updateDate).to.throwException(); done(); }); it('should throw error when given an unsaved Date', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addDate({ tag: 'work', date: '1994-11-05T13:15:30Z'}); var date = contact.dates()[0]; expect(contact.updateDate).withArgs(date).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit date for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addDate({ tag: 'work', date: '1994-11-05T13:15:30Z'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { var date = contact.dates()[0]; date.id().should.be.a.Number; date.date('1995-11-05T13:15:30Z'); date.tag('A year later'); contact.updateDate(date).then( function (contact) { var date = contact.dates()[0]; date.id().should.be.a.Number; var dExpected = new Date('1995-11-05T13:15:30Z').toString(); var dActual = new Date(date.date().toString()).toString(); dExpected.should.be.eql(dActual); date.tag().should.be.eql('A year later'); done(); }, function (error) { done(error); } ); }, function (error) { done(error); } ); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateNote', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addNote({ content: 'I like big Wix and I cannot lie'}); var note = contact.notes()[0]; expect(contact.updateNote).withArgs(note).to.throwException(); done(); }); it('should throw error when not given an note', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); expect(contact.updateNote).to.throwException(); done(); }); it('should throw error when given an unsaved Note', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addNote({ content: 'I like big Wix and I cannot lie'}); var note = contact.notes()[0]; expect(contact.updateNote).withArgs(note).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit note for Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addNote({ content: 'I like big Wix and I cannot lie'}); var note = contact.notes()[0]; contact.postNote(note).then( function(contact){ var note = contact.notes()[0]; note.content('I like big butts and I cannot lie'); contact.updateNote(note).then( function (contact) { var note = contact.notes()[0]; note.id().should.be.a.Number; note.content().should.be.eql('I like big butts and I cannot lie'); done(); }, function (error) { done(error); } ).done(null, done); }, function(error){ done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); }); describe('updateCustomField', function () { it('should throw error when given an unsaved Contact', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); contact.addCustomField({ field: 'Host', value: 'Wayne Campbell'}); var customField = contact.customFields()[0]; expect(contact.updateCustomField).withArgs(customField).to.throwException(); done(); }); it('should throw error when not given an customField', function (done) { var contact = api.Contacts.newContact(); expect(contact.updateCustomField).to.throwException(); done(); }); it('should throw error when given an unsaved customField', function (done) { var contact = api.Contacts.newContact(); contact.addPhone({ tag: 'work', phone: '+1-415-639-5555'}); api.Contacts.create(contact).then( function (contactId) { api.Contacts.getContactById(contactId).then( function(contact) { contact.addCustomField({ field: 'Host', value: 'Wayne Campbell'}); var customField = contact.customFields()[0]; expect(contact.updateCustomField).withArgs(customField).to.throwException(); done(); }, function (error) { done(error); } ).done(null, done); }, function (error) { done(error); } ).done(null, done); }); it('should edit customField