From 9863a2558369454b13c8027999e4502962e0e804 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 10:32:23 -0500 Subject: [PATCH 1/9] removed unneeded withCallback calls from sparkpost.js --- lib/sparkpost.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sparkpost.js b/lib/sparkpost.js index 9f85293..e370ac0 100644 --- a/lib/sparkpost.js +++ b/lib/sparkpost.js @@ -141,25 +141,25 @@ SparkPost.prototype.get = function(options, callback) { options.method = 'GET'; options.json = true; - return withCallback(this.request(options), callback); + return this.request(options, callback); }; SparkPost.prototype.post = function(options, callback) { options.method = 'POST'; - return withCallback(this.request(options), callback); + return this.request(options, callback); }; SparkPost.prototype.put = function(options, callback) { options.method = 'PUT'; - return withCallback(this.request(options), callback); + return this.request(options, callback); }; SparkPost.prototype.delete = function(options, callback) { options.method = 'DELETE'; - return withCallback(this.request(options), callback); + return this.request(options, callback); }; module.exports = SparkPost; From 2481f7807d4b87f2310d14f070909bb5ede1814a Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 11:21:01 -0500 Subject: [PATCH 2/9] removed calls to withCallback for api calls --- lib/inboundDomains.js | 8 ++++---- lib/messageEvents.js | 3 +-- lib/recipientLists.js | 10 +++++----- lib/relayWebhooks.js | 10 +++++----- lib/sendingDomains.js | 13 ++++++------- lib/subaccounts.js | 8 ++++---- lib/suppressionList.js | 8 ++++---- lib/templates.js | 12 ++++++------ lib/transmissions.js | 7 +++---- lib/webhooks.js | 18 +++++++++--------- 10 files changed, 47 insertions(+), 50 deletions(-) diff --git a/lib/inboundDomains.js b/lib/inboundDomains.js index 9549c0f..47c7620 100644 --- a/lib/inboundDomains.js +++ b/lib/inboundDomains.js @@ -15,7 +15,7 @@ module.exports = function(client) { const options = { uri: api }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Get an inbound domain by its domain name @@ -32,7 +32,7 @@ module.exports = function(client) { const options = { uri: `${api}/${domain}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new inbound domain @@ -50,7 +50,7 @@ module.exports = function(client) { uri: api , json: createOpts }; - return withCallback(client.post(options, callback), callback); + return client.post(options, callback); }, /** * Delete an existing inbound domain @@ -67,7 +67,7 @@ module.exports = function(client) { const options = { uri: `${api}/${domain}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); } }; }; diff --git a/lib/messageEvents.js b/lib/messageEvents.js index 98c1e90..6d468d0 100644 --- a/lib/messageEvents.js +++ b/lib/messageEvents.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'message-events'; /* @@ -29,7 +28,7 @@ module.exports = function(client) { options.qs[paramname] = parameters[paramname]; } }); - return withCallback(client.get(options), callback); + return client.get(options, callback); } }; }; diff --git a/lib/recipientLists.js b/lib/recipientLists.js index 5c5eeee..a1edec6 100644 --- a/lib/recipientLists.js +++ b/lib/recipientLists.js @@ -16,7 +16,7 @@ module.exports = function(client) { const reqOpts = { uri: api }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -46,7 +46,7 @@ module.exports = function(client) { qs: options }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, @@ -72,7 +72,7 @@ module.exports = function(client) { } }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** @@ -103,7 +103,7 @@ module.exports = function(client) { } }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** @@ -124,7 +124,7 @@ module.exports = function(client) { uri: `${api}/${id}` }; - return withCallback(client.delete(reqOpts), callback); + return client.delete(reqOpts, callback); } }; diff --git a/lib/relayWebhooks.js b/lib/relayWebhooks.js index a368763..5d835ca 100644 --- a/lib/relayWebhooks.js +++ b/lib/relayWebhooks.js @@ -15,7 +15,7 @@ module.exports = function(client) { const reqOpts = { uri: api }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** * Get details about a specified relay webhook by its id @@ -33,7 +33,7 @@ module.exports = function(client) { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new relay webhook @@ -52,7 +52,7 @@ module.exports = function(client) { , json: webhook }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update an existing relay webhook @@ -76,7 +76,7 @@ module.exports = function(client) { , json: webhook }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** * Delete an existing relay webhook @@ -94,7 +94,7 @@ module.exports = function(client) { uri: `${api}/${id}` }; - return withCallback(client.delete(options, callback), callback); + return client.delete(options, callback); } }; }; diff --git a/lib/sendingDomains.js b/lib/sendingDomains.js index 43698e9..9756402 100644 --- a/lib/sendingDomains.js +++ b/lib/sendingDomains.js @@ -4,7 +4,6 @@ const withCallback = require('./Promise'); const api = 'sending-domains'; module.exports = function(client) { - return { /** * Lists all sending domains @@ -17,7 +16,7 @@ module.exports = function(client) { uri: api }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -36,7 +35,7 @@ module.exports = function(client) { uri: `${api}/${domain}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -56,7 +55,7 @@ module.exports = function(client) { json: createOpts }; - return withCallback(client.post(options), callback); + return client.post(options, callback); }, /** @@ -81,7 +80,7 @@ module.exports = function(client) { json: updateOpts }; - return withCallback(client.put(options), callback); + return client.put(options, callback); }, /** @@ -100,7 +99,7 @@ module.exports = function(client) { uri: `${api}/${domain}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); }, /** @@ -125,7 +124,7 @@ module.exports = function(client) { json: options }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); } }; diff --git a/lib/subaccounts.js b/lib/subaccounts.js index ab004e8..2996034 100644 --- a/lib/subaccounts.js +++ b/lib/subaccounts.js @@ -15,7 +15,7 @@ module.exports = function(client) { const options = { uri: api }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Get details about a specified subaccount by its id @@ -32,7 +32,7 @@ module.exports = function(client) { const options = { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new subaccount @@ -50,7 +50,7 @@ module.exports = function(client) { uri: api, json: subaccount }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update existing subaccount by id @@ -74,7 +74,7 @@ module.exports = function(client) { json: subaccount }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); } }; diff --git a/lib/suppressionList.js b/lib/suppressionList.js index 2ea71bc..f06da11 100644 --- a/lib/suppressionList.js +++ b/lib/suppressionList.js @@ -19,7 +19,7 @@ module.exports = function(client) { uri: api , qs: parameters }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -37,7 +37,7 @@ module.exports = function(client) { const options = { uri: `${api}/${email}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -62,7 +62,7 @@ module.exports = function(client) { json: { recipients: listEntries } }; - return withCallback(client.put(options, callback), callback); + return client.put(options, callback); }, /** @@ -80,7 +80,7 @@ module.exports = function(client) { const options = { uri: `${api}/${email}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); } }; diff --git a/lib/templates.js b/lib/templates.js index a2d0f81..d53a784 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -17,7 +17,7 @@ module.exports = function(client) { const options = { uri: api }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Get details about a specified template by its id. @@ -44,7 +44,7 @@ module.exports = function(client) { , qs: options }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** * Create a new template. @@ -63,7 +63,7 @@ module.exports = function(client) { , json: template }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update an existing template. @@ -95,7 +95,7 @@ module.exports = function(client) { , qs: options }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** * Delete an existing template. @@ -112,7 +112,7 @@ module.exports = function(client) { const options = { uri: `${api}/${id}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); }, /** * Preview the most recent version of an existing template by id. @@ -146,7 +146,7 @@ module.exports = function(client) { delete reqOpts.json.draft; } - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); } }; }; diff --git a/lib/transmissions.js b/lib/transmissions.js index 74e1a85..1b084c2 100644 --- a/lib/transmissions.js +++ b/lib/transmissions.js @@ -10,7 +10,6 @@ const api = 'transmissions'; * info about a specific transmission */ module.exports = function(client) { - return { /** * List an overview of all transmissions in the account @@ -31,7 +30,7 @@ module.exports = function(client) { qs: options }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** * Retrieve the details about a transmission by its id @@ -49,7 +48,7 @@ module.exports = function(client) { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Sends a message by creating a new transmission @@ -78,7 +77,7 @@ module.exports = function(client) { qs: options }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); } }; diff --git a/lib/webhooks.js b/lib/webhooks.js index 47d8cbc..bc8a820 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -29,7 +29,7 @@ module.exports = function(client) { reqOpts.qs.timezone = options.timezone; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -60,7 +60,7 @@ module.exports = function(client) { reqOpts.qs.timezone = options.timezone; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -80,7 +80,7 @@ module.exports = function(client) { json: webhook }; - return withCallback(client.post(options), callback); + return client.post(options, callback); }, /** @@ -107,7 +107,7 @@ module.exports = function(client) { delete options.json.id; - return withCallback(client.put(options), callback); + return client.put(options, callback); }, /** @@ -126,7 +126,7 @@ module.exports = function(client) { uri: `${api}/${id}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); }, /** @@ -154,7 +154,7 @@ module.exports = function(client) { } }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** @@ -185,7 +185,7 @@ module.exports = function(client) { reqOpts.qs.limit = options.limit; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -198,7 +198,7 @@ module.exports = function(client) { const reqOpts = { uri: `${api}/events/documentation` }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -224,7 +224,7 @@ module.exports = function(client) { reqOpts.qs.events = options.events; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); } }; }; From 258678699605ec659c0e1e95885652fbc63f91fd Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 11:21:33 -0500 Subject: [PATCH 3/9] fixed tests --- test/spec/messageEvents.spec.js | 3 +-- test/spec/recipientLists.spec.js | 3 +++ test/spec/templates.spec.js | 7 ++++++- test/spec/transmissions.spec.js | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/spec/messageEvents.spec.js b/test/spec/messageEvents.spec.js index 5b9fdfc..eecf271 100644 --- a/test/spec/messageEvents.spec.js +++ b/test/spec/messageEvents.spec.js @@ -2,8 +2,7 @@ var chai = require('chai') , expect = chai.expect - , sinon = require('sinon') - , Promise = require('../../lib/Promise'); + , sinon = require('sinon'); require('sinon-as-promised'); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index e0bee3f..fc353b1 100644 --- a/test/spec/recipientLists.spec.js +++ b/test/spec/recipientLists.spec.js @@ -50,6 +50,9 @@ describe('Recipient Lists Library', function() { it('should not throw an error if optional 2nd argument is a function (callback)', function() { let cb = sinon.stub(); + + client.get.yields(); + return recipientLists.get('test-id', cb).then(() => { expect(cb.callCount).to.equal(1); }); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index 82cbb30..f89b308 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -1,5 +1,4 @@ 'use strict'; - var _ = require('lodash') , chai = require('chai') , expect = chai.expect @@ -115,6 +114,9 @@ describe('Templates Library', function() { , template = { name: 'A new name!' }; + + client.put.yields(); + return templates.update(id, template, cb).then(function() { expect(cb.callCount).to.equal(1); }); @@ -172,6 +174,9 @@ describe('Templates Library', function() { it('should not throw an error if optional 2nd argument is a function (callback)', function() { let cb = sinon.stub(); + + client.post.yields(); + return templates.preview('test', cb).then(function() { expect(cb.callCount).to.equal(1); }); diff --git a/test/spec/transmissions.spec.js b/test/spec/transmissions.spec.js index 71dd5f2..125c64c 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -103,6 +103,8 @@ describe('Transmissions Library', function() { }); it('should call client get method with the appropriate uri using callback', function(done) { + client.get.yields(); + transmissions.list(function() { expect(client.get.firstCall.args[0].uri).to.equal('transmissions'); done(); @@ -181,6 +183,9 @@ describe('Transmissions Library', function() { , transmission = { campaign_id: 'test-campaign' }; + + client.post.yields(); + return transmissions.send(transmission, cb).then(function() { expect(cb.callCount).to.equal(1); }); From 0db8a9e14d6b5df54e370bf0bb10453e8d40b4f3 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 11:45:22 -0500 Subject: [PATCH 4/9] created reject function for early returns --- lib/inboundDomains.js | 7 +++---- lib/recipientLists.js | 11 +++++------ lib/relayWebhooks.js | 11 +++++------ lib/sendingDomains.js | 15 +++++++-------- lib/sparkpost.js | 4 ++++ lib/subaccounts.js | 9 ++++----- lib/suppressionList.js | 7 +++---- lib/templates.js | 13 ++++++------- lib/transmissions.js | 5 ++--- lib/webhooks.js | 17 ++++++++--------- 10 files changed, 47 insertions(+), 52 deletions(-) diff --git a/lib/inboundDomains.js b/lib/inboundDomains.js index 47c7620..3f52303 100644 --- a/lib/inboundDomains.js +++ b/lib/inboundDomains.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'inbound-domains'; module.exports = function(client) { @@ -26,7 +25,7 @@ module.exports = function(client) { */ get: function(domain, callback) { if (!domain || typeof domain !== 'string') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } const options = { @@ -43,7 +42,7 @@ module.exports = function(client) { */ create: function(createOpts, callback) { if (!createOpts || typeof createOpts !== 'object') { - return withCallback(Promise.reject(new Error('create options are required')), callback); + return client.reject(new Error('create options are required'), callback); } const options = { @@ -61,7 +60,7 @@ module.exports = function(client) { */ delete: function(domain, callback) { if (!domain || typeof domain !== 'string') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } const options = { diff --git a/lib/recipientLists.js b/lib/recipientLists.js index a1edec6..a4f7364 100644 --- a/lib/recipientLists.js +++ b/lib/recipientLists.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'recipient-lists'; module.exports = function(client) { @@ -38,7 +37,7 @@ module.exports = function(client) { } if (!id) { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const reqOpts = { @@ -61,7 +60,7 @@ module.exports = function(client) { */ create: function(recipientList, callback) { if (!recipientList || typeof recipientList !== 'object' || !recipientList.recipients) { - return withCallback(Promise.reject(new Error('recipient list is required')), callback); + return client.reject(new Error('recipient list is required'), callback); } const reqOpts = { @@ -88,11 +87,11 @@ module.exports = function(client) { */ update: function(id, recipientList, callback) { if (!id) { - return withCallback(Promise.reject(new Error('recipient list id is required')), callback); + return client.reject(new Error('recipient list id is required'), callback); } if (!recipientList || typeof recipientList === 'function') { - return withCallback(Promise.reject(new Error('recipient list is required')), callback); + return client.reject(new Error('recipient list is required'), callback); } const reqOpts = { @@ -117,7 +116,7 @@ module.exports = function(client) { */ delete: function(id, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const reqOpts = { diff --git a/lib/relayWebhooks.js b/lib/relayWebhooks.js index 5d835ca..9126aea 100644 --- a/lib/relayWebhooks.js +++ b/lib/relayWebhooks.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'relay-webhooks'; module.exports = function(client) { @@ -26,7 +25,7 @@ module.exports = function(client) { */ get: function(id, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const options = { @@ -44,7 +43,7 @@ module.exports = function(client) { */ create: function(webhook, callback) { if (!webhook || typeof webhook !== 'object') { - return withCallback(Promise.reject(new Error('webhook object is required')), callback); + return client.reject(new Error('webhook object is required'), callback); } const reqOpts = { @@ -64,11 +63,11 @@ module.exports = function(client) { */ update: function(id, webhook, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } if (!webhook || typeof webhook !== 'object') { - return withCallback(Promise.reject(new Error('webhook object is required')), callback); + return client.reject(new Error('webhook object is required'), callback); } const reqOpts = { @@ -87,7 +86,7 @@ module.exports = function(client) { */ delete: function(id, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const options = { diff --git a/lib/sendingDomains.js b/lib/sendingDomains.js index 9756402..b28559d 100644 --- a/lib/sendingDomains.js +++ b/lib/sendingDomains.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'sending-domains'; module.exports = function(client) { @@ -28,7 +27,7 @@ module.exports = function(client) { */ get: function(domain, callback) { if (!domain || typeof domain === 'function') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } const options = { @@ -47,7 +46,7 @@ module.exports = function(client) { */ create: function(createOpts, callback) { if (!createOpts || typeof createOpts !== 'object') { - return withCallback(Promise.reject(new Error('create options are required')), callback); + return client.reject(new Error('create options are required'), callback); } const options = { @@ -68,11 +67,11 @@ module.exports = function(client) { */ update: function(domain, updateOpts, callback) { if (typeof domain !== 'string') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } if (!updateOpts || typeof updateOpts !== 'object') { - return withCallback(Promise.reject(new Error('update options are required')), callback); + return client.reject(new Error('update options are required'), callback); } const options = { @@ -92,7 +91,7 @@ module.exports = function(client) { */ delete: function(domain, callback) { if (typeof domain !== 'string') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } const options = { @@ -112,11 +111,11 @@ module.exports = function(client) { */ verify: function(domain, options, callback) { if (typeof domain !== 'string') { - return withCallback(Promise.reject(new Error('domain is required')), callback); + return client.reject(new Error('domain is required'), callback); } if (!options || typeof options !== 'object') { - return withCallback(Promise.reject(new Error('verification options are required')), callback); + return client.reject(new Error('verification options are required'), callback); } const reqOpts = { diff --git a/lib/sparkpost.js b/lib/sparkpost.js index e370ac0..87783b8 100644 --- a/lib/sparkpost.js +++ b/lib/sparkpost.js @@ -162,6 +162,10 @@ SparkPost.prototype.delete = function(options, callback) { return this.request(options, callback); }; +SparkPost.prototype.reject = function(error, callback) { + return withCallback(Promise.reject(error), callback); +}; + module.exports = SparkPost; /** diff --git a/lib/subaccounts.js b/lib/subaccounts.js index 2996034..15546ba 100644 --- a/lib/subaccounts.js +++ b/lib/subaccounts.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'subaccounts'; module.exports = function(client) { @@ -26,7 +25,7 @@ module.exports = function(client) { */ get: function(id, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const options = { @@ -43,7 +42,7 @@ module.exports = function(client) { */ create: function(subaccount, callback) { if (!subaccount || typeof subaccount !== 'object') { - return withCallback(Promise.reject(new Error('subaccount object is required')), callback); + return client.reject(new Error('subaccount object is required'), callback); } const reqOpts = { @@ -62,11 +61,11 @@ module.exports = function(client) { */ update: function(id, subaccount, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } if (!subaccount || typeof subaccount !== 'object') { - return withCallback(Promise.reject(new Error('subaccount object is required')), callback); + return client.reject(new Error('subaccount object is required'), callback); } const reqOpts = { diff --git a/lib/suppressionList.js b/lib/suppressionList.js index f06da11..f683a11 100644 --- a/lib/suppressionList.js +++ b/lib/suppressionList.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'suppression-list'; module.exports = function(client) { @@ -31,7 +30,7 @@ module.exports = function(client) { */ get: function(email, callback) { if (!email || typeof email === 'function') { - return withCallback(Promise.reject(new Error('email is required')), callback); + return client.reject(new Error('email is required'), callback); } const options = { @@ -50,7 +49,7 @@ module.exports = function(client) { */ upsert: function(listEntries, callback) { if (!listEntries || typeof listEntries === 'function') { - return withCallback(Promise.reject(new Error('list entries is required')), callback); + return client.reject(new Error('list entries is required'), callback); } if (!Array.isArray(listEntries)) { @@ -74,7 +73,7 @@ module.exports = function(client) { */ delete: function(email, callback) { if (!email || typeof email === 'function') { - return withCallback(Promise.reject(new Error('email is required')), callback); + return client.reject(new Error('email is required'), callback); } const options = { diff --git a/lib/templates.js b/lib/templates.js index d53a784..a7b2b9f 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'templates'; const _ = require('lodash'); @@ -36,7 +35,7 @@ module.exports = function(client) { } if (!id) { - return withCallback(Promise.reject(new Error('template id is required')), callback); + return client.reject(new Error('template id is required'), callback); } const reqOpts = { @@ -55,7 +54,7 @@ module.exports = function(client) { */ create: function(template, callback) { if (!template || typeof template !== 'object') { - return withCallback(Promise.reject(new Error('template object is required')), callback); + return client.reject(new Error('template object is required'), callback); } const reqOpts = { @@ -82,11 +81,11 @@ module.exports = function(client) { } if (!id) { - return withCallback(Promise.reject(new Error('template id is required')), callback); + return client.reject(new Error('template id is required'), callback); } if (!template || typeof template !== 'object') { - return withCallback(Promise.reject(new Error('template object is required')), callback); + return client.reject(new Error('template object is required'), callback); } const reqOpts = { @@ -106,7 +105,7 @@ module.exports = function(client) { */ delete: function(id, callback) { if (!id || typeof id !== 'string') { - return withCallback(Promise.reject(new Error('template id is required')), callback); + return client.reject(new Error('template id is required'), callback); } const options = { @@ -132,7 +131,7 @@ module.exports = function(client) { } if (!id) { - return withCallback(Promise.reject(new Error('template id is required')), callback); + return client.reject(new Error('template id is required'), callback); } const reqOpts = { diff --git a/lib/transmissions.js b/lib/transmissions.js index 1b084c2..084c9f8 100644 --- a/lib/transmissions.js +++ b/lib/transmissions.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const withCallback = require('./Promise'); const api = 'transmissions'; /* @@ -41,7 +40,7 @@ module.exports = function(client) { */ get: function(id, callback) { if (typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const options = { @@ -66,7 +65,7 @@ module.exports = function(client) { } if (!transmission || typeof transmission !== 'object') { - return withCallback(Promise.reject(new Error('transmission object is required')), callback); + return client.reject(new Error('transmission object is required'), callback); } transmission = formatPayload(transmission); diff --git a/lib/webhooks.js b/lib/webhooks.js index bc8a820..d6f46d6 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -1,6 +1,5 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'webhooks'; module.exports = function(client) { @@ -48,7 +47,7 @@ module.exports = function(client) { } if (typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const reqOpts = { @@ -72,7 +71,7 @@ module.exports = function(client) { */ create: function(webhook, callback) { if (!webhook || typeof webhook === 'function') { - return withCallback(Promise.reject(new Error('webhook object is required')), callback); + return client.reject(new Error('webhook object is required'), callback); } const options = { @@ -93,11 +92,11 @@ module.exports = function(client) { */ update: function(id, webhook, callback) { if (!id) { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } if (!webhook || typeof webhook === 'function') { - return withCallback(Promise.reject(new Error('webhook object is required')), callback); + return client.reject(new Error('webhook object is required'), callback); } const options = { @@ -119,7 +118,7 @@ module.exports = function(client) { */ delete: function(id, callback) { if (!id || typeof id === 'function') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const options = { @@ -140,11 +139,11 @@ module.exports = function(client) { */ validate: function(id, options, callback) { if (typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } if (!options || typeof options === 'function' || !options.message) { - return withCallback(Promise.reject(new Error('message is required')), callback); + return client.reject(new Error('message is required'), callback); } const reqOpts = { @@ -173,7 +172,7 @@ module.exports = function(client) { } if (typeof id !== 'string') { - return withCallback(Promise.reject(new Error('id is required')), callback); + return client.reject(new Error('id is required'), callback); } const reqOpts = { From 1737693fb14dc0ea2b19f1bc23f7267c1d5382ff Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 11:45:42 -0500 Subject: [PATCH 5/9] fixed tests --- test/spec/inboundDomains.spec.js | 4 +++- test/spec/recipientLists.spec.js | 4 +++- test/spec/relayWebhooks.spec.js | 4 +++- test/spec/sendingDomains.spec.js | 6 ++++-- test/spec/subaccounts.spec.js | 4 +++- test/spec/suppressionList.spec.js | 4 +++- test/spec/templates.spec.js | 4 +++- test/spec/transmissions.spec.js | 4 +++- test/spec/webhooks.spec.js | 4 +++- 9 files changed, 28 insertions(+), 10 deletions(-) diff --git a/test/spec/inboundDomains.spec.js b/test/spec/inboundDomains.spec.js index ce4b3fe..63fea96 100644 --- a/test/spec/inboundDomains.spec.js +++ b/test/spec/inboundDomains.spec.js @@ -2,6 +2,7 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -16,7 +17,8 @@ describe('Inbound Domains Library', function() { client = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; inboundDomains = require('../../lib/inboundDomains')(client); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index fc353b1..2123c0c 100644 --- a/test/spec/recipientLists.spec.js +++ b/test/spec/recipientLists.spec.js @@ -3,6 +3,7 @@ var _ = require('lodash') , chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -18,7 +19,8 @@ describe('Recipient Lists Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; recipientLists = require('../../lib/recipientLists')(client); diff --git a/test/spec/relayWebhooks.spec.js b/test/spec/relayWebhooks.spec.js index 35aaa35..c7cbccf 100644 --- a/test/spec/relayWebhooks.spec.js +++ b/test/spec/relayWebhooks.spec.js @@ -2,6 +2,7 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -17,7 +18,8 @@ describe('Relay Webhooks Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; relayWebhooks = require('../../lib/relayWebhooks')(client); diff --git a/test/spec/sendingDomains.spec.js b/test/spec/sendingDomains.spec.js index e8d3aa7..2fd7f57 100644 --- a/test/spec/sendingDomains.spec.js +++ b/test/spec/sendingDomains.spec.js @@ -3,6 +3,7 @@ var _ = require('lodash') , chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -18,7 +19,8 @@ describe('Sending Domains Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; sendingDomains = require('../../lib/sendingDomains')(client); @@ -120,5 +122,5 @@ describe('Sending Domains Library', function() { return expect(sendingDomains.verify('test')).to.be.rejectedWith('verification options are required'); }); }); - + }); diff --git a/test/spec/subaccounts.spec.js b/test/spec/subaccounts.spec.js index b4cec81..ac0a5d7 100644 --- a/test/spec/subaccounts.spec.js +++ b/test/spec/subaccounts.spec.js @@ -2,6 +2,7 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -16,7 +17,8 @@ describe('Subaccounts Library', function() { client = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), - put: sinon.stub().resolves({}) + put: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; subaccounts = require('../../lib/subaccounts')(client); diff --git a/test/spec/suppressionList.spec.js b/test/spec/suppressionList.spec.js index f28be3b..4832e66 100644 --- a/test/spec/suppressionList.spec.js +++ b/test/spec/suppressionList.spec.js @@ -2,6 +2,7 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -17,7 +18,8 @@ describe('Suppression List Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; suppressionList = require('../../lib/suppressionList')(client); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index f89b308..5e517c8 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -2,6 +2,7 @@ var _ = require('lodash') , chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -17,7 +18,8 @@ describe('Templates Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; templates = require('../../lib/templates')(client); diff --git a/test/spec/transmissions.spec.js b/test/spec/transmissions.spec.js index 125c64c..d822e17 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -2,6 +2,7 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -88,7 +89,8 @@ describe('Transmissions Library', function() { beforeEach(function() { client = { get: sinon.stub().resolves({}), - post: sinon.stub().resolves({}) + post: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; transmissions = require('../../lib/transmissions')(client); diff --git a/test/spec/webhooks.spec.js b/test/spec/webhooks.spec.js index 2f79d49..0ed46bb 100644 --- a/test/spec/webhooks.spec.js +++ b/test/spec/webhooks.spec.js @@ -3,6 +3,7 @@ var _ = require('lodash') , chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -18,7 +19,8 @@ describe('Webhooks Library', function() { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; webhooks = require('../../lib/webhooks')(client); From 4a7271e80c4d5254527b66f8c26afc86c62ee839 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 12:48:43 -0500 Subject: [PATCH 6/9] added tests to guarantee that callback is called on api call --- test/spec/inboundDomains.spec.js | 39 +++++++++++++++ test/spec/messageEvents.spec.js | 9 ++++ test/spec/recipientLists.spec.js | 72 ++++++++++++++++++++++++++- test/spec/relayWebhooks.spec.js | 32 ++++++++++++ test/spec/sendingDomains.spec.js | 54 +++++++++++++++++++++ test/spec/subaccounts.spec.js | 36 ++++++++++++++ test/spec/suppressionList.spec.js | 36 ++++++++++++++ test/spec/templates.spec.js | 54 +++++++++++++++++++++ test/spec/transmissions.spec.js | 29 ++++++++++- test/spec/webhooks.spec.js | 81 +++++++++++++++++++++++++++++++ 10 files changed, 439 insertions(+), 3 deletions(-) diff --git a/test/spec/inboundDomains.spec.js b/test/spec/inboundDomains.spec.js index 63fea96..9438745 100644 --- a/test/spec/inboundDomains.spec.js +++ b/test/spec/inboundDomains.spec.js @@ -31,6 +31,17 @@ describe('Inbound Domains Library', function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'}); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return inboundDomains.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + + + }); }); describe('get Method', function() { @@ -41,6 +52,15 @@ describe('Inbound Domains Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return inboundDomains.get('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(inboundDomains.get()).to.be.rejectedWith('domain is required'); }); @@ -56,6 +76,16 @@ describe('Inbound Domains Library', function() { }); }); + it('should call the callback once', function() { + let createOpts = {domain: 'test'}; + client.post.yields(); + let cb = sinon.stub(); + + return inboundDomains.create(createOpts, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(inboundDomains.create()).to.be.rejectedWith('create options are required'); }); @@ -69,6 +99,15 @@ describe('Inbound Domains Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return inboundDomains.delete('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(inboundDomains.delete()).to.be.rejectedWith('domain is required'); }); diff --git a/test/spec/messageEvents.spec.js b/test/spec/messageEvents.spec.js index eecf271..359180f 100644 --- a/test/spec/messageEvents.spec.js +++ b/test/spec/messageEvents.spec.js @@ -71,5 +71,14 @@ describe('Message Events Library', function() { }); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return messageEvents.search({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); }); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index 2123c0c..76bbd50 100644 --- a/test/spec/recipientLists.spec.js +++ b/test/spec/recipientLists.spec.js @@ -35,6 +35,15 @@ describe('Recipient Lists Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return recipientLists.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + }); describe('get', function() { @@ -46,14 +55,22 @@ describe('Recipient Lists Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return recipientLists.get('test-id', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(recipientLists.get()).to.be.rejectedWith('id is required'); }); it('should not throw an error if optional 2nd argument is a function (callback)', function() { - let cb = sinon.stub(); - client.get.yields(); + let cb = sinon.stub(); return recipientLists.get('test-id', cb).then(() => { expect(cb.callCount).to.equal(1); @@ -95,6 +112,27 @@ describe('Recipient Lists Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + let testList = { + id: 'test_list', + recipients: [ + { + address: { + email: 'test@test.com', + name: 'test' + } + } + ] + }; + + return recipientLists.create(testList, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if no recipients are provided', function() { return Promise.all([ expect(recipientLists.create(), 'no recipient list hash at all').to.be.rejectedWith('recipient list is required'), @@ -147,6 +185,26 @@ describe('Recipient Lists Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + const testList = { + recipients: [ + { + address: { + email: 'test@test.com', + name: 'test' + } + } + ] + }; + + return recipientLists.update('test-id', testList, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if recipient list is missing', function() { return expect(recipientLists.update('test-id')).to.be.rejectedWith('recipient list is required'); }); @@ -185,6 +243,16 @@ describe('Recipient Lists Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return recipientLists.delete('test-id', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + + it('should throw an error if id is missing', function() { return expect(recipientLists.delete()).to.be.rejectedWith('id is required'); }); diff --git a/test/spec/relayWebhooks.spec.js b/test/spec/relayWebhooks.spec.js index c7cbccf..fb3d197 100644 --- a/test/spec/relayWebhooks.spec.js +++ b/test/spec/relayWebhooks.spec.js @@ -32,6 +32,15 @@ describe('Relay Webhooks Library', function() { expect(client.get.firstCall.args[0].uri).to.equal('relay-webhooks'); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return relayWebhooks.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get Method', function() { @@ -42,6 +51,15 @@ describe('Relay Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return relayWebhooks.get('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(relayWebhooks.get()).to.be.rejectedWith('id is required'); }); @@ -61,6 +79,20 @@ describe('Relay Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + let webhook = { + target: 'test', + domain: 'inbound.example.com' + }; + + return relayWebhooks.create(webhook, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if webhook object is missing', function() { return expect(relayWebhooks.create()).to.be.rejectedWith('webhook object is required'); }); diff --git a/test/spec/sendingDomains.spec.js b/test/spec/sendingDomains.spec.js index 2fd7f57..4d310c4 100644 --- a/test/spec/sendingDomains.spec.js +++ b/test/spec/sendingDomains.spec.js @@ -33,6 +33,15 @@ describe('Sending Domains Library', function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains'}); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return sendingDomains.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get', function() { @@ -43,6 +52,15 @@ describe('Sending Domains Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return sendingDomains.get('domain.com', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(sendingDomains.get()).to.be.rejectedWith('domain is required'); }); @@ -60,6 +78,15 @@ describe('Sending Domains Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return sendingDomains.create({ domain: 'test' }, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if create options are missing', function() { return expect(sendingDomains.create()).to.be.rejectedWith('create options are required'); }); @@ -78,6 +105,15 @@ describe('Sending Domains Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + return sendingDomains.update('test', { domain: 'test' }, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if update options are missing', function() { return expect(sendingDomains.update('test')).to.be.rejectedWith('update options are required'); }); @@ -95,6 +131,15 @@ describe('Sending Domains Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return sendingDomains.delete('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(sendingDomains.delete()).to.be.rejectedWith('domain is required'); }); @@ -114,6 +159,15 @@ describe('Sending Domains Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return sendingDomains.verify('test', {}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if domain is missing', function() { return expect(sendingDomains.verify()).to.be.rejectedWith('domain is required'); }); diff --git a/test/spec/subaccounts.spec.js b/test/spec/subaccounts.spec.js index ac0a5d7..4a17683 100644 --- a/test/spec/subaccounts.spec.js +++ b/test/spec/subaccounts.spec.js @@ -31,6 +31,15 @@ describe('Subaccounts Library', function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts'); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return subaccounts.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get Method', function() { @@ -41,6 +50,15 @@ describe('Subaccounts Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return subaccounts.get('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(subaccounts.get()).to.be.rejectedWith('id is required'); }); @@ -61,6 +79,15 @@ describe('Subaccounts Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return subaccounts.create({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if subaccount object is missing', function() { return expect(subaccounts.create()).to.be.rejectedWith('subaccount object is required'); }); @@ -81,6 +108,15 @@ describe('Subaccounts Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + return subaccounts.update('id', {}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if subaccount id is missing from options', function() { return expect(subaccounts.update()).to.be.rejectedWith('id is required'); }); diff --git a/test/spec/suppressionList.spec.js b/test/spec/suppressionList.spec.js index 4832e66..88187e8 100644 --- a/test/spec/suppressionList.spec.js +++ b/test/spec/suppressionList.spec.js @@ -32,6 +32,15 @@ describe('Suppression List Library', function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list'); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return suppressionList.list({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get', function() { @@ -42,6 +51,15 @@ describe('Suppression List Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return suppressionList.get('test@test.com', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if email is missing', function() { return expect(suppressionList.get()).to.be.rejectedWith('email is required'); }); @@ -58,6 +76,15 @@ describe('Suppression List Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + return suppressionList.upsert({ email: 'test@test.com' }, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should accept an array of list entries', function() { var listEntries = [ { email: 'test1@test.com' }, @@ -84,6 +111,15 @@ describe('Suppression List Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return suppressionList.delete('test@test.com', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if email deleteEntry missing', function() { return expect(suppressionList.delete()).to.be.rejectedWith('email is required'); }); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index 5e517c8..4504927 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -32,6 +32,15 @@ describe('Templates Library', function() { expect(client.get.firstCall.args[0].uri).to.equal('templates'); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return templates.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get Method', function() { @@ -43,6 +52,15 @@ describe('Templates Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return templates.get('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(templates.get()).to.be.rejectedWith('template id is required'); }); @@ -83,6 +101,15 @@ describe('Templates Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return templates.create({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if template object is missing', function() { return expect(templates.create()).to.be.rejectedWith('template object is required'); }); @@ -102,6 +129,15 @@ describe('Templates Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + return templates.update('id', {}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if template id is missing', function() { return expect(templates.update()).to.be.rejectedWith('template id is required'); }); @@ -148,6 +184,15 @@ describe('Templates Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return templates.delete('id', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(templates.delete()).to.be.rejectedWith('template id is required'); }); @@ -170,6 +215,15 @@ describe('Templates Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return templates.preview('id', {}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(templates.preview()).to.be.rejectedWith('template id is required'); }); diff --git a/test/spec/transmissions.spec.js b/test/spec/transmissions.spec.js index d822e17..33cb3bb 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -96,7 +96,7 @@ describe('Transmissions Library', function() { transmissions = require('../../lib/transmissions')(client); }); - describe('all Method', function() { + describe('list Method', function() { it('should call client get method with the appropriate uri', function() { return transmissions.list() .then(function() { @@ -134,6 +134,15 @@ describe('Transmissions Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({template_id: 'test-template'}); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return transmissions.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('find Method', function() { @@ -144,6 +153,15 @@ describe('Transmissions Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return transmissions.get('id', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(transmissions.get()).to.be.rejectedWith('id is required'); }); @@ -162,6 +180,15 @@ describe('Transmissions Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return transmissions.send({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if transmission object is missing', function() { return expect(transmissions.send(function() {})).to.be.rejectedWith('transmission object is required'); }); diff --git a/test/spec/webhooks.spec.js b/test/spec/webhooks.spec.js index 0ed46bb..85a7f75 100644 --- a/test/spec/webhooks.spec.js +++ b/test/spec/webhooks.spec.js @@ -44,6 +44,15 @@ describe('Webhooks Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({timezone: 'America/New_York'}); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return webhooks.list(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('get Method', function() { @@ -54,6 +63,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return webhooks.get('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(webhooks.get()).to.be.rejectedWith('id is required'); }); @@ -85,6 +103,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return webhooks.create({}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if webhook is missing', function() { return expect(webhooks.create()).to.be.rejectedWith('webhook object is required'); }); @@ -105,6 +132,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.put.yields(); + let cb = sinon.stub(); + + return webhooks.update('id', {}, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(webhooks.update()).to.be.rejectedWith('id is required'); }); @@ -122,6 +158,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.delete.yields(); + let cb = sinon.stub(); + + return webhooks.delete('id', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(webhooks.delete()).to.be.rejectedWith('id is required'); }); @@ -142,6 +187,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.post.yields(); + let cb = sinon.stub(); + + return webhooks.validate('id', { message: {} }, cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(webhooks.validate()).to.be.rejectedWith('id is required'); }); @@ -159,6 +213,15 @@ describe('Webhooks Library', function() { }); }); + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return webhooks.getBatchStatus('test', cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); + it('should throw an error if id is missing', function() { return expect(webhooks.getBatchStatus()).to.be.rejectedWith('id is required'); }); @@ -182,6 +245,15 @@ describe('Webhooks Library', function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/documentation'); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return webhooks.getDocumentation(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); describe('getSamples Method', function() { @@ -202,5 +274,14 @@ describe('Webhooks Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({events: 'bounces'}); }); }); + + it('should call the callback once', function() { + client.get.yields(); + let cb = sinon.stub(); + + return webhooks.getSamples(cb).then(function() { + expect(cb.callCount).to.equal(1); + }); + }); }); }); From dbdcbd9158f99a656b350e6a23fed204beeca214 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 14:58:10 -0500 Subject: [PATCH 7/9] renamed Promise.js to withCallback.js --- lib/sparkpost.js | 2 +- lib/{Promise.js => withCallback.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/{Promise.js => withCallback.js} (100%) diff --git a/lib/sparkpost.js b/lib/sparkpost.js index 87783b8..5e28754 100644 --- a/lib/sparkpost.js +++ b/lib/sparkpost.js @@ -2,7 +2,7 @@ const version = require('../package.json').version; const url = require('url'); -const withCallback = require('./Promise'); +const withCallback = require('./withCallback'); const request = require('request'); const _ = require('lodash'); diff --git a/lib/Promise.js b/lib/withCallback.js similarity index 100% rename from lib/Promise.js rename to lib/withCallback.js From 951424160e152b0559adb03b3d7788fe7f772cb0 Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 14:58:50 -0500 Subject: [PATCH 8/9] moved callback tests into primary test for each method --- test/spec/inboundDomains.spec.js | 62 +++++--------- test/spec/messageEvents.spec.js | 18 ++--- test/spec/recipientLists.spec.js | 99 ++++++----------------- test/spec/relayWebhooks.spec.js | 61 ++++++-------- test/spec/sendingDomains.spec.js | 88 +++++++------------- test/spec/subaccounts.spec.js | 60 +++++--------- test/spec/suppressionList.spec.js | 60 +++++--------- test/spec/templates.spec.js | 97 +++++++--------------- test/spec/transmissions.spec.js | 56 ++++--------- test/spec/webhooks.spec.js | 130 +++++++++--------------------- 10 files changed, 218 insertions(+), 513 deletions(-) diff --git a/test/spec/inboundDomains.spec.js b/test/spec/inboundDomains.spec.js index 9438745..3693d91 100644 --- a/test/spec/inboundDomains.spec.js +++ b/test/spec/inboundDomains.spec.js @@ -11,7 +11,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Inbound Domains Library', function() { - let client, inboundDomains; + let client, inboundDomains, callback; beforeEach(function() { client = { @@ -21,45 +21,34 @@ describe('Inbound Domains Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + inboundDomains = require('../../lib/inboundDomains')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return inboundDomains.list() + client.get.yields(); + + return inboundDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'}); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return inboundDomains.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - - - }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return inboundDomains.get('test') + client.get.yields(); + + return inboundDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains/test'}); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return inboundDomains.get('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); it('should throw an error if domain is missing', function() { return expect(inboundDomains.get()).to.be.rejectedWith('domain is required'); @@ -68,24 +57,17 @@ describe('Inbound Domains Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + let createOpts = {domain: 'test'}; - return inboundDomains.create(createOpts) + return inboundDomains.create(createOpts, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('inbound-domains'); expect(client.post.firstCall.args[0].json).to.deep.equal(createOpts); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - let createOpts = {domain: 'test'}; - client.post.yields(); - let cb = sinon.stub(); - - return inboundDomains.create(createOpts, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if domain is missing', function() { return expect(inboundDomains.create()).to.be.rejectedWith('create options are required'); }); @@ -93,21 +75,15 @@ describe('Inbound Domains Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return inboundDomains.delete('test') + client.delete.yields(); + + return inboundDomains.delete('test', callback) .then(function () { expect(client.delete.firstCall.args[0].uri).to.equal('inbound-domains/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return inboundDomains.delete('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if domain is missing', function() { return expect(inboundDomains.delete()).to.be.rejectedWith('domain is required'); }); diff --git a/test/spec/messageEvents.spec.js b/test/spec/messageEvents.spec.js index 359180f..aca7e25 100644 --- a/test/spec/messageEvents.spec.js +++ b/test/spec/messageEvents.spec.js @@ -10,18 +10,22 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Message Events Library', function() { - let client, messageEvents; + let client, messageEvents, callback; beforeEach(function() { client = { get: sinon.stub().resolves({}) }; + callback = sinon.stub(); + messageEvents = require('../../lib/messageEvents')(client); }); describe('search Method', function() { it('should call client get method with the appropriate parameters', function() { + client.get.yields(); + var options = { bounce_classes: '10,50', campaign_ids: 'test_campaign', @@ -38,11 +42,12 @@ describe('Message Events Library', function() { to: '2016-11-14T16:15', transmission_ids: '65832150921904138' }; - return messageEvents.search(options) + return messageEvents.search(options, callback) .then(function() { Object.keys(options).forEach(function(key) { expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]); }); + expect(callback.callCount).to.equal(1); }); }); @@ -71,14 +76,5 @@ describe('Message Events Library', function() { }); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return messageEvents.search({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); }); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index 76bbd50..1e505c1 100644 --- a/test/spec/recipientLists.spec.js +++ b/test/spec/recipientLists.spec.js @@ -12,7 +12,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Recipient Lists Library', function() { - var client, recipientLists; + var client, recipientLists, callback; beforeEach(function() { client = { @@ -23,47 +23,36 @@ describe('Recipient Lists Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + recipientLists = require('../../lib/recipientLists')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return recipientLists.list() + client.get.yields(); + + return recipientLists.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return recipientLists.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return recipientLists.get('test-id') + client.get.yields(); + + return recipientLists.get('test-id', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists/test-id'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return recipientLists.get('test-id', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(recipientLists.get()).to.be.rejectedWith('id is required'); }); @@ -93,6 +82,8 @@ describe('Recipient Lists Library', function() { describe('create', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + let testList = { id: 'test_list', recipients: [ @@ -105,34 +96,14 @@ describe('Recipient Lists Library', function() { ] }; - return recipientLists.create(testList) + return recipientLists.create(testList, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('recipient-lists'); expect(client.post.firstCall.args[0].json).to.deep.equal(testList); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - let testList = { - id: 'test_list', - recipients: [ - { - address: { - email: 'test@test.com', - name: 'test' - } - } - ] - }; - - return recipientLists.create(testList, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if no recipients are provided', function() { return Promise.all([ expect(recipientLists.create(), 'no recipient list hash at all').to.be.rejectedWith('recipient list is required'), @@ -166,6 +137,8 @@ describe('Recipient Lists Library', function() { describe('update', function() { it('should call client put method with the appropriate uri and payload', function() { + client.put.yields(); + const testList = { recipients: [ { @@ -178,33 +151,14 @@ describe('Recipient Lists Library', function() { }; const testId = 'test-id'; - return recipientLists.update(testId, testList) + return recipientLists.update(testId, testList, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('recipient-lists/' + testId); expect(client.put.firstCall.args[0].json).to.deep.equal(testList); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - const testList = { - recipients: [ - { - address: { - email: 'test@test.com', - name: 'test' - } - } - ] - }; - - return recipientLists.update('test-id', testList, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if recipient list is missing', function() { return expect(recipientLists.update('test-id')).to.be.rejectedWith('recipient list is required'); }); @@ -237,22 +191,15 @@ describe('Recipient Lists Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - return recipientLists.delete('test') + client.delete.yields(); + + return recipientLists.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('recipient-lists/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return recipientLists.delete('test-id', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - - it('should throw an error if id is missing', function() { return expect(recipientLists.delete()).to.be.rejectedWith('id is required'); }); diff --git a/test/spec/relayWebhooks.spec.js b/test/spec/relayWebhooks.spec.js index fb3d197..0ad19c0 100644 --- a/test/spec/relayWebhooks.spec.js +++ b/test/spec/relayWebhooks.spec.js @@ -11,7 +11,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Relay Webhooks Library', function() { - let client, relayWebhooks; + let client, relayWebhooks, callback; beforeEach(function() { client = { @@ -22,44 +22,34 @@ describe('Relay Webhooks Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + relayWebhooks = require('../../lib/relayWebhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return relayWebhooks.list() + client.get.yields(); + + return relayWebhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('relay-webhooks'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return relayWebhooks.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return relayWebhooks.get('test') + client.get.yields(); + + return relayWebhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'relay-webhooks/test'}); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return relayWebhooks.get('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(relayWebhooks.get()).to.be.rejectedWith('id is required'); }); @@ -67,32 +57,21 @@ describe('Relay Webhooks Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + let webhook = { target: 'test', domain: 'inbound.example.com' }; - return relayWebhooks.create(webhook) + return relayWebhooks.create(webhook, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('relay-webhooks'); expect(client.post.firstCall.args[0].json).to.deep.equal(webhook); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - let webhook = { - target: 'test', - domain: 'inbound.example.com' - }; - - return relayWebhooks.create(webhook, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if webhook object is missing', function() { return expect(relayWebhooks.create()).to.be.rejectedWith('webhook object is required'); }); @@ -100,14 +79,17 @@ describe('Relay Webhooks Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { + client.put.yields(); + let webhook = { name: 'New Replies Webhook' }; - return relayWebhooks.update('test', webhook) + return relayWebhooks.update('test', webhook, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('relay-webhooks/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(webhook); + expect(callback.callCount).to.equal(1); }); }); @@ -122,9 +104,12 @@ describe('Relay Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return relayWebhooks.delete('test') + client.delete.yields(); + + return relayWebhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('relay-webhooks/test'); + expect(callback.callCount).to.equal(1); }); }); diff --git a/test/spec/sendingDomains.spec.js b/test/spec/sendingDomains.spec.js index 4d310c4..c330f02 100644 --- a/test/spec/sendingDomains.spec.js +++ b/test/spec/sendingDomains.spec.js @@ -12,7 +12,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Sending Domains Library', function() { - var client, sendingDomains; + var client, sendingDomains, callback; beforeEach(function() { client = { @@ -23,44 +23,34 @@ describe('Sending Domains Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + sendingDomains = require('../../lib/sendingDomains')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return sendingDomains.list() + client.get.yields(); + + return sendingDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains'}); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return sendingDomains.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return sendingDomains.get('test') + client.get.yields(); + + return sendingDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains/test'}); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return sendingDomains.get('domain.com', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if domain is missing', function() { return expect(sendingDomains.get()).to.be.rejectedWith('domain is required'); }); @@ -68,22 +58,16 @@ describe('Sending Domains Library', function() { describe('create', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var sendingDomain = { domain: 'test' }; - return sendingDomains.create(sendingDomain).then(function() { + return sendingDomains.create(sendingDomain, callback).then(function() { expect(client.post.firstCall.args[0].uri).to.equal('sending-domains'); expect(client.post.firstCall.args[0].json).to.deep.equal(sendingDomain); - }); - }); - - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return sendingDomains.create({ domain: 'test' }, cb).then(function() { - expect(cb.callCount).to.equal(1); + expect(callback.callCount).to.equal(1); }); }); @@ -94,26 +78,20 @@ describe('Sending Domains Library', function() { describe('update', function() { it('should call client put method with the appropriate uri and payload', function() { + client.put.yields(); + var sendingDomain = { tracking_domain: 'click.example1.com' }; - return sendingDomains.update('test', sendingDomain) + return sendingDomains.update('test', sendingDomain, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('sending-domains/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(_.omit(sendingDomain, 'domain')); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - return sendingDomains.update('test', { domain: 'test' }, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if update options are missing', function() { return expect(sendingDomains.update('test')).to.be.rejectedWith('update options are required'); }); @@ -125,21 +103,15 @@ describe('Sending Domains Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - return sendingDomains.delete('test') + client.delete.yields(); + + return sendingDomains.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('sending-domains/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return sendingDomains.delete('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if domain is missing', function() { return expect(sendingDomains.delete()).to.be.rejectedWith('domain is required'); }); @@ -147,27 +119,21 @@ describe('Sending Domains Library', function() { describe('verify', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var options = { dkim_verify: true, spf_verify: true }; - return sendingDomains.verify('test', options) + return sendingDomains.verify('test', options, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('sending-domains/test/verify'); expect(client.post.firstCall.args[0].json).to.deep.equal(_.omit(options, 'domain')); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return sendingDomains.verify('test', {}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if domain is missing', function() { return expect(sendingDomains.verify()).to.be.rejectedWith('domain is required'); }); diff --git a/test/spec/subaccounts.spec.js b/test/spec/subaccounts.spec.js index 4a17683..8f372e1 100644 --- a/test/spec/subaccounts.spec.js +++ b/test/spec/subaccounts.spec.js @@ -11,7 +11,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Subaccounts Library', function() { - let client, subaccounts; + let client, subaccounts, callback; beforeEach(function() { client = { @@ -21,44 +21,34 @@ describe('Subaccounts Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + subaccounts = require('../../lib/subaccounts')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return subaccounts.list() + client.get.yields(); + + return subaccounts.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return subaccounts.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return subaccounts.get('test') + client.get.yields(); + + return subaccounts.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return subaccounts.get('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(subaccounts.get()).to.be.rejectedWith('id is required'); }); @@ -66,28 +56,22 @@ describe('Subaccounts Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var subaccount = { name: 'test', key_label: 'test', key_grants: [] }; - return subaccounts.create(subaccount) + return subaccounts.create(subaccount, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('subaccounts'); expect(client.post.firstCall.args[0].json).to.deep.equal(subaccount); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return subaccounts.create({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if subaccount object is missing', function() { return expect(subaccounts.create()).to.be.rejectedWith('subaccount object is required'); }); @@ -95,28 +79,22 @@ describe('Subaccounts Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { + client.put.yields(); + var subaccount = { name: 'Hey Joe! Garage and Parts', status: 'suspended', ip_pool: '' }; - return subaccounts.update('test', subaccount) + return subaccounts.update('test', subaccount, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('subaccounts/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(subaccount); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - return subaccounts.update('id', {}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if subaccount id is missing from options', function() { return expect(subaccounts.update()).to.be.rejectedWith('id is required'); }); diff --git a/test/spec/suppressionList.spec.js b/test/spec/suppressionList.spec.js index 88187e8..6c82145 100644 --- a/test/spec/suppressionList.spec.js +++ b/test/spec/suppressionList.spec.js @@ -11,7 +11,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Suppression List Library', function() { - let client, suppressionList; + let client, suppressionList, callback; beforeEach(function() { client = { @@ -22,44 +22,34 @@ describe('Suppression List Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + suppressionList = require('../../lib/suppressionList')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return suppressionList.list({limit: 5}) + client.get.yields(); + + return suppressionList.list({limit: 5}, callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return suppressionList.list({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return suppressionList.get('test@test.com') + client.get.yields(); + + return suppressionList.get('test@test.com', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return suppressionList.get('test@test.com', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if email is missing', function() { return expect(suppressionList.get()).to.be.rejectedWith('email is required'); }); @@ -67,24 +57,18 @@ describe('Suppression List Library', function() { describe('upsert', function() { it('should accept a single list entry', function() { + client.put.yields(); + var listEntry = { email: 'test@test.com' }; - return suppressionList.upsert(listEntry) + return suppressionList.upsert(listEntry, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('suppression-list'); expect(client.put.firstCall.args[0].json.recipients).to.deep.equal([listEntry]); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - return suppressionList.upsert({ email: 'test@test.com' }, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should accept an array of list entries', function() { var listEntries = [ { email: 'test1@test.com' }, @@ -105,21 +89,15 @@ describe('Suppression List Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - return suppressionList.delete('test@test.com') + client.delete.yields(); + + return suppressionList.delete('test@test.com', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return suppressionList.delete('test@test.com', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if email deleteEntry missing', function() { return expect(suppressionList.delete()).to.be.rejectedWith('email is required'); }); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index 4504927..78827b4 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -11,7 +11,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Templates Library', function() { - var client, templates; + var client, templates, callback; beforeEach(function() { client = { @@ -22,45 +22,35 @@ describe('Templates Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + templates = require('../../lib/templates')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return templates.list() + client.get.yields(); + + return templates.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('templates'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return templates.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { + client.get.yields(); + var id = 'test'; - return templates.get(id) + return templates.get(id, callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('templates/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return templates.get('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(templates.get()).to.be.rejectedWith('template id is required'); }); @@ -77,39 +67,24 @@ describe('Templates Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({draft: true}); }); }); - - it('should work given just an id and callback', function() { - var id = 'test'; - - return templates.get(id, function() { - expect(client.get.firstCall.args[0].uri).to.contain(id); - expect(client.get.firstCall.args[0].qs).to.deep.equal({}); - }); - }); }); describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var template = { id: 'test' }; - return templates.create(template) + return templates.create(template, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('templates'); expect(client.post.firstCall.args[0].json).to.deep.equal(template); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return templates.create({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if template object is missing', function() { return expect(templates.create()).to.be.rejectedWith('template object is required'); }); @@ -117,27 +92,21 @@ describe('Templates Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { + client.put.yields(); + var id = 'test' , template = { name: 'A new name!' }; - return templates.update(id, template) + return templates.update(id, template, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('templates/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(template); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - return templates.update('id', {}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if template id is missing', function() { return expect(templates.update()).to.be.rejectedWith('template id is required'); }); @@ -178,21 +147,15 @@ describe('Templates Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return templates.delete('test') + client.delete.yields(); + + return templates.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('templates/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return templates.delete('id', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(templates.delete()).to.be.rejectedWith('template id is required'); }); @@ -200,6 +163,8 @@ describe('Templates Library', function() { describe('preview Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var id = 'test' , options = { substitution_data: { @@ -208,22 +173,14 @@ describe('Templates Library', function() { 'member': true } }; - return templates.preview(id, options) + return templates.preview(id, options, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('templates/test/preview'); expect(client.post.firstCall.args[0].json).to.deep.equal(options); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return templates.preview('id', {}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(templates.preview()).to.be.rejectedWith('template id is required'); }); diff --git a/test/spec/transmissions.spec.js b/test/spec/transmissions.spec.js index 33cb3bb..7f9aa55 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -9,7 +9,6 @@ require('sinon-as-promised'); chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); - var ccTransmission = { recipients: [ { @@ -84,7 +83,7 @@ var ccTransmission = { , expectedCCHeader = '"John" , "Jane" '; describe('Transmissions Library', function() { - var client, transmissions; + var client, transmissions, callback; beforeEach(function() { client = { @@ -93,26 +92,22 @@ describe('Transmissions Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + transmissions = require('../../lib/transmissions')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return transmissions.list() + client.get.yields(); + + return transmissions.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('transmissions'); + expect(callback.callCount).to.equal(1); }); }); - it('should call client get method with the appropriate uri using callback', function(done) { - client.get.yields(); - - transmissions.list(function() { - expect(client.get.firstCall.args[0].uri).to.equal('transmissions'); - done(); - }); - }); - it('should allow campaign_id to be set in options', function() { var options = { campaign_id: 'test-campaign' @@ -134,34 +129,19 @@ describe('Transmissions Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({template_id: 'test-template'}); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return transmissions.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('find Method', function() { it('should call client get method with the appropriate uri', function() { - return transmissions.get('test') + client.get.yields(); + + return transmissions.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'transmissions/test'}); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return transmissions.get('id', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(transmissions.get()).to.be.rejectedWith('id is required'); }); @@ -169,26 +149,20 @@ describe('Transmissions Library', function() { describe('send Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var transmission = { campaign_id: 'test-campaign' }; - return transmissions.send(transmission) + return transmissions.send(transmission, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('transmissions'); expect(client.post.firstCall.args[0].json).to.deep.equal(transmission); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return transmissions.send({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if transmission object is missing', function() { return expect(transmissions.send(function() {})).to.be.rejectedWith('transmission object is required'); }); diff --git a/test/spec/webhooks.spec.js b/test/spec/webhooks.spec.js index 85a7f75..e528930 100644 --- a/test/spec/webhooks.spec.js +++ b/test/spec/webhooks.spec.js @@ -12,7 +12,7 @@ chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); describe('Webhooks Library', function() { - var client, webhooks; + var client, webhooks, callback; beforeEach(function() { client = { @@ -23,14 +23,19 @@ describe('Webhooks Library', function() { reject: SparkPost.prototype.reject }; + callback = sinon.stub(); + webhooks = require('../../lib/webhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.list() + client.get.yields(); + + return webhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks'); + expect(callback.callCount).to.equal(1); }); }); @@ -44,34 +49,19 @@ describe('Webhooks Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({timezone: 'America/New_York'}); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return webhooks.list(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.get('test') + client.get.yields(); + + return webhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return webhooks.get('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(webhooks.get()).to.be.rejectedWith('id is required'); }); @@ -90,28 +80,22 @@ describe('Webhooks Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields() + var webhook = { name: 'Example webhook', target: 'http://client.example.com/example-webhook', events: ['delivery', 'injection', 'open', 'click'] }; - return webhooks.create(webhook) + return webhooks.create(webhook, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('webhooks'); expect(client.post.firstCall.args[0].json).to.deep.equal(webhook); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return webhooks.create({}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if webhook is missing', function() { return expect(webhooks.create()).to.be.rejectedWith('webhook object is required'); }); @@ -119,28 +103,22 @@ describe('Webhooks Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri', function() { + client.put.yields(); + var webhook = { name: 'Renamed webhook', events: ['rejection', 'delay'], auth_type: 'none' }; - return webhooks.update('test', webhook) + return webhooks.update('test', webhook, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('webhooks/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(webhook); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.put.yields(); - let cb = sinon.stub(); - - return webhooks.update('id', {}, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(webhooks.update()).to.be.rejectedWith('id is required'); }); @@ -152,21 +130,15 @@ describe('Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return webhooks.delete('test') + client.delete.yields(); + + return webhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('webhooks/test'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.delete.yields(); - let cb = sinon.stub(); - - return webhooks.delete('id', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(webhooks.delete()).to.be.rejectedWith('id is required'); }); @@ -174,28 +146,22 @@ describe('Webhooks Library', function() { describe('validate Method', function() { it('should call client post method with the appropriate uri and payload', function() { + client.post.yields(); + var options = { message: { msys: {} } }; - return webhooks.validate('test', options) + return webhooks.validate('test', options, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('webhooks/test/validate'); expect(client.post.firstCall.args[0].json).to.deep.equal(options); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.post.yields(); - let cb = sinon.stub(); - - return webhooks.validate('id', { message: {} }, cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(webhooks.validate()).to.be.rejectedWith('id is required'); }); @@ -207,21 +173,15 @@ describe('Webhooks Library', function() { describe('getBatchStatus Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getBatchStatus('test') + client.get.yields(); + + return webhooks.getBatchStatus('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test/batch-status'); + expect(callback.callCount).to.equal(1); }); }); - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return webhooks.getBatchStatus('test', cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); - it('should throw an error if id is missing', function() { return expect(webhooks.getBatchStatus()).to.be.rejectedWith('id is required'); }); @@ -240,27 +200,24 @@ describe('Webhooks Library', function() { describe('getDocumentation Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getDocumentation() + client.get.yields(); + + return webhooks.getDocumentation(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/documentation'); + expect(callback.callCount).to.equal(1); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return webhooks.getDocumentation(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); describe('getSamples Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getSamples() + client.get.yields(); + + return webhooks.getSamples(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/samples'); + expect(callback.callCount).to.equal(1); }); }); @@ -274,14 +231,5 @@ describe('Webhooks Library', function() { expect(client.get.firstCall.args[0].qs).to.deep.equal({events: 'bounces'}); }); }); - - it('should call the callback once', function() { - client.get.yields(); - let cb = sinon.stub(); - - return webhooks.getSamples(cb).then(function() { - expect(cb.callCount).to.equal(1); - }); - }); }); }); From c5af38e921f6a4595f049f568ec874210ffa782e Mon Sep 17 00:00:00 2001 From: Avi Goldman Date: Thu, 19 Jan 2017 16:37:33 -0500 Subject: [PATCH 9/9] modified tests to check that the callback is passed through --- test/spec/inboundDomains.spec.js | 17 ++++---------- test/spec/messageEvents.spec.js | 6 ++--- test/spec/recipientLists.spec.js | 25 +++++++------------- test/spec/relayWebhooks.spec.js | 22 +++++------------- test/spec/sendingDomains.spec.js | 26 ++++++--------------- test/spec/subaccounts.spec.js | 18 ++++----------- test/spec/suppressionList.spec.js | 18 ++++----------- test/spec/templates.spec.js | 26 ++++++--------------- test/spec/transmissions.spec.js | 14 ++++-------- test/spec/webhooks.spec.js | 38 ++++++++----------------------- 10 files changed, 59 insertions(+), 151 deletions(-) diff --git a/test/spec/inboundDomains.spec.js b/test/spec/inboundDomains.spec.js index 3693d91..f9eae93 100644 --- a/test/spec/inboundDomains.spec.js +++ b/test/spec/inboundDomains.spec.js @@ -21,31 +21,28 @@ describe('Inbound Domains Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; inboundDomains = require('../../lib/inboundDomains')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); return inboundDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return inboundDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains/test'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -57,14 +54,12 @@ describe('Inbound Domains Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - let createOpts = {domain: 'test'}; return inboundDomains.create(createOpts, callback) .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('inbound-domains'); expect(client.post.firstCall.args[0].json).to.deep.equal(createOpts); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -75,12 +70,10 @@ describe('Inbound Domains Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return inboundDomains.delete('test', callback) .then(function () { expect(client.delete.firstCall.args[0].uri).to.equal('inbound-domains/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/messageEvents.spec.js b/test/spec/messageEvents.spec.js index aca7e25..cfd381b 100644 --- a/test/spec/messageEvents.spec.js +++ b/test/spec/messageEvents.spec.js @@ -17,15 +17,13 @@ describe('Message Events Library', function() { get: sinon.stub().resolves({}) }; - callback = sinon.stub(); + callback = function() {}; messageEvents = require('../../lib/messageEvents')(client); }); describe('search Method', function() { it('should call client get method with the appropriate parameters', function() { - client.get.yields(); - var options = { bounce_classes: '10,50', campaign_ids: 'test_campaign', @@ -47,7 +45,7 @@ describe('Message Events Library', function() { Object.keys(options).forEach(function(key) { expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]); }); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index 1e505c1..af1b261 100644 --- a/test/spec/recipientLists.spec.js +++ b/test/spec/recipientLists.spec.js @@ -23,7 +23,7 @@ describe('Recipient Lists Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; recipientLists = require('../../lib/recipientLists')(client); }); @@ -31,12 +31,10 @@ describe('Recipient Lists Library', function() { describe('list', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return recipientLists.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); @@ -44,12 +42,10 @@ describe('Recipient Lists Library', function() { describe('get', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return recipientLists.get('test-id', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists/test-id'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -58,9 +54,10 @@ describe('Recipient Lists Library', function() { }); it('should not throw an error if optional 2nd argument is a function (callback)', function() { - client.get.yields(); let cb = sinon.stub(); + client.get.yields(); + return recipientLists.get('test-id', cb).then(() => { expect(cb.callCount).to.equal(1); }); @@ -82,8 +79,6 @@ describe('Recipient Lists Library', function() { describe('create', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - let testList = { id: 'test_list', recipients: [ @@ -100,7 +95,7 @@ describe('Recipient Lists Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('recipient-lists'); expect(client.post.firstCall.args[0].json).to.deep.equal(testList); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -137,8 +132,6 @@ describe('Recipient Lists Library', function() { describe('update', function() { it('should call client put method with the appropriate uri and payload', function() { - client.put.yields(); - const testList = { recipients: [ { @@ -155,7 +148,7 @@ describe('Recipient Lists Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('recipient-lists/' + testId); expect(client.put.firstCall.args[0].json).to.deep.equal(testList); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -191,12 +184,10 @@ describe('Recipient Lists Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return recipientLists.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('recipient-lists/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/relayWebhooks.spec.js b/test/spec/relayWebhooks.spec.js index 0ad19c0..627bbf5 100644 --- a/test/spec/relayWebhooks.spec.js +++ b/test/spec/relayWebhooks.spec.js @@ -22,31 +22,27 @@ describe('Relay Webhooks Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; relayWebhooks = require('../../lib/relayWebhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return relayWebhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('relay-webhooks'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return relayWebhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'relay-webhooks/test'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -57,8 +53,6 @@ describe('Relay Webhooks Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - let webhook = { target: 'test', domain: 'inbound.example.com' @@ -68,7 +62,7 @@ describe('Relay Webhooks Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('relay-webhooks'); expect(client.post.firstCall.args[0].json).to.deep.equal(webhook); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -79,8 +73,6 @@ describe('Relay Webhooks Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { - client.put.yields(); - let webhook = { name: 'New Replies Webhook' }; @@ -89,7 +81,7 @@ describe('Relay Webhooks Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('relay-webhooks/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(webhook); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -104,12 +96,10 @@ describe('Relay Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return relayWebhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('relay-webhooks/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/sendingDomains.spec.js b/test/spec/sendingDomains.spec.js index c330f02..2989651 100644 --- a/test/spec/sendingDomains.spec.js +++ b/test/spec/sendingDomains.spec.js @@ -23,31 +23,27 @@ describe('Sending Domains Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; sendingDomains = require('../../lib/sendingDomains')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return sendingDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return sendingDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains/test'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -58,8 +54,6 @@ describe('Sending Domains Library', function() { describe('create', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var sendingDomain = { domain: 'test' }; @@ -67,7 +61,7 @@ describe('Sending Domains Library', function() { return sendingDomains.create(sendingDomain, callback).then(function() { expect(client.post.firstCall.args[0].uri).to.equal('sending-domains'); expect(client.post.firstCall.args[0].json).to.deep.equal(sendingDomain); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -78,8 +72,6 @@ describe('Sending Domains Library', function() { describe('update', function() { it('should call client put method with the appropriate uri and payload', function() { - client.put.yields(); - var sendingDomain = { tracking_domain: 'click.example1.com' }; @@ -88,7 +80,7 @@ describe('Sending Domains Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('sending-domains/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(_.omit(sendingDomain, 'domain')); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -103,12 +95,10 @@ describe('Sending Domains Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return sendingDomains.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('sending-domains/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -119,8 +109,6 @@ describe('Sending Domains Library', function() { describe('verify', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var options = { dkim_verify: true, spf_verify: true @@ -130,7 +118,7 @@ describe('Sending Domains Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('sending-domains/test/verify'); expect(client.post.firstCall.args[0].json).to.deep.equal(_.omit(options, 'domain')); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/subaccounts.spec.js b/test/spec/subaccounts.spec.js index 8f372e1..87b7cf1 100644 --- a/test/spec/subaccounts.spec.js +++ b/test/spec/subaccounts.spec.js @@ -21,31 +21,27 @@ describe('Subaccounts Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; subaccounts = require('../../lib/subaccounts')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return subaccounts.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return subaccounts.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts/test'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -56,8 +52,6 @@ describe('Subaccounts Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var subaccount = { name: 'test', key_label: 'test', @@ -68,7 +62,7 @@ describe('Subaccounts Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('subaccounts'); expect(client.post.firstCall.args[0].json).to.deep.equal(subaccount); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -79,8 +73,6 @@ describe('Subaccounts Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { - client.put.yields(); - var subaccount = { name: 'Hey Joe! Garage and Parts', status: 'suspended', @@ -91,7 +83,7 @@ describe('Subaccounts Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('subaccounts/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(subaccount); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/suppressionList.spec.js b/test/spec/suppressionList.spec.js index 6c82145..db01e02 100644 --- a/test/spec/suppressionList.spec.js +++ b/test/spec/suppressionList.spec.js @@ -22,31 +22,27 @@ describe('Suppression List Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; suppressionList = require('../../lib/suppressionList')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return suppressionList.list({limit: 5}, callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return suppressionList.get('test@test.com', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -57,15 +53,13 @@ describe('Suppression List Library', function() { describe('upsert', function() { it('should accept a single list entry', function() { - client.put.yields(); - var listEntry = { email: 'test@test.com' }; return suppressionList.upsert(listEntry, callback) .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('suppression-list'); expect(client.put.firstCall.args[0].json.recipients).to.deep.equal([listEntry]); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -89,12 +83,10 @@ describe('Suppression List Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return suppressionList.delete('test@test.com', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index 78827b4..c419a13 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -22,32 +22,28 @@ describe('Templates Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; templates = require('../../lib/templates')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return templates.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('templates'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - var id = 'test'; return templates.get(id, callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('templates/test'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -71,8 +67,6 @@ describe('Templates Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var template = { id: 'test' }; @@ -81,7 +75,7 @@ describe('Templates Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('templates'); expect(client.post.firstCall.args[0].json).to.deep.equal(template); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -92,8 +86,6 @@ describe('Templates Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri and payload', function() { - client.put.yields(); - var id = 'test' , template = { name: 'A new name!' @@ -103,7 +95,7 @@ describe('Templates Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('templates/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(template); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -147,12 +139,10 @@ describe('Templates Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return templates.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('templates/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -163,8 +153,6 @@ describe('Templates Library', function() { describe('preview Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var id = 'test' , options = { substitution_data: { @@ -177,7 +165,7 @@ describe('Templates Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('templates/test/preview'); expect(client.post.firstCall.args[0].json).to.deep.equal(options); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/transmissions.spec.js b/test/spec/transmissions.spec.js index 7f9aa55..fbc5011 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -92,19 +92,17 @@ describe('Transmissions Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; transmissions = require('../../lib/transmissions')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return transmissions.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('transmissions'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -133,12 +131,10 @@ describe('Transmissions Library', function() { describe('find Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return transmissions.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'transmissions/test'}); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -149,8 +145,6 @@ describe('Transmissions Library', function() { describe('send Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var transmission = { campaign_id: 'test-campaign' }; @@ -159,7 +153,7 @@ describe('Transmissions Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('transmissions'); expect(client.post.firstCall.args[0].json).to.deep.equal(transmission); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/webhooks.spec.js b/test/spec/webhooks.spec.js index e528930..b0d82c7 100644 --- a/test/spec/webhooks.spec.js +++ b/test/spec/webhooks.spec.js @@ -23,19 +23,17 @@ describe('Webhooks Library', function() { reject: SparkPost.prototype.reject }; - callback = sinon.stub(); + callback = function() {}; webhooks = require('../../lib/webhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return webhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -53,12 +51,10 @@ describe('Webhooks Library', function() { describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return webhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -80,8 +76,6 @@ describe('Webhooks Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields() - var webhook = { name: 'Example webhook', target: 'http://client.example.com/example-webhook', @@ -92,7 +86,7 @@ describe('Webhooks Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('webhooks'); expect(client.post.firstCall.args[0].json).to.deep.equal(webhook); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -103,8 +97,6 @@ describe('Webhooks Library', function() { describe('update Method', function() { it('should call client put method with the appropriate uri', function() { - client.put.yields(); - var webhook = { name: 'Renamed webhook', events: ['rejection', 'delay'], @@ -115,7 +107,7 @@ describe('Webhooks Library', function() { .then(function() { expect(client.put.firstCall.args[0].uri).to.equal('webhooks/test'); expect(client.put.firstCall.args[0].json).to.deep.equal(webhook); - expect(callback.callCount).to.equal(1); + expect(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -130,12 +122,10 @@ describe('Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - client.delete.yields(); - return webhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('webhooks/test'); - expect(callback.callCount).to.equal(1); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -146,8 +136,6 @@ describe('Webhooks Library', function() { describe('validate Method', function() { it('should call client post method with the appropriate uri and payload', function() { - client.post.yields(); - var options = { message: { msys: {} @@ -158,7 +146,7 @@ describe('Webhooks Library', function() { .then(function() { expect(client.post.firstCall.args[0].uri).to.equal('webhooks/test/validate'); expect(client.post.firstCall.args[0].json).to.deep.equal(options); - expect(callback.callCount).to.equal(1); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -173,12 +161,10 @@ describe('Webhooks Library', function() { describe('getBatchStatus Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return webhooks.getBatchStatus('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test/batch-status'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -200,24 +186,20 @@ describe('Webhooks Library', function() { describe('getDocumentation Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return webhooks.getDocumentation(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/documentation'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('getSamples Method', function() { it('should call client get method with the appropriate uri', function() { - client.get.yields(); - return webhooks.getSamples(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/samples'); - expect(callback.callCount).to.equal(1); + expect(client.get.firstCall.args[1]).to.equal(callback); }); });