@@ -4,12 +4,9 @@ var createApi = require('../src/api')
44var error = require ( '../src/error' )
55
66describe ( 'api: POST /' , function ( ) {
7- var api , queue
8- beforeEach ( function ( ) {
9- queue = {
10- addToQueue : sinon . spy ( )
11- }
12- api = createApi ( queue , {
7+ var api
8+ beforeEach ( function ( ) {
9+ api = createApi ( function ( ) { } , {
1310 token : '1234'
1411 } )
1512 } )
@@ -28,15 +25,17 @@ describe('api: POST /', function () {
2825 } )
2926
3027 it ( 'should return 422 on errorneous responses' , function ( done ) {
31- queue = {
32- addToQueue : function ( ) {
33- return {
34- code : '001' ,
35- error : true
28+ queue = function ( ) {
29+ return {
30+ addToQueue : function ( ) {
31+ return {
32+ code : '001' ,
33+ error : true
34+ }
3635 }
3736 }
3837 }
39- api = createApi ( queue , {
38+ var api = createApi ( queue , {
4039 token : '1234'
4140 } )
4241
@@ -50,8 +49,17 @@ describe('api: POST /', function () {
5049 it ( 'should run the queue with the correct params' , function ( done ) {
5150 var meta = { id : 1 }
5251
53- queue . addToQueue = sinon . stub ( )
54- queue . addToQueue . onCall ( 0 ) . returns ( { id : '1234' } )
52+ var addToQueue = sinon . stub ( )
53+ addToQueue . onCall ( 0 ) . returns ( { id : '1234' } )
54+
55+ var queue = function ( ) {
56+ return {
57+ addToQueue : addToQueue
58+ }
59+ }
60+ var api = createApi ( queue , {
61+ token : '1234'
62+ } )
5563
5664 request ( api )
5765 . post ( '/' )
@@ -61,7 +69,7 @@ describe('api: POST /', function () {
6169 . end ( function ( err , res ) {
6270 if ( err ) return done ( err )
6371
64- if ( ! queue . addToQueue . calledWith ( { url : 'https://google.com' , meta : meta } ) ) {
72+ if ( ! addToQueue . calledWith ( { url : 'https://google.com' , meta : meta } ) ) {
6573 throw new Error ( 'Queue was not called with correct url' )
6674 }
6775
0 commit comments