@@ -28,7 +28,7 @@ describe('Rest Tests', function () {
28
28
29
29
it ( 'constructs' , ( ) => {
30
30
this . timeout ( 1000 ) ;
31
-
31
+
32
32
let rest : restm . RestClient = new restm . RestClient ( 'typed-test-client-tests' ) ;
33
33
assert ( rest , 'rest client should not be null' ) ;
34
34
} )
@@ -38,77 +38,77 @@ describe('Rest Tests', function () {
38
38
39
39
let restRes : restm . IRestResponse < HttpBinData > = await _rest . get < HttpBinData > ( 'https://httpbin.org/get' ) ;
40
40
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
41
- assert ( restRes . result . url === 'https://httpbin.org/get' ) ;
41
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/get' ) ;
42
42
} ) ;
43
43
44
44
it ( 'gets a resource with baseUrl' , async ( ) => {
45
45
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . get < HttpBinData > ( 'get' ) ;
46
46
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
47
- assert ( restRes . result . url === 'https://httpbin.org/get' ) ;
47
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/get' ) ;
48
48
} ) ;
49
-
49
+
50
50
it ( 'creates a resource' , async ( ) => {
51
51
let res : any = { name : 'foo' } ;
52
52
let restRes : restm . IRestResponse < HttpBinData > = await _rest . create < HttpBinData > ( 'https://httpbin.org/post' , res ) ;
53
53
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
54
- assert ( restRes . result . url === 'https://httpbin.org/post' ) ;
55
- assert ( restRes . result . json . name === 'foo' ) ;
54
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/post' ) ;
55
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
56
56
} ) ;
57
-
57
+
58
58
it ( 'creates a resource with a baseUrl' , async ( ) => {
59
59
let res : any = { name : 'foo' } ;
60
60
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . create < HttpBinData > ( 'post' , res ) ;
61
61
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
62
- assert ( restRes . result . url === 'https://httpbin.org/post' ) ;
63
- assert ( restRes . result . json . name === 'foo' ) ;
64
- } ) ;
65
-
62
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/post' ) ;
63
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
64
+ } ) ;
65
+
66
66
it ( 'replaces a resource' , async ( ) => {
67
67
this . timeout ( 3000 ) ;
68
68
69
69
let res : any = { name : 'foo' } ;
70
70
let restRes : restm . IRestResponse < HttpBinData > = await _rest . replace < HttpBinData > ( 'https://httpbin.org/put' , res ) ;
71
71
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
72
- assert ( restRes . result . url === 'https://httpbin.org/put' ) ;
73
- assert ( restRes . result . json . name === 'foo' ) ;
72
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/put' ) ;
73
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
74
74
} ) ;
75
-
75
+
76
76
it ( 'replaces a resource with a baseUrl' , async ( ) => {
77
77
let res : any = { name : 'foo' } ;
78
78
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . replace < HttpBinData > ( 'put' , res ) ;
79
79
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
80
- assert ( restRes . result . url === 'https://httpbin.org/put' ) ;
81
- assert ( restRes . result . json . name === 'foo' ) ;
80
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/put' ) ;
81
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
82
82
} ) ;
83
-
83
+
84
84
it ( 'updates a resource' , async ( ) => {
85
85
let res : any = { name : 'foo' } ;
86
86
let restRes : restm . IRestResponse < HttpBinData > = await _rest . update < HttpBinData > ( 'https://httpbin.org/patch' , res ) ;
87
87
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
88
- assert ( restRes . result . url === 'https://httpbin.org/patch' ) ;
89
- assert ( restRes . result . json . name === 'foo' ) ;
88
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/patch' ) ;
89
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
90
90
} ) ;
91
-
91
+
92
92
it ( 'updates a resource with a baseUrl' , async ( ) => {
93
93
let res : any = { name : 'foo' } ;
94
94
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . update < HttpBinData > ( 'patch' , res ) ;
95
95
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
96
- assert ( restRes . result . url === 'https://httpbin.org/patch' ) ;
97
- assert ( restRes . result . json . name === 'foo' ) ;
98
- } ) ;
96
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/patch' ) ;
97
+ assert ( restRes . result && restRes . result . json . name === 'foo' ) ;
98
+ } ) ;
99
99
100
100
it ( 'deletes a resource' , async ( ) => {
101
101
let restRes : restm . IRestResponse < HttpBinData > = await _rest . del < HttpBinData > ( 'https://httpbin.org/delete' ) ;
102
102
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
103
- assert ( restRes . result . url === 'https://httpbin.org/delete' ) ;
103
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/delete' ) ;
104
104
} ) ;
105
105
106
106
it ( 'deletes a resource with a baseUrl' , async ( ) => {
107
107
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . del < HttpBinData > ( 'delete' ) ;
108
108
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
109
- assert ( restRes . result . url === 'https://httpbin.org/delete' ) ;
110
- } ) ;
111
-
109
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/delete' ) ;
110
+ } ) ;
111
+
112
112
it ( 'does an options request' , async ( ) => {
113
113
let restRes : restm . IRestResponse < HttpBinData > = await _rest . options < HttpBinData > ( 'https://httpbin.org' ) ;
114
114
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
@@ -117,7 +117,7 @@ describe('Rest Tests', function () {
117
117
it ( 'does an options request with baseUrl' , async ( ) => {
118
118
let restRes : restm . IRestResponse < HttpBinData > = await _restBin . options < HttpBinData > ( '' ) ;
119
119
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
120
- } ) ;
120
+ } ) ;
121
121
122
122
//----------------------------------------------
123
123
// Get Error Cases
@@ -132,9 +132,9 @@ describe('Rest Tests', function () {
132
132
133
133
try {
134
134
let restRes : restm . IRestResponse < HttpBinData > = await _rest . get < HttpBinData > ( 'https://httpbin.org/status/404' ) ;
135
-
135
+
136
136
assert ( restRes . statusCode == 404 , "statusCode should be 404" ) ;
137
- assert ( restRes . result == null , "object should be null" ) ;
137
+ assert ( restRes . result === null , "object should be null" ) ;
138
138
}
139
139
catch ( err ) {
140
140
assert ( false , "should not throw" ) ;
@@ -145,7 +145,7 @@ describe('Rest Tests', function () {
145
145
// Unauthorized (401)
146
146
// should throw and attach statusCode to the Error object
147
147
// err.message is message proerty of resourceful error object or if not supplied, a generic error message
148
- //
148
+ //
149
149
it ( 'gets and handles unauthorized (401)' , async ( ) => {
150
150
try {
151
151
let restRes : restm . IRestResponse < HttpBinData > = await _rest . get < HttpBinData > ( 'https://httpbin.org/status/401' ) ;
@@ -155,13 +155,13 @@ describe('Rest Tests', function () {
155
155
assert ( err [ 'statusCode' ] == 401 , "statusCode should be 401" ) ;
156
156
assert ( err . message && err . message . length > 0 , "should have error message" ) ;
157
157
}
158
- } ) ;
159
-
158
+ } ) ;
159
+
160
160
//
161
161
// Internal Server Error
162
162
// should throw and attach statusCode to the Error object
163
163
// err.message is message proerty of resourceful error object or if not supplied, a generic error message
164
- //
164
+ //
165
165
it ( 'gets and handles a server error (500)' , async ( ) => {
166
166
try {
167
167
let restRes : restm . IRestResponse < HttpBinData > = await _rest . get < HttpBinData > ( 'https://httpbin.org/status/500' ) ;
@@ -187,7 +187,7 @@ describe('Rest Tests', function () {
187
187
188
188
// Assert
189
189
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
190
- assert ( restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
190
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
191
191
} ) ;
192
192
193
193
it ( 'maintains the path from the base url with no slashes' , async ( ) => {
@@ -199,7 +199,7 @@ describe('Rest Tests', function () {
199
199
200
200
// Assert
201
201
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
202
- assert ( restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
202
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
203
203
} ) ;
204
204
205
205
it ( 'maintains the path from the base url with double slashes' , async ( ) => {
@@ -211,7 +211,7 @@ describe('Rest Tests', function () {
211
211
212
212
// Assert
213
213
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
214
- assert ( restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
214
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/anythingextra' ) ;
215
215
} ) ;
216
216
217
217
it ( 'maintains the path from the base url with multiple parts' , async ( ) => {
@@ -223,7 +223,7 @@ describe('Rest Tests', function () {
223
223
224
224
// Assert
225
225
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
226
- assert ( restRes . result . url === 'https://httpbin.org/anything/extrapart/anythingextra' ) ;
226
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/extrapart/anythingextra' ) ;
227
227
} ) ;
228
228
229
229
it ( 'maintains the path from the base url where request has multiple parts' , async ( ) => {
@@ -235,7 +235,7 @@ describe('Rest Tests', function () {
235
235
236
236
// Assert
237
237
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
238
- assert ( restRes . result . url === 'https://httpbin.org/anything/anythingextra/moreparts' ) ;
238
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/anythingextra/moreparts' ) ;
239
239
} ) ;
240
240
241
241
it ( 'maintains the path from the base url where both have multiple parts' , async ( ) => {
@@ -247,7 +247,7 @@ describe('Rest Tests', function () {
247
247
248
248
// Assert
249
249
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
250
- assert ( restRes . result . url === 'https://httpbin.org/anything/multiple/anythingextra/moreparts' ) ;
250
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/multiple/anythingextra/moreparts' ) ;
251
251
} ) ;
252
252
253
253
it ( 'maintains the path from the base url where request has query parameters' , async ( ) => {
@@ -260,9 +260,9 @@ describe('Rest Tests', function () {
260
260
261
261
// Assert
262
262
assert ( restRes . statusCode == 200 , "statusCode should be 200" ) ;
263
- assert ( restRes . result . url === 'https://httpbin.org/anything/multiple/anythingextra/moreparts?foo=bar&baz=top' ) ;
264
- assert ( restRes . result . args . foo === 'bar' ) ;
265
- assert ( restRes . result . args . baz === 'top' ) ;
263
+ assert ( restRes . result && restRes . result . url === 'https://httpbin.org/anything/multiple/anythingextra/moreparts?foo=bar&baz=top' ) ;
264
+ assert ( restRes . result && restRes . result . args . foo === 'bar' ) ;
265
+ assert ( restRes . result && restRes . result . args . baz === 'top' ) ;
266
266
} ) ;
267
267
268
268
//
@@ -277,11 +277,11 @@ describe('Rest Tests', function () {
277
277
let res : string = util . getUrl ( '' , 'http://httpbin.org' ) ;
278
278
assert ( res === 'http://httpbin.org' , "should be http://httpbin.org" ) ;
279
279
} ) ;
280
-
280
+
281
281
it ( 'resolves a null resource with baseUrl' , async ( ) => {
282
282
let res : string = util . getUrl ( null , 'http://httpbin.org' ) ;
283
283
assert ( res === 'http://httpbin.org' , "should be http://httpbin.org" ) ;
284
- } ) ;
284
+ } ) ;
285
285
286
286
it ( 'resolves a full resource and no baseUrl' , async ( ) => {
287
287
let res : string = util . getUrl ( 'http://httpbin.org/get?x=y&a=b' ) ;
@@ -296,7 +296,7 @@ describe('Rest Tests', function () {
296
296
it ( 'resolves a relative path resource with host baseUrl' , async ( ) => {
297
297
let res : string = util . getUrl ( 'get/foo' , 'http://httpbin.org' ) ;
298
298
assert ( res === 'http://httpbin.org/get/foo' , `should be http://httpbin.org/get/foo but is ${ res } ` ) ;
299
- } ) ;
299
+ } ) ;
300
300
301
301
it ( 'resolves a rooted path resource with pathed baseUrl' , async ( ) => {
302
302
let res : string = util . getUrl ( '/get/foo' , 'http://httpbin.org/bar' ) ;
0 commit comments