diff --git a/lib/inboundDomains.js b/lib/inboundDomains.js index 9549c0f..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) { @@ -15,7 +14,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 @@ -26,13 +25,13 @@ 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 = { uri: `${api}/${domain}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new inbound domain @@ -43,14 +42,14 @@ 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 = { uri: api , json: createOpts }; - return withCallback(client.post(options, callback), callback); + return client.post(options, callback); }, /** * Delete an existing inbound domain @@ -61,13 +60,13 @@ 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 = { 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..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) { @@ -16,7 +15,7 @@ module.exports = function(client) { const reqOpts = { uri: api }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -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 = { @@ -46,7 +45,7 @@ module.exports = function(client) { qs: options }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, @@ -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 = { @@ -72,7 +71,7 @@ module.exports = function(client) { } }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** @@ -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 = { @@ -103,7 +102,7 @@ module.exports = function(client) { } }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** @@ -117,14 +116,14 @@ 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 = { 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..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) { @@ -15,7 +14,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 @@ -26,14 +25,14 @@ 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 = { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new relay webhook @@ -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 = { @@ -52,7 +51,7 @@ module.exports = function(client) { , json: webhook }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update an existing relay webhook @@ -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 = { @@ -76,7 +75,7 @@ module.exports = function(client) { , json: webhook }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** * Delete an existing relay webhook @@ -87,14 +86,14 @@ 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 = { 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..b28559d 100644 --- a/lib/sendingDomains.js +++ b/lib/sendingDomains.js @@ -1,10 +1,8 @@ 'use strict'; -const withCallback = require('./Promise'); const api = 'sending-domains'; module.exports = function(client) { - return { /** * Lists all sending domains @@ -17,7 +15,7 @@ module.exports = function(client) { uri: api }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -29,14 +27,14 @@ 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 = { uri: `${api}/${domain}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -48,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 = { @@ -56,7 +54,7 @@ module.exports = function(client) { json: createOpts }; - return withCallback(client.post(options), callback); + return client.post(options, callback); }, /** @@ -69,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 = { @@ -81,7 +79,7 @@ module.exports = function(client) { json: updateOpts }; - return withCallback(client.put(options), callback); + return client.put(options, callback); }, /** @@ -93,14 +91,14 @@ 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 = { uri: `${api}/${domain}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); }, /** @@ -113,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 = { @@ -125,7 +123,7 @@ module.exports = function(client) { json: options }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); } }; diff --git a/lib/sparkpost.js b/lib/sparkpost.js index 9f85293..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'); @@ -141,25 +141,29 @@ 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); +}; + +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 ab004e8..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) { @@ -15,7 +14,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 @@ -26,13 +25,13 @@ 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 = { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Create a new subaccount @@ -43,14 +42,14 @@ 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 = { uri: api, json: subaccount }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update existing subaccount by id @@ -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 = { @@ -74,7 +73,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..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) { @@ -19,7 +18,7 @@ module.exports = function(client) { uri: api , qs: parameters }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -31,13 +30,13 @@ 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 = { uri: `${api}/${email}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** @@ -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)) { @@ -62,7 +61,7 @@ module.exports = function(client) { json: { recipients: listEntries } }; - return withCallback(client.put(options, callback), callback); + return client.put(options, callback); }, /** @@ -74,13 +73,13 @@ 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 = { 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..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'); @@ -17,7 +16,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. @@ -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 = { @@ -44,7 +43,7 @@ module.exports = function(client) { , qs: options }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** * Create a new template. @@ -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 = { @@ -63,7 +62,7 @@ module.exports = function(client) { , json: template }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** * Update an existing template. @@ -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 = { @@ -95,7 +94,7 @@ module.exports = function(client) { , qs: options }; - return withCallback(client.put(reqOpts), callback); + return client.put(reqOpts, callback); }, /** * Delete an existing template. @@ -106,13 +105,13 @@ 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 = { 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. @@ -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 = { @@ -146,7 +145,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..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'; /* @@ -10,7 +9,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 +29,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 @@ -42,14 +40,14 @@ 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 = { uri: `${api}/${id}` }; - return withCallback(client.get(options), callback); + return client.get(options, callback); }, /** * Sends a message by creating a new transmission @@ -67,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); @@ -78,7 +76,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..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) { @@ -29,7 +28,7 @@ module.exports = function(client) { reqOpts.qs.timezone = options.timezone; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -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 = { @@ -60,7 +59,7 @@ module.exports = function(client) { reqOpts.qs.timezone = options.timezone; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -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 = { @@ -80,7 +79,7 @@ module.exports = function(client) { json: webhook }; - return withCallback(client.post(options), callback); + return client.post(options, callback); }, /** @@ -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 = { @@ -107,7 +106,7 @@ module.exports = function(client) { delete options.json.id; - return withCallback(client.put(options), callback); + return client.put(options, callback); }, /** @@ -119,14 +118,14 @@ 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 = { uri: `${api}/${id}` }; - return withCallback(client.delete(options), callback); + return client.delete(options, callback); }, /** @@ -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 = { @@ -154,7 +153,7 @@ module.exports = function(client) { } }; - return withCallback(client.post(reqOpts), callback); + return client.post(reqOpts, callback); }, /** @@ -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 = { @@ -185,7 +184,7 @@ module.exports = function(client) { reqOpts.qs.limit = options.limit; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -198,7 +197,7 @@ module.exports = function(client) { const reqOpts = { uri: `${api}/events/documentation` }; - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); }, /** @@ -224,7 +223,7 @@ module.exports = function(client) { reqOpts.qs.events = options.events; } - return withCallback(client.get(reqOpts), callback); + return client.get(reqOpts, callback); } }; }; diff --git a/lib/Promise.js b/lib/withCallback.js similarity index 100% rename from lib/Promise.js rename to lib/withCallback.js diff --git a/test/spec/inboundDomains.spec.js b/test/spec/inboundDomains.spec.js index ce4b3fe..f9eae93 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'); @@ -10,35 +11,42 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + inboundDomains = require('../../lib/inboundDomains')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return inboundDomains.list() + + return inboundDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return inboundDomains.get('test') + return inboundDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains/test'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); + it('should throw an error if domain is missing', function() { return expect(inboundDomains.get()).to.be.rejectedWith('domain is required'); }); @@ -47,10 +55,11 @@ describe('Inbound Domains Library', function() { describe('create Method', function() { it('should call client post method with the appropriate uri and payload', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -61,9 +70,10 @@ describe('Inbound Domains Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return inboundDomains.delete('test') + return inboundDomains.delete('test', callback) .then(function () { expect(client.delete.firstCall.args[0].uri).to.equal('inbound-domains/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/messageEvents.spec.js b/test/spec/messageEvents.spec.js index 5b9fdfc..cfd381b 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'); @@ -11,13 +10,15 @@ 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 = function() {}; + messageEvents = require('../../lib/messageEvents')(client); }); @@ -39,11 +40,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(client.get.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/recipientLists.spec.js b/test/spec/recipientLists.spec.js index e0bee3f..af1b261 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'); @@ -11,36 +12,40 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + recipientLists = require('../../lib/recipientLists')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return recipientLists.list() + return recipientLists.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); - }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return recipientLists.get('test-id') + return recipientLists.get('test-id', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists/test-id'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -50,6 +55,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); }); @@ -83,10 +91,11 @@ 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -135,10 +144,11 @@ 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -174,9 +184,10 @@ describe('Recipient Lists Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - return recipientLists.delete('test') + return recipientLists.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('recipient-lists/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/relayWebhooks.spec.js b/test/spec/relayWebhooks.spec.js index 35aaa35..627bbf5 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'); @@ -10,33 +11,38 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + relayWebhooks = require('../../lib/relayWebhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return relayWebhooks.list() + return relayWebhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('relay-webhooks'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return relayWebhooks.get('test') + return relayWebhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'relay-webhooks/test'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -52,10 +58,11 @@ describe('Relay Webhooks Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -70,10 +77,11 @@ describe('Relay Webhooks Library', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -88,9 +96,10 @@ describe('Relay Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return relayWebhooks.delete('test') + return relayWebhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('relay-webhooks/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/sendingDomains.spec.js b/test/spec/sendingDomains.spec.js index e8d3aa7..2989651 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'); @@ -11,33 +12,38 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + sendingDomains = require('../../lib/sendingDomains')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return sendingDomains.list() + return sendingDomains.list(callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return sendingDomains.get('test') + return sendingDomains.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains/test'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -52,9 +58,10 @@ describe('Sending Domains Library', function() { 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); + expect(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -69,10 +76,11 @@ describe('Sending Domains Library', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -87,9 +95,10 @@ describe('Sending Domains Library', function() { describe('delete', function() { it('should call client delete method with the appropriate uri', function() { - return sendingDomains.delete('test') + return sendingDomains.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('sending-domains/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -105,10 +114,11 @@ describe('Sending Domains Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -120,5 +130,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..87b7cf1 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'); @@ -10,32 +11,37 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), - put: sinon.stub().resolves({}) + put: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + subaccounts = require('../../lib/subaccounts')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return subaccounts.list() + return subaccounts.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return subaccounts.get('test') + return subaccounts.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('subaccounts/test'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -52,10 +58,11 @@ describe('Subaccounts Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -72,10 +79,11 @@ describe('Subaccounts Library', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/suppressionList.spec.js b/test/spec/suppressionList.spec.js index f28be3b..db01e02 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'); @@ -10,33 +11,38 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + suppressionList = require('../../lib/suppressionList')(client); }); describe('list', function() { it('should call client get method with the appropriate uri', function() { - return suppressionList.list({limit: 5}) + return suppressionList.list({limit: 5}, callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('get', function() { it('should call client get method with the appropriate uri', function() { - return suppressionList.get('test@test.com') + return suppressionList.get('test@test.com', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -49,10 +55,11 @@ describe('Suppression List Library', function() { it('should accept a single list entry', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -76,9 +83,10 @@ 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') + return suppressionList.delete('test@test.com', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('suppression-list/test@test.com'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); diff --git a/test/spec/templates.spec.js b/test/spec/templates.spec.js index 82cbb30..c419a13 100644 --- a/test/spec/templates.spec.js +++ b/test/spec/templates.spec.js @@ -1,8 +1,8 @@ 'use strict'; - var _ = require('lodash') , chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); @@ -11,24 +11,28 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + templates = require('../../lib/templates')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return templates.list() + return templates.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('templates'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); @@ -36,9 +40,10 @@ describe('Templates Library', function() { describe('get Method', function() { it('should call client get method with the appropriate uri', function() { 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(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -58,15 +63,6 @@ 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() { @@ -75,10 +71,11 @@ describe('Templates Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -94,10 +91,11 @@ describe('Templates Library', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -115,6 +113,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); }); @@ -138,9 +139,10 @@ describe('Templates Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return templates.delete('test') + return templates.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('templates/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -159,10 +161,11 @@ 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -172,6 +175,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..fbc5011 100644 --- a/test/spec/transmissions.spec.js +++ b/test/spec/transmissions.spec.js @@ -2,13 +2,13 @@ var chai = require('chai') , expect = chai.expect + , SparkPost = require('../../lib/sparkpost') , sinon = require('sinon'); require('sinon-as-promised'); chai.use(require('sinon-chai')); chai.use(require('chai-as-promised')); - var ccTransmission = { recipients: [ { @@ -83,32 +83,29 @@ var ccTransmission = { , expectedCCHeader = '"John" , "Jane" '; describe('Transmissions Library', function() { - var client, transmissions; + var client, transmissions, callback; beforeEach(function() { client = { get: sinon.stub().resolves({}), - post: sinon.stub().resolves({}) + post: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = 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() + return transmissions.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('transmissions'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); - it('should call client get method with the appropriate uri using callback', function(done) { - 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,9 +131,10 @@ describe('Transmissions Library', function() { describe('find Method', function() { it('should call client get method with the appropriate uri', function() { - return transmissions.get('test') + return transmissions.get('test', callback) .then(function() { expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'transmissions/test'}); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -151,10 +149,11 @@ describe('Transmissions Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -181,6 +180,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); }); diff --git a/test/spec/webhooks.spec.js b/test/spec/webhooks.spec.js index 2f79d49..b0d82c7 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'); @@ -11,24 +12,28 @@ 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 = { get: sinon.stub().resolves({}), post: sinon.stub().resolves({}), put: sinon.stub().resolves({}), - delete: sinon.stub().resolves({}) + delete: sinon.stub().resolves({}), + reject: SparkPost.prototype.reject }; + callback = function() {}; + webhooks = require('../../lib/webhooks')(client); }); describe('list Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.list() + return webhooks.list(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -46,9 +51,10 @@ describe('Webhooks Library', function() { describe('get Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.get('test') + return webhooks.get('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -76,10 +82,11 @@ describe('Webhooks Library', function() { 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -96,10 +103,11 @@ describe('Webhooks Library', function() { 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(client.put.firstCall.args[1]).to.equal(callback); }); }); @@ -114,9 +122,10 @@ describe('Webhooks Library', function() { describe('delete Method', function() { it('should call client delete method with the appropriate uri', function() { - return webhooks.delete('test') + return webhooks.delete('test', callback) .then(function() { expect(client.delete.firstCall.args[0].uri).to.equal('webhooks/test'); + expect(client.delete.firstCall.args[1]).to.equal(callback); }); }); @@ -133,10 +142,11 @@ describe('Webhooks Library', function() { } }; - 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(client.post.firstCall.args[1]).to.equal(callback); }); }); @@ -151,9 +161,10 @@ describe('Webhooks Library', function() { describe('getBatchStatus Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getBatchStatus('test') + return webhooks.getBatchStatus('test', callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/test/batch-status'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); @@ -175,18 +186,20 @@ describe('Webhooks Library', function() { describe('getDocumentation Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getDocumentation() + return webhooks.getDocumentation(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/documentation'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); }); }); describe('getSamples Method', function() { it('should call client get method with the appropriate uri', function() { - return webhooks.getSamples() + return webhooks.getSamples(callback) .then(function() { expect(client.get.firstCall.args[0].uri).to.equal('webhooks/events/samples'); + expect(client.get.firstCall.args[1]).to.equal(callback); }); });