@@ -50,104 +50,60 @@ describe('httpRequest', () => {
50
50
it ( 'should do /hello' , done => {
51
51
httpRequest ( {
52
52
url : httpRequestServer + '/hello' ,
53
- } ) . then (
54
- function ( httpResponse ) {
55
- expect ( httpResponse . status ) . toBe ( 200 ) ;
56
- expect ( httpResponse . buffer ) . toEqual ( new Buffer ( '{"response":"OK"}' ) ) ;
57
- expect ( httpResponse . text ) . toEqual ( '{"response":"OK"}' ) ;
58
- expect ( httpResponse . data . response ) . toEqual ( 'OK' ) ;
59
- done ( ) ;
60
- } ,
61
- function ( ) {
62
- fail ( 'should not fail' ) ;
63
- done ( ) ;
64
- }
65
- ) ;
66
- } ) ;
67
-
68
- it ( 'should do /hello with callback and promises' , done => {
69
- let calls = 0 ;
70
- httpRequest ( {
71
- url : httpRequestServer + '/hello' ,
72
- success : function ( ) {
73
- calls ++ ;
74
- } ,
75
- error : function ( ) {
76
- calls ++ ;
77
- } ,
78
- } ) . then (
79
- function ( httpResponse ) {
80
- expect ( calls ) . toBe ( 1 ) ;
81
- expect ( httpResponse . status ) . toBe ( 200 ) ;
82
- expect ( httpResponse . buffer ) . toEqual ( new Buffer ( '{"response":"OK"}' ) ) ;
83
- expect ( httpResponse . text ) . toEqual ( '{"response":"OK"}' ) ;
84
- expect ( httpResponse . data . response ) . toEqual ( 'OK' ) ;
85
- done ( ) ;
86
- } ,
87
- function ( ) {
88
- fail ( 'should not fail' ) ;
89
- done ( ) ;
90
- }
91
- ) ;
53
+ } ) . then ( function ( httpResponse ) {
54
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
55
+ expect ( httpResponse . buffer ) . toEqual ( new Buffer ( '{"response":"OK"}' ) ) ;
56
+ expect ( httpResponse . text ) . toEqual ( '{"response":"OK"}' ) ;
57
+ expect ( httpResponse . data . response ) . toEqual ( 'OK' ) ;
58
+ done ( ) ;
59
+ } , done . fail ) ;
92
60
} ) ;
93
61
94
62
it ( 'should do not follow redirects by default' , done => {
95
63
httpRequest ( {
96
64
url : httpRequestServer + '/301' ,
97
- } ) . then (
98
- function ( httpResponse ) {
99
- expect ( httpResponse . status ) . toBe ( 301 ) ;
100
- done ( ) ;
101
- } ,
102
- function ( ) {
103
- fail ( 'should not fail' ) ;
104
- done ( ) ;
105
- }
106
- ) ;
65
+ } ) . then ( function ( httpResponse ) {
66
+ expect ( httpResponse . status ) . toBe ( 301 ) ;
67
+ done ( ) ;
68
+ } , done . fail ) ;
107
69
} ) ;
108
70
109
71
it ( 'should follow redirects when set' , done => {
110
72
httpRequest ( {
111
73
url : httpRequestServer + '/301' ,
112
74
followRedirects : true ,
113
- } ) . then (
114
- function ( httpResponse ) {
115
- expect ( httpResponse . status ) . toBe ( 200 ) ;
116
- expect ( httpResponse . buffer ) . toEqual ( new Buffer ( '{"response":"OK"}' ) ) ;
117
- expect ( httpResponse . text ) . toEqual ( '{"response":"OK"}' ) ;
118
- expect ( httpResponse . data . response ) . toEqual ( 'OK' ) ;
119
- done ( ) ;
120
- } ,
121
- function ( ) {
122
- fail ( 'should not fail' ) ;
123
- done ( ) ;
124
- }
125
- ) ;
75
+ } ) . then ( function ( httpResponse ) {
76
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
77
+ expect ( httpResponse . buffer ) . toEqual ( new Buffer ( '{"response":"OK"}' ) ) ;
78
+ expect ( httpResponse . text ) . toEqual ( '{"response":"OK"}' ) ;
79
+ expect ( httpResponse . data . response ) . toEqual ( 'OK' ) ;
80
+ done ( ) ;
81
+ } , done . fail ) ;
126
82
} ) ;
127
83
128
84
it ( 'should fail on 404' , done => {
129
85
let calls = 0 ;
130
86
httpRequest ( {
131
87
url : httpRequestServer + '/404' ,
132
- success : function ( ) {
88
+ } ) . then (
89
+ function ( ) {
133
90
calls ++ ;
134
91
fail ( 'should not succeed' ) ;
135
92
done ( ) ;
136
93
} ,
137
- error : function ( httpResponse ) {
94
+ function ( httpResponse ) {
138
95
calls ++ ;
139
96
expect ( calls ) . toBe ( 1 ) ;
140
97
expect ( httpResponse . status ) . toBe ( 404 ) ;
141
98
expect ( httpResponse . buffer ) . toEqual ( new Buffer ( 'NO' ) ) ;
142
99
expect ( httpResponse . text ) . toEqual ( 'NO' ) ;
143
100
expect ( httpResponse . data ) . toBe ( undefined ) ;
144
101
done ( ) ;
145
- } ,
146
- } ) ;
102
+ }
103
+ ) ;
147
104
} ) ;
148
105
149
106
it ( 'should post on echo' , done => {
150
- let calls = 0 ;
151
107
httpRequest ( {
152
108
method : 'POST' ,
153
109
url : httpRequestServer + '/echo' ,
@@ -157,15 +113,8 @@ describe('httpRequest', () => {
157
113
headers : {
158
114
'Content-Type' : 'application/json' ,
159
115
} ,
160
- success : function ( ) {
161
- calls ++ ;
162
- } ,
163
- error : function ( ) {
164
- calls ++ ;
165
- } ,
166
116
} ) . then (
167
117
function ( httpResponse ) {
168
- expect ( calls ) . toBe ( 1 ) ;
169
118
expect ( httpResponse . status ) . toBe ( 200 ) ;
170
119
expect ( httpResponse . data ) . toEqual ( { foo : 'bar' } ) ;
171
120
done ( ) ;
@@ -220,15 +169,10 @@ describe('httpRequest', () => {
220
169
it ( 'should fail gracefully' , done => {
221
170
httpRequest ( {
222
171
url : 'http://not a good url' ,
223
- success : function ( ) {
224
- fail ( 'should not succeed' ) ;
225
- done ( ) ;
226
- } ,
227
- error : function ( error ) {
228
- expect ( error ) . not . toBeUndefined ( ) ;
229
- expect ( error ) . not . toBeNull ( ) ;
230
- done ( ) ;
231
- } ,
172
+ } ) . then ( done . fail , function ( error ) {
173
+ expect ( error ) . not . toBeUndefined ( ) ;
174
+ expect ( error ) . not . toBeNull ( ) ;
175
+ done ( ) ;
232
176
} ) ;
233
177
} ) ;
234
178
0 commit comments