@@ -4,7 +4,7 @@ var nock = require('nock');
44var Api = require ( './../../' ) . Api ;
55
66
7- describe ( 'Api. request() method' , function ( ) {
7+ describe ( 'Api.request() method' , function ( ) {
88
99 it ( 'should resolve returned promise with data if everything went ok' , function ( done ) {
1010 var url = 'http://foobar:8080' ,
@@ -31,6 +31,97 @@ describe('Api. request() method', function() {
3131 expect ( promise ) . to . eventually . deep . equal ( { 'got' : 'ok' } ) . and . notify ( done ) ;
3232 } ) ;
3333
34+
35+ it ( 'should resolve returned promise with data if everything went ok (empty fields)' , function ( done ) {
36+ var url = 'http://foobar:8080' ,
37+ path = '/test' ,
38+ params = {
39+ 'foo' : 1 ,
40+ 'bar' : 'baz'
41+ } ,
42+ fields = [ ] ,
43+ method = 'GET' ;
44+
45+ nock ( url )
46+ . get ( '/attask/api' + path + '?foo=1&bar=baz' )
47+ . reply ( 200 , {
48+ data : {
49+ 'got' : 'ok'
50+ }
51+ } ) ;
52+
53+ var api = new Api ( { url : url } ) ;
54+ var promise = api . request ( path , params , fields , method ) ;
55+ expect ( promise ) . to . eventually . deep . equal ( { 'got' : 'ok' } ) . and . notify ( done ) ;
56+ } ) ;
57+
58+
59+ it ( 'should resolve returned promise with data if everything went ok (without fields)' , function ( done ) {
60+ var url = 'http://foobar:8080' ,
61+ path = '/test' ,
62+ params = {
63+ 'foo' : 1 ,
64+ 'bar' : 'baz'
65+ } ,
66+ method = 'GET' ;
67+
68+ nock ( url )
69+ . get ( '/attask/api' + path + '?foo=1&bar=baz' )
70+ . reply ( 200 , {
71+ data : {
72+ 'got' : 'ok'
73+ }
74+ } ) ;
75+
76+ var api = new Api ( { url : url } ) ;
77+ var promise = api . request ( path , params , null , method ) ;
78+ expect ( promise ) . to . eventually . deep . equal ( { 'got' : 'ok' } ) . and . notify ( done ) ;
79+ } ) ;
80+
81+
82+ it ( 'should resolve returned promise with data if everything went ok (without fields and params)' , function ( done ) {
83+ var url = 'http://foobar:8080' ,
84+ path = '/test' ,
85+ method = 'GET' ;
86+
87+ nock ( url )
88+ . get ( '/attask/api' + path )
89+ . reply ( 200 , {
90+ data : {
91+ 'got' : 'ok'
92+ }
93+ } ) ;
94+
95+ var api = new Api ( { url : url } ) ;
96+ var promise = api . request ( path , null , null , method ) ;
97+ expect ( promise ) . to . eventually . deep . equal ( { 'got' : 'ok' } ) . and . notify ( done ) ;
98+ } ) ;
99+
100+
101+ it ( 'should resolve returned promise with data if everything went ok (path without leading /)' , function ( done ) {
102+ var url = 'http://foobar:8080' ,
103+ path = 'test' ,
104+ params = {
105+ 'foo' : 1 ,
106+ 'bar' : 'baz'
107+ } ,
108+ fields = [ ] ,
109+ method = 'GET' ;
110+
111+ nock ( url )
112+ . get ( '/attask/api/' + path + '?foo=1&bar=baz' )
113+ . reply ( 200 , {
114+ data : {
115+ 'got' : 'ok'
116+ }
117+ } ) ;
118+
119+ var api = new Api ( { url : url } ) ;
120+ var promise = api . request ( path , params , fields , method ) ;
121+ expect ( promise ) . to . eventually . deep . equal ( { 'got' : 'ok' } ) . and . notify ( done ) ;
122+ } ) ;
123+
124+
34125 it ( 'should reject returned promise with error data on error' , function ( done ) {
35126 var url = 'http://foobar:8080' ,
36127 path = '/test' ,
0 commit comments