Skip to content

Commit 9514241

Browse files
committed
moved callback tests into primary test for each method
1 parent dbdcbd9 commit 9514241

10 files changed

+218
-513
lines changed

test/spec/inboundDomains.spec.js

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ chai.use(require('sinon-chai'));
1111
chai.use(require('chai-as-promised'));
1212

1313
describe('Inbound Domains Library', function() {
14-
let client, inboundDomains;
14+
let client, inboundDomains, callback;
1515

1616
beforeEach(function() {
1717
client = {
@@ -21,45 +21,34 @@ describe('Inbound Domains Library', function() {
2121
reject: SparkPost.prototype.reject
2222
};
2323

24+
callback = sinon.stub();
25+
2426
inboundDomains = require('../../lib/inboundDomains')(client);
2527
});
2628

2729
describe('list Method', function() {
2830
it('should call client get method with the appropriate uri', function() {
29-
return inboundDomains.list()
31+
client.get.yields();
32+
33+
return inboundDomains.list(callback)
3034
.then(function() {
3135
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains'});
36+
expect(callback.callCount).to.equal(1);
3237
});
3338
});
34-
35-
it('should call the callback once', function() {
36-
client.get.yields();
37-
let cb = sinon.stub();
38-
39-
return inboundDomains.list(cb).then(function() {
40-
expect(cb.callCount).to.equal(1);
41-
});
42-
43-
44-
});
4539
});
4640

4741
describe('get Method', function() {
4842
it('should call client get method with the appropriate uri', function() {
49-
return inboundDomains.get('test')
43+
client.get.yields();
44+
45+
return inboundDomains.get('test', callback)
5046
.then(function() {
5147
expect(client.get.firstCall.args[0]).to.deep.equal({uri: 'inbound-domains/test'});
48+
expect(callback.callCount).to.equal(1);
5249
});
5350
});
5451

55-
it('should call the callback once', function() {
56-
client.get.yields();
57-
let cb = sinon.stub();
58-
59-
return inboundDomains.get('test', cb).then(function() {
60-
expect(cb.callCount).to.equal(1);
61-
});
62-
});
6352

6453
it('should throw an error if domain is missing', function() {
6554
return expect(inboundDomains.get()).to.be.rejectedWith('domain is required');
@@ -68,46 +57,33 @@ describe('Inbound Domains Library', function() {
6857

6958
describe('create Method', function() {
7059
it('should call client post method with the appropriate uri and payload', function() {
60+
client.post.yields();
61+
7162
let createOpts = {domain: 'test'};
72-
return inboundDomains.create(createOpts)
63+
return inboundDomains.create(createOpts, callback)
7364
.then(function() {
7465
expect(client.post.firstCall.args[0].uri).to.equal('inbound-domains');
7566
expect(client.post.firstCall.args[0].json).to.deep.equal(createOpts);
67+
expect(callback.callCount).to.equal(1);
7668
});
7769
});
7870

79-
it('should call the callback once', function() {
80-
let createOpts = {domain: 'test'};
81-
client.post.yields();
82-
let cb = sinon.stub();
83-
84-
return inboundDomains.create(createOpts, cb).then(function() {
85-
expect(cb.callCount).to.equal(1);
86-
});
87-
});
88-
8971
it('should throw an error if domain is missing', function() {
9072
return expect(inboundDomains.create()).to.be.rejectedWith('create options are required');
9173
});
9274
});
9375

9476
describe('delete Method', function() {
9577
it('should call client delete method with the appropriate uri', function() {
96-
return inboundDomains.delete('test')
78+
client.delete.yields();
79+
80+
return inboundDomains.delete('test', callback)
9781
.then(function () {
9882
expect(client.delete.firstCall.args[0].uri).to.equal('inbound-domains/test');
83+
expect(callback.callCount).to.equal(1);
9984
});
10085
});
10186

102-
it('should call the callback once', function() {
103-
client.delete.yields();
104-
let cb = sinon.stub();
105-
106-
return inboundDomains.delete('test', cb).then(function() {
107-
expect(cb.callCount).to.equal(1);
108-
});
109-
});
110-
11187
it('should throw an error if domain is missing', function() {
11288
return expect(inboundDomains.delete()).to.be.rejectedWith('domain is required');
11389
});

test/spec/messageEvents.spec.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ chai.use(require('sinon-chai'));
1010
chai.use(require('chai-as-promised'));
1111

1212
describe('Message Events Library', function() {
13-
let client, messageEvents;
13+
let client, messageEvents, callback;
1414

1515
beforeEach(function() {
1616
client = {
1717
get: sinon.stub().resolves({})
1818
};
1919

20+
callback = sinon.stub();
21+
2022
messageEvents = require('../../lib/messageEvents')(client);
2123
});
2224

2325
describe('search Method', function() {
2426
it('should call client get method with the appropriate parameters', function() {
27+
client.get.yields();
28+
2529
var options = {
2630
bounce_classes: '10,50',
2731
campaign_ids: 'test_campaign',
@@ -38,11 +42,12 @@ describe('Message Events Library', function() {
3842
to: '2016-11-14T16:15',
3943
transmission_ids: '65832150921904138'
4044
};
41-
return messageEvents.search(options)
45+
return messageEvents.search(options, callback)
4246
.then(function() {
4347
Object.keys(options).forEach(function(key) {
4448
expect(client.get.firstCall.args[0].qs).to.have.property(key).and.equal(options[key]);
4549
});
50+
expect(callback.callCount).to.equal(1);
4651
});
4752
});
4853

@@ -71,14 +76,5 @@ describe('Message Events Library', function() {
7176
});
7277
});
7378
});
74-
75-
it('should call the callback once', function() {
76-
client.get.yields();
77-
let cb = sinon.stub();
78-
79-
return messageEvents.search({}, cb).then(function() {
80-
expect(cb.callCount).to.equal(1);
81-
});
82-
});
8379
});
8480
});

test/spec/recipientLists.spec.js

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ chai.use(require('sinon-chai'));
1212
chai.use(require('chai-as-promised'));
1313

1414
describe('Recipient Lists Library', function() {
15-
var client, recipientLists;
15+
var client, recipientLists, callback;
1616

1717
beforeEach(function() {
1818
client = {
@@ -23,47 +23,36 @@ describe('Recipient Lists Library', function() {
2323
reject: SparkPost.prototype.reject
2424
};
2525

26+
callback = sinon.stub();
27+
2628
recipientLists = require('../../lib/recipientLists')(client);
2729
});
2830

2931
describe('list', function() {
3032

3133
it('should call client get method with the appropriate uri', function() {
32-
return recipientLists.list()
34+
client.get.yields();
35+
36+
return recipientLists.list(callback)
3337
.then(function() {
3438
expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists');
39+
expect(callback.callCount).to.equal(1);
3540
});
3641
});
37-
38-
it('should call the callback once', function() {
39-
client.get.yields();
40-
let cb = sinon.stub();
41-
42-
return recipientLists.list(cb).then(function() {
43-
expect(cb.callCount).to.equal(1);
44-
});
45-
});
46-
4742
});
4843

4944
describe('get', function() {
5045

5146
it('should call client get method with the appropriate uri', function() {
52-
return recipientLists.get('test-id')
47+
client.get.yields();
48+
49+
return recipientLists.get('test-id', callback)
5350
.then(function() {
5451
expect(client.get.firstCall.args[0].uri).to.equal('recipient-lists/test-id');
52+
expect(callback.callCount).to.equal(1);
5553
});
5654
});
5755

58-
it('should call the callback once', function() {
59-
client.get.yields();
60-
let cb = sinon.stub();
61-
62-
return recipientLists.get('test-id', cb).then(function() {
63-
expect(cb.callCount).to.equal(1);
64-
});
65-
});
66-
6756
it('should throw an error if id is missing', function() {
6857
return expect(recipientLists.get()).to.be.rejectedWith('id is required');
6958
});
@@ -93,6 +82,8 @@ describe('Recipient Lists Library', function() {
9382
describe('create', function() {
9483

9584
it('should call client post method with the appropriate uri and payload', function() {
85+
client.post.yields();
86+
9687
let testList = {
9788
id: 'test_list',
9889
recipients: [
@@ -105,34 +96,14 @@ describe('Recipient Lists Library', function() {
10596
]
10697
};
10798

108-
return recipientLists.create(testList)
99+
return recipientLists.create(testList, callback)
109100
.then(function() {
110101
expect(client.post.firstCall.args[0].uri).to.equal('recipient-lists');
111102
expect(client.post.firstCall.args[0].json).to.deep.equal(testList);
103+
expect(callback.callCount).to.equal(1);
112104
});
113105
});
114106

115-
it('should call the callback once', function() {
116-
client.post.yields();
117-
let cb = sinon.stub();
118-
119-
let testList = {
120-
id: 'test_list',
121-
recipients: [
122-
{
123-
address: {
124-
email: 'test@test.com',
125-
name: 'test'
126-
}
127-
}
128-
]
129-
};
130-
131-
return recipientLists.create(testList, cb).then(function() {
132-
expect(cb.callCount).to.equal(1);
133-
});
134-
});
135-
136107
it('should throw an error if no recipients are provided', function() {
137108
return Promise.all([
138109
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() {
166137
describe('update', function() {
167138

168139
it('should call client put method with the appropriate uri and payload', function() {
140+
client.put.yields();
141+
169142
const testList = {
170143
recipients: [
171144
{
@@ -178,33 +151,14 @@ describe('Recipient Lists Library', function() {
178151
};
179152
const testId = 'test-id';
180153

181-
return recipientLists.update(testId, testList)
154+
return recipientLists.update(testId, testList, callback)
182155
.then(function() {
183156
expect(client.put.firstCall.args[0].uri).to.equal('recipient-lists/' + testId);
184157
expect(client.put.firstCall.args[0].json).to.deep.equal(testList);
158+
expect(callback.callCount).to.equal(1);
185159
});
186160
});
187161

188-
it('should call the callback once', function() {
189-
client.put.yields();
190-
let cb = sinon.stub();
191-
192-
const testList = {
193-
recipients: [
194-
{
195-
address: {
196-
email: 'test@test.com',
197-
name: 'test'
198-
}
199-
}
200-
]
201-
};
202-
203-
return recipientLists.update('test-id', testList, cb).then(function() {
204-
expect(cb.callCount).to.equal(1);
205-
});
206-
});
207-
208162
it('should throw an error if recipient list is missing', function() {
209163
return expect(recipientLists.update('test-id')).to.be.rejectedWith('recipient list is required');
210164
});
@@ -237,22 +191,15 @@ describe('Recipient Lists Library', function() {
237191
describe('delete', function() {
238192

239193
it('should call client delete method with the appropriate uri', function() {
240-
return recipientLists.delete('test')
194+
client.delete.yields();
195+
196+
return recipientLists.delete('test', callback)
241197
.then(function() {
242198
expect(client.delete.firstCall.args[0].uri).to.equal('recipient-lists/test');
199+
expect(callback.callCount).to.equal(1);
243200
});
244201
});
245202

246-
it('should call the callback once', function() {
247-
client.delete.yields();
248-
let cb = sinon.stub();
249-
250-
return recipientLists.delete('test-id', cb).then(function() {
251-
expect(cb.callCount).to.equal(1);
252-
});
253-
});
254-
255-
256203
it('should throw an error if id is missing', function() {
257204
return expect(recipientLists.delete()).to.be.rejectedWith('id is required');
258205
});

0 commit comments

Comments
 (0)