@@ -5,7 +5,7 @@ import std.functional, std.string;
55
66// forward commonly needed imports
77public import dlangbot.app;
8- public import vibe.http.common : HTTPMethod;
8+ public import vibe.http.common : HTTPMethod, HTTPStatus ;
99public import vibe.http.client : HTTPClientRequest;
1010public import vibe.http.server : HTTPServerRequest, HTTPServerResponse;
1111public import std.functional : toDelegate;
@@ -104,6 +104,8 @@ auto payloadServer(scope HTTPServerRequest req, scope HTTPServerResponse res)
104104 assert (0 , " Request for unexpected URL received: " ~ req.requestURL);
105105 }
106106
107+ res.statusCode = expectation.respStatusCode;
108+
107109 string filePath = buildPath(payloadDir, req.requestURL[1 .. $].replace(" /" , " _" ));
108110
109111 if (expectation.reqHandler ! is null )
@@ -169,14 +171,18 @@ void replaceAPIReferences(string official, string local, ref Json json)
169171
170172struct APIExpectation
171173{
174+ // / the called server url
172175 string url;
173176
174- // implement a custom request handler
177+ // / implement a custom request handler
175178 private void delegate (scope HTTPServerRequest req, scope HTTPServerResponse res) reqHandler;
176179
177- // modify the json of the payload before being served
180+ // / modify the json of the payload before being served
178181 private void delegate (ref Json j) jsonHandler;
179182
183+ // / respond with the given status
184+ HTTPStatus respStatusCode = HTTPStatus.ok;
185+
180186 this (string url)
181187 {
182188 this .url = url;
@@ -195,7 +201,11 @@ void setAPIExpectations(Args...)(Args args)
195201 {
196202 static if (is (Args[i] : string ))
197203 {
198- apiExpectations ~= APIExpectation(arg);
204+ apiExpectations ~= APIExpectation(arg);
205+ }
206+ else static if (is (Args[i] : HTTPStatus))
207+ {
208+ apiExpectations[$ - 1 ].respStatusCode = arg;
199209 }
200210 else
201211 {
0 commit comments