Skip to content

Commit c5af38e

Browse files
committed
modified tests to check that the callback is passed through
1 parent 9514241 commit c5af38e

10 files changed

+59
-151
lines changed

test/spec/inboundDomains.spec.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,28 @@ describe('Inbound Domains Library', function() {
2121
reject: SparkPost.prototype.reject
2222
};
2323

24-
callback = sinon.stub();
24+
callback = function() {};
2525

2626
inboundDomains = require('../../lib/inboundDomains')(client);
2727
});
2828

2929
describe('list Method', function() {
3030
it('should call client get method with the appropriate uri', function() {
31-
client.get.yields();
3231

3332
return inboundDomains.list(callback)
3433
.then(function() {
3534
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'});
36-
expect(callback.callCount).to.equal(1);
35+
expect(client.get.firstCall.args[1]).to.equal(callback);
3736
});
3837
});
3938
});
4039

4140
describe('get Method', function() {
4241
it('should call client get method with the appropriate uri', function() {
43-
client.get.yields();
44-
4542
return inboundDomains.get('test', callback)
4643
.then(function() {
4744
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains/test'});
48-
expect(callback.callCount).to.equal(1);
45+
expect(client.get.firstCall.args[1]).to.equal(callback);
4946
});
5047
});
5148

@@ -57,14 +54,12 @@ describe('Inbound Domains Library', function() {
5754

5855
describe('create Method', function() {
5956
it('should call client post method with the appropriate uri and payload', function() {
60-
client.post.yields();
61-
6257
let createOpts = {domain: 'test'};
6358
return inboundDomains.create(createOpts, callback)
6459
.then(function() {
6560
expect(client.post.firstCall.args[0].uri).to.equal('inbound-domains');
6661
expect(client.post.firstCall.args[0].json).to.deep.equal(createOpts);
67-
expect(callback.callCount).to.equal(1);
62+
expect(client.post.firstCall.args[1]).to.equal(callback);
6863
});
6964
});
7065

@@ -75,12 +70,10 @@ describe('Inbound Domains Library', function() {
7570

7671
describe('delete Method', function() {
7772
it('should call client delete method with the appropriate uri', function() {
78-
client.delete.yields();
79-
8073
return inboundDomains.delete('test', callback)
8174
.then(function () {
8275
expect(client.delete.firstCall.args[0].uri).to.equal('inbound-domains/test');
83-
expect(callback.callCount).to.equal(1);
76+
expect(client.delete.firstCall.args[1]).to.equal(callback);
8477
});
8578
});
8679

test/spec/messageEvents.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ describe('Message Events Library', function() {
1717
get: sinon.stub().resolves({})
1818
};
1919

20-
callback = sinon.stub();
20+
callback = function() {};
2121

2222
messageEvents = require('../../lib/messageEvents')(client);
2323
});
2424

2525
describe('search Method', function() {
2626
it('should call client get method with the appropriate parameters', function() {
27-
client.get.yields();
28-
2927
var options = {
3028
bounce_classes: '10,50',
3129
campaign_ids: 'test_campaign',
@@ -47,7 +45,7 @@ describe('Message Events Library', function() {
4745
Object.keys(options).forEach(function(key) {
4846
expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]);
4947
});
50-
expect(callback.callCount).to.equal(1);
48+
expect(client.get.firstCall.args[1]).to.equal(callback);
5149
});
5250
});
5351

test/spec/recipientLists.spec.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,29 @@ describe('Recipient Lists Library', function() {
2323
reject: SparkPost.prototype.reject
2424
};
2525

26-
callback = sinon.stub();
26+
callback = function() {};
2727

2828
recipientLists = require('../../lib/recipientLists')(client);
2929
});
3030

3131
describe('list', function() {
3232

3333
it('should call client get method with the appropriate uri', function() {
34-
client.get.yields();
35-
3634
return recipientLists.list(callback)
3735
.then(function() {
3836
expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists');
39-
expect(callback.callCount).to.equal(1);
37+
expect(client.get.firstCall.args[1]).to.equal(callback);
4038
});
4139
});
4240
});
4341

4442
describe('get', function() {
4543

4644
it('should call client get method with the appropriate uri', function() {
47-
client.get.yields();
48-
4945
return recipientLists.get('test-id', callback)
5046
.then(function() {
5147
expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists/test-id');
52-
expect(callback.callCount).to.equal(1);
48+
expect(client.get.firstCall.args[1]).to.equal(callback);
5349
});
5450
});
5551

@@ -58,9 +54,10 @@ describe('Recipient Lists Library', function() {
5854
});
5955

6056
it('should not throw an error if optional 2nd argument is a function (callback)', function() {
61-
client.get.yields();
6257
let cb = sinon.stub();
6358

59+
client.get.yields();
60+
6461
return recipientLists.get('test-id', cb).then(() => {
6562
expect(cb.callCount).to.equal(1);
6663
});
@@ -82,8 +79,6 @@ describe('Recipient Lists Library', function() {
8279
describe('create', function() {
8380

8481
it('should call client post method with the appropriate uri and payload', function() {
85-
client.post.yields();
86-
8782
let testList = {
8883
id: 'test_list',
8984
recipients: [
@@ -100,7 +95,7 @@ describe('Recipient Lists Library', function() {
10095
.then(function() {
10196
expect(client.post.firstCall.args[0].uri).to.equal('recipient-lists');
10297
expect(client.post.firstCall.args[0].json).to.deep.equal(testList);
103-
expect(callback.callCount).to.equal(1);
98+
expect(client.post.firstCall.args[1]).to.equal(callback);
10499
});
105100
});
106101

@@ -137,8 +132,6 @@ describe('Recipient Lists Library', function() {
137132
describe('update', function() {
138133

139134
it('should call client put method with the appropriate uri and payload', function() {
140-
client.put.yields();
141-
142135
const testList = {
143136
recipients: [
144137
{
@@ -155,7 +148,7 @@ describe('Recipient Lists Library', function() {
155148
.then(function() {
156149
expect(client.put.firstCall.args[0].uri).to.equal('recipient-lists/' + testId);
157150
expect(client.put.firstCall.args[0].json).to.deep.equal(testList);
158-
expect(callback.callCount).to.equal(1);
151+
expect(client.put.firstCall.args[1]).to.equal(callback);
159152
});
160153
});
161154

@@ -191,12 +184,10 @@ describe('Recipient Lists Library', function() {
191184
describe('delete', function() {
192185

193186
it('should call client delete method with the appropriate uri', function() {
194-
client.delete.yields();
195-
196187
return recipientLists.delete('test', callback)
197188
.then(function() {
198189
expect(client.delete.firstCall.args[0].uri).to.equal('recipient-lists/test');
199-
expect(callback.callCount).to.equal(1);
190+
expect(client.delete.firstCall.args[1]).to.equal(callback);
200191
});
201192
});
202193

test/spec/relayWebhooks.spec.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,27 @@ describe('Relay Webhooks Library', function() {
2222
reject: SparkPost.prototype.reject
2323
};
2424

25-
callback = sinon.stub();
25+
callback = function() {};
2626

2727
relayWebhooks = require('../../lib/relayWebhooks')(client);
2828
});
2929

3030
describe('list Method', function() {
3131
it('should call client get method with the appropriate uri', function() {
32-
client.get.yields();
33-
3432
return relayWebhooks.list(callback)
3533
.then(function() {
3634
expect(client.get.firstCall.args[0].uri).to.equal('relay-webhooks');
37-
expect(callback.callCount).to.equal(1);
35+
expect(client.get.firstCall.args[1]).to.equal(callback);
3836
});
3937
});
4038
});
4139

4240
describe('get Method', function() {
4341
it('should call client get method with the appropriate uri', function() {
44-
client.get.yields();
45-
4642
return relayWebhooks.get('test', callback)
4743
.then(function() {
4844
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'relay-webhooks/test'});
49-
expect(callback.callCount).to.equal(1);
45+
expect(client.get.firstCall.args[1]).to.equal(callback);
5046
});
5147
});
5248

@@ -57,8 +53,6 @@ describe('Relay Webhooks Library', function() {
5753

5854
describe('create Method', function() {
5955
it('should call client post method with the appropriate uri and payload', function() {
60-
client.post.yields();
61-
6256
let webhook = {
6357
target: 'test',
6458
domain: 'inbound.example.com'
@@ -68,7 +62,7 @@ describe('Relay Webhooks Library', function() {
6862
.then(function() {
6963
expect(client.post.firstCall.args[0].uri).to.equal('relay-webhooks');
7064
expect(client.post.firstCall.args[0].json).to.deep.equal(webhook);
71-
expect(callback.callCount).to.equal(1);
65+
expect(client.post.firstCall.args[1]).to.equal(callback);
7266
});
7367
});
7468

@@ -79,8 +73,6 @@ describe('Relay Webhooks Library', function() {
7973

8074
describe('update Method', function() {
8175
it('should call client put method with the appropriate uri and payload', function() {
82-
client.put.yields();
83-
8476
let webhook = {
8577
name: 'New Replies Webhook'
8678
};
@@ -89,7 +81,7 @@ describe('Relay Webhooks Library', function() {
8981
.then(function() {
9082
expect(client.put.firstCall.args[0].uri).to.equal('relay-webhooks/test');
9183
expect(client.put.firstCall.args[0].json).to.deep.equal(webhook);
92-
expect(callback.callCount).to.equal(1);
84+
expect(client.put.firstCall.args[1]).to.equal(callback);
9385
});
9486
});
9587

@@ -104,12 +96,10 @@ describe('Relay Webhooks Library', function() {
10496

10597
describe('delete Method', function() {
10698
it('should call client delete method with the appropriate uri', function() {
107-
client.delete.yields();
108-
10999
return relayWebhooks.delete('test', callback)
110100
.then(function() {
111101
expect(client.delete.firstCall.args[0].uri).to.equal('relay-webhooks/test');
112-
expect(callback.callCount).to.equal(1);
102+
expect(client.delete.firstCall.args[1]).to.equal(callback);
113103
});
114104
});
115105

test/spec/sendingDomains.spec.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,27 @@ describe('Sending Domains Library', function() {
2323
reject: SparkPost.prototype.reject
2424
};
2525

26-
callback = sinon.stub();
26+
callback = function() {};
2727

2828
sendingDomains = require('../../lib/sendingDomains')(client);
2929
});
3030

3131
describe('list', function() {
3232
it('should call client get method with the appropriate uri', function() {
33-
client.get.yields();
34-
3533
return sendingDomains.list(callback)
3634
.then(function() {
3735
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains'});
38-
expect(callback.callCount).to.equal(1);
36+
expect(client.get.firstCall.args[1]).to.equal(callback);
3937
});
4038
});
4139
});
4240

4341
describe('get', function() {
4442
it('should call client get method with the appropriate uri', function() {
45-
client.get.yields();
46-
4743
return sendingDomains.get('test', callback)
4844
.then(function() {
4945
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'sending-domains/test'});
50-
expect(callback.callCount).to.equal(1);
46+
expect(client.get.firstCall.args[1]).to.equal(callback);
5147
});
5248
});
5349

@@ -58,16 +54,14 @@ describe('Sending Domains Library', function() {
5854

5955
describe('create', function() {
6056
it('should call client post method with the appropriate uri and payload', function() {
61-
client.post.yields();
62-
6357
var sendingDomain = {
6458
domain: 'test'
6559
};
6660

6761
return sendingDomains.create(sendingDomain, callback).then(function() {
6862
expect(client.post.firstCall.args[0].uri).to.equal('sending-domains');
6963
expect(client.post.firstCall.args[0].json).to.deep.equal(sendingDomain);
70-
expect(callback.callCount).to.equal(1);
64+
expect(client.post.firstCall.args[1]).to.equal(callback);
7165
});
7266
});
7367

@@ -78,8 +72,6 @@ describe('Sending Domains Library', function() {
7872

7973
describe('update', function() {
8074
it('should call client put method with the appropriate uri and payload', function() {
81-
client.put.yields();
82-
8375
var sendingDomain = {
8476
tracking_domain: 'click.example1.com'
8577
};
@@ -88,7 +80,7 @@ describe('Sending Domains Library', function() {
8880
.then(function() {
8981
expect(client.put.firstCall.args[0].uri).to.equal('sending-domains/test');
9082
expect(client.put.firstCall.args[0].json).to.deep.equal(_.omit(sendingDomain, 'domain'));
91-
expect(callback.callCount).to.equal(1);
83+
expect(client.put.firstCall.args[1]).to.equal(callback);
9284
});
9385
});
9486

@@ -103,12 +95,10 @@ describe('Sending Domains Library', function() {
10395

10496
describe('delete', function() {
10597
it('should call client delete method with the appropriate uri', function() {
106-
client.delete.yields();
107-
10898
return sendingDomains.delete('test', callback)
10999
.then(function() {
110100
expect(client.delete.firstCall.args[0].uri).to.equal('sending-domains/test');
111-
expect(callback.callCount).to.equal(1);
101+
expect(client.delete.firstCall.args[1]).to.equal(callback);
112102
});
113103
});
114104

@@ -119,8 +109,6 @@ describe('Sending Domains Library', function() {
119109

120110
describe('verify', function() {
121111
it('should call client post method with the appropriate uri and payload', function() {
122-
client.post.yields();
123-
124112
var options = {
125113
dkim_verify: true,
126114
spf_verify: true
@@ -130,7 +118,7 @@ describe('Sending Domains Library', function() {
130118
.then(function() {
131119
expect(client.post.firstCall.args[0].uri).to.equal('sending-domains/test/verify');
132120
expect(client.post.firstCall.args[0].json).to.deep.equal(_.omit(options, 'domain'));
133-
expect(callback.callCount).to.equal(1);
121+
expect(client.post.firstCall.args[1]).to.equal(callback);
134122
});
135123
});
136124

0 commit comments

Comments
 (0)