@@ -27,6 +27,8 @@ Public Function Specs() As SpecSuite
27
27
Dim ResponseHeaders As String
28
28
Dim Headers As Collection
29
29
Dim Cookies As Dictionary
30
+ Dim Options As Dictionary
31
+ Dim Request As RestRequest
30
32
31
33
With Specs.It("should parse json" )
32
34
json = "{""a"":1,""b"":3.14,""c"":""Howdy!"",""d"":true,""e"":[1,2]}"
@@ -125,6 +127,11 @@ Public Function Specs() As SpecSuite
125
127
.Expect(RestHelpers.JoinUrl("a/" , "/b" )).ToEqual "a/b"
126
128
End With
127
129
130
+ With Specs.It("should not join blank urls with /" )
131
+ .Expect(RestHelpers.JoinUrl("" , "b" )).ToEqual "b"
132
+ .Expect(RestHelpers.JoinUrl("a" , "" )).ToEqual "a"
133
+ End With
134
+
128
135
With Specs.It("should combine objects, with overwrite option" )
129
136
Set A = New Dictionary
130
137
Set B = New Dictionary
@@ -183,6 +190,24 @@ Public Function Specs() As SpecSuite
183
190
.Expect(Parsed("d & e" )).ToEqual "A + B"
184
191
End With
185
192
193
+ With Specs.It("should identify valid protocols" )
194
+ .Expect(RestHelpers.IncludesProtocol("http://testing.com" )).ToEqual "http://"
195
+ .Expect(RestHelpers.IncludesProtocol("https://testing.com" )).ToEqual "https://"
196
+ .Expect(RestHelpers.IncludesProtocol("ftp://testing.com" )).ToEqual "ftp://"
197
+ .Expect(RestHelpers.IncludesProtocol("htp://testing.com" )).ToEqual ""
198
+ .Expect(RestHelpers.IncludesProtocol("testing.com/http://" )).ToEqual ""
199
+ .Expect(RestHelpers.IncludesProtocol("http://https://testing.com" )).ToEqual "http://"
200
+ End With
201
+
202
+ With Specs.It("should remove valid protocols" )
203
+ .Expect(RestHelpers.RemoveProtocol("http://testing.com" )).ToEqual "testing.com"
204
+ .Expect(RestHelpers.RemoveProtocol("https://testing.com" )).ToEqual "testing.com"
205
+ .Expect(RestHelpers.RemoveProtocol("ftp://testing.com" )).ToEqual "testing.com"
206
+ .Expect(RestHelpers.RemoveProtocol("htp://testing.com" )).ToEqual "htp://testing.com"
207
+ .Expect(RestHelpers.RemoveProtocol("testing.com/http://" )).ToEqual "testing.com/http://"
208
+ .Expect(RestHelpers.RemoveProtocol("http://https://testing.com" )).ToEqual "https://testing.com"
209
+ End With
210
+
186
211
With Specs.It("should extract headers from response headers" )
187
212
ResponseHeaders = "Connection: keep -alive" & vbCrLf & _
188
213
"Date: Tue, 18 Feb 2014 15:00:26 GMT" & vbCrLf & _
@@ -208,6 +233,35 @@ Public Function Specs() As SpecSuite
208
233
.Expect(Cookies("duplicate-cookie" )).ToEqual "B"
209
234
End With
210
235
236
+ With Specs.It("should create request from options" )
237
+ Set Request = RestHelpers.CreateRequestFromOptions(Nothing )
238
+ .Expect(Request.Headers.count).ToEqual 0
239
+
240
+ Set Options = New Dictionary
241
+ Set Request = RestHelpers.CreateRequestFromOptions(Options)
242
+ .Expect(Request.Headers.count).ToEqual 0
243
+
244
+ Options.Add "Headers" , New Dictionary
245
+ Options("Headers" ).Add "HeaderKey" , "HeaderValue"
246
+ Set Request = RestHelpers.CreateRequestFromOptions(Options)
247
+ .Expect(Request.Headers("HeaderKey" )).ToEqual "HeaderValue"
248
+
249
+ Options.Add "Cookies" , New Dictionary
250
+ Options("Cookies" ).Add "CookieKey" , "CookieValue"
251
+ Set Request = RestHelpers.CreateRequestFromOptions(Options)
252
+ .Expect(Request.Cookies("CookieKey" )).ToEqual "CookieValue"
253
+
254
+ Options.Add "QuerystringParams" , New Dictionary
255
+ Options("QuerystringParams" ).Add "QuerystringKey" , "QuerystringValue"
256
+ Set Request = RestHelpers.CreateRequestFromOptions(Options)
257
+ .Expect(Request.QuerystringParams("QuerystringKey" )).ToEqual "QuerystringValue"
258
+
259
+ Options.Add "UrlSegments" , New Dictionary
260
+ Options("UrlSegments" ).Add "SegmentKey" , "SegmentValue"
261
+ Set Request = RestHelpers.CreateRequestFromOptions(Options)
262
+ .Expect(Request.UrlSegments("SegmentKey" )).ToEqual "SegmentValue"
263
+ End With
264
+
211
265
With Specs.It("should encode string to base64" )
212
266
.Expect(RestHelpers.EncodeStringToBase64("Howdy!" )).ToEqual "SG93ZHkh"
213
267
End With
0 commit comments