@@ -12,7 +12,7 @@ chai.use(require('sinon-chai'));
1212chai . use ( require ( 'chai-as-promised' ) ) ;
1313
1414describe ( '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