Skip to content

Commit 1e61f6a

Browse files
committed
Update and add specs
1 parent 810b823 commit 1e61f6a

File tree

5 files changed

+44
-23
lines changed

5 files changed

+44
-23
lines changed

specs/Excel-REST - Specs.xlsm

1.03 KB
Binary file not shown.

specs/RestClientAsyncSpecs.bas

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ Public Function Specs() As SpecSuite
1313
Client.BaseUrl = "http://localhost:3000"
1414

1515
Dim Request As RestRequest
16-
17-
With Specs.It("should wait")
18-
Dim GoalTime As Long
19-
GoalTime = GetTickCount() + 100
20-
21-
Wait 100
22-
.Expect(GetTickCount()).ToBeGTE GoalTime
23-
End With
16+
Dim WaitTime As Integer
17+
WaitTime = 500
2418

2519
With Specs.It("should pass response to callback")
2620
Set Request = New RestRequest
2721
Request.Resource = "get"
2822

2923
Client.ExecuteAsync Request, "SimpleCallback"
30-
Wait 200
24+
Wait WaitTime * 2
3125
.Expect(AsyncResponse).ToBeDefined
3226
End With
3327

@@ -36,7 +30,7 @@ Public Function Specs() As SpecSuite
3630
Request.Resource = "get"
3731

3832
Client.ExecuteAsync Request, "ComplexCallback", Array("A", "B", "C")
39-
Wait 200
33+
Wait WaitTime
4034
.Expect(AsyncResponse).ToBeDefined
4135
If UBound(AsyncArgs) > 1 Then
4236
.Expect(AsyncArgs(0)).ToEqual "A"
@@ -53,25 +47,25 @@ Public Function Specs() As SpecSuite
5347

5448
Request.AddUrlSegment "code", 200
5549
Client.ExecuteAsync Request, "SimpleCallback"
56-
Wait 200
50+
Wait WaitTime
5751
.Expect(AsyncResponse.StatusCode).ToEqual 200
5852
.Expect(AsyncResponse.StatusDescription).ToEqual "OK"
5953

6054
Request.AddUrlSegment "code", 304
6155
Client.ExecuteAsync Request, "SimpleCallback"
62-
Wait 200
56+
Wait WaitTime
6357
.Expect(AsyncResponse.StatusCode).ToEqual 304
6458
.Expect(AsyncResponse.StatusDescription).ToEqual "Not Modified"
6559

6660
Request.AddUrlSegment "code", 404
6761
Client.ExecuteAsync Request, "SimpleCallback"
68-
Wait 200
62+
Wait WaitTime
6963
.Expect(AsyncResponse.StatusCode).ToEqual 404
7064
.Expect(AsyncResponse.StatusDescription).ToEqual "Not Found"
7165

7266
Request.AddUrlSegment "code", 500
7367
Client.ExecuteAsync Request, "SimpleCallback"
74-
Wait 200
68+
Wait WaitTime
7569
.Expect(AsyncResponse.StatusCode).ToEqual 500
7670
.Expect(AsyncResponse.StatusDescription).ToEqual "Internal Server Error"
7771
End With
@@ -81,9 +75,9 @@ Public Function Specs() As SpecSuite
8175
Request.Resource = "timeout"
8276
Request.AddQuerystringParam "ms", 2000
8377

84-
Client.TimeoutMS = 500
78+
Client.TimeoutMS = 100
8579
Client.ExecuteAsync Request, "SimpleCallback"
86-
Wait 1000
80+
Wait 500
8781
.Expect(AsyncResponse).ToBeDefined
8882
If Not AsyncResponse Is Nothing Then
8983
.Expect(AsyncResponse.StatusCode).ToEqual 504
@@ -105,7 +99,7 @@ Public Sub ComplexCallback(Response As RestResponse, Args As Variant)
10599
End Sub
106100

107101
Public Sub Reset()
108-
Set AsyncResponse = Nothing
102+
Set AsyncResponse = New RestResponse
109103
AsyncArgs = Array()
110104
End Sub
111105

specs/RestClientSpecs.bas

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Public Function Specs() As SpecSuite
7979

8080
.Expect(Client.Execute(Request).Data("body")).ToEqual "Howdy!"
8181

82-
Dim Body As New Dictionary
82+
Dim Body As Object
83+
Set Body = CreateObject("Scripting.Dictionary")
8384
Body.Add "a", 3.14
8485

8586
Set Request = New RestRequest
@@ -104,5 +105,19 @@ Public Function Specs() As SpecSuite
104105
.Expect(Response.Data("query")("d")).ToEqual "False"
105106
End With
106107

108+
With Specs.It("should return 504 on request timeout")
109+
Set Request = New RestRequest
110+
Request.Resource = "timeout"
111+
Request.AddQuerystringParam "ms", 2000
112+
113+
Client.TimeoutMS = 500
114+
Set Response = Client.Execute(Request)
115+
.Expect(Response.StatusCode).ToEqual 504
116+
.Expect(Response.StatusDescription).ToEqual "Gateway Timeout"
117+
Debug.Print Response.Content
118+
End With
119+
120+
Set Client = Nothing
121+
107122
InlineRunner.RunSuite Specs
108123
End Function

specs/RestRequestSpecs.bas

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ Public Function Specs() As SpecSuite
7777

7878
.Expect(Request.FormattedResource).ToEqual "?A=123&B=456&C=789"
7979
End With
80+
81+
With Specs.It("should not add ? if already in resource")
82+
Set Request = New RestRequest
83+
Request.IncludeCacheBreaker = False
84+
85+
Request.AddParameter "B", "456"
86+
Request.Method = httpGET
87+
Request.Resource = "?A=123"
88+
89+
.Expect(Request.FormattedResource).ToEqual "?A=123&B=456"
90+
End With
8091

8192
With Specs.It("should URL encode querystring")
8293
Set Request = New RestRequest
@@ -122,7 +133,8 @@ Public Function Specs() As SpecSuite
122133
With Specs.It("should only combine body and parameters if not GET Request")
123134
Set Request = New RestRequest
124135

125-
Dim Body As New Dictionary
136+
Dim Body As Object
137+
Set Body = CreateObject("Scripting.Dictionary")
126138
Body.Add "A", 123
127139

128140
Request.AddBody Body

specs/server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
var express = require('express');
22
var app = express();
33

4-
app.use(plain());
5-
app.use(express.json());
6-
app.use(express.urlencoded());
7-
84
app.use(function(req, res, next){
95
console.log('%s %s', req.method, req.url);
106
next();
117
});
128

9+
app.use(plain());
10+
app.use(express.json());
11+
app.use(express.urlencoded());
12+
1313
// Standard
1414
app.get('/get', standardResponse);
1515
app.post('/post', standardResponse);

0 commit comments

Comments
 (0)