-
Notifications
You must be signed in to change notification settings - Fork 4
add v3 fixtures with andReturnJSON option #15
Conversation
18253b9
to
f8b78ac
Compare
The tests for the status option fail on older versions of Node.js--only on These tests fail because This looks to me like a potential problem in spur-errors, as the transpiled code reads, exports.__esModule = true;var BaseError = {
create: function create(message, internalError) {
Error.captureStackTrace(this);
var error = Object.assign(new Error(), BaseError);
if (message) {
error.message = message;
}
if (internalError) {
error.internalError = internalError;
}
return error;
}
} The fix is probably to use transform-object-assign, which evidently isn't part of the ES2015 preset. For later, I removed: Status (optional)var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost/v3/fixtures");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify({
fixtures: [{
endpoint: "MyMockEndpoint",
json: {},
status: 404
}]
})); If the mock server is running on The minimally required empty object models the existing parameters and behavior of the Removed Support@["#{fixture.endpoint}"].andReturnJSON(fixture.json, fixture.status) to @["#{fixture.endpoint}"].andReturnJSON(fixture.json) Failing Testsit "should respond with 304 status", ()->
@HTTPService
.post("http://localhost:#{@config.Port}/v3/fixtures/")
.send({
fixtures: [{
endpoint: "UsersMockEndpoint"
json: {"test": true}
status: 304
}]
})
.promiseBody()
.then =>
@HTTPService
.get("http://localhost:#{@config.Port}/api/users/")
.promiseBody()
.then (response)->
expect(response.statusCode).to.equal(304)
it "should respond with 404 status", ()->
@HTTPService
.post("http://localhost:#{@config.Port}/v3/fixtures/")
.send({
fixtures: [{
endpoint: "UsersMockEndpoint"
json: {}
status: 404
}]
})
.promiseBody()
.then =>
@HTTPService
.get("http://localhost:#{@config.Port}/api/users/")
.promiseBody()
.catch (error)->
expect(error.statusCode).to.equal(404) I was also surprised to see that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morewry Looks good overall. Just one minor request, could you please add the example client usage to the readme? Didn't notice we were missing that. We can start with the v3:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost/v3/fixtures");
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify({
fixtures: [{
endpoint: "MyMockEndpoint",
json: '{"example":[1, 2, 3]}'
}]
}));
Only correction I would add there is the JSON as as string part:
json: {"example":[1, 2, 3]}
f8b78ac
to
47f7ef3
Compare
@acolchado Updated PR with README |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you much for the change @morewry
Summary
Adds
/v3/fixtures
with an option to utilizeandReturnJSON
functionality of mock endpoints.Purpose
The three "fixtures" middleware handlers enable the customization of fixtures returned by mock endpoints from web clients, e.g. with
XMLHttpRequest
orfetch
, addressing use cases of web UI developers and manual QA.The existing
/fixtures
and/v2/fixtures
handlers enable the selection of a pre-existing method from mock endpoints. This pull requests creates a/v3/fixtures
handler that enables a user to set an explicit complete response in JSON, giving the web client interface functional parity (basically, also see further about status) with the Node.js runtime interface in controlling mock endpoint responses.Previous Usage
On a web page used for active development or testing,
If the mock server is running on
localhost
and the mock endpointMyMockEndpoint
is registered and has a methodmyMethod
, thePOST
request succeeds and successive requests that are handled byMyMockEndpoint
will runmyMethod
to generate its response.New Usage
Method
If the mock server is running on
localhost
and the mock endpointMyMockEndpoint
is registered and has a methodmyMethod
, thePOST
request succeeds and successive requests that are handled byMyMockEndpoint
will runmyMethod
to generate its response.JSON
If the mock server is running on
localhost
and the mock endpointMyMockEndpoint
is registered, thePOST
request succeeds and successive requests that are handled byMyMockEndpoint
will respond with an HTTP status of200
and the JSON{"example":[1, 2, 3]}
.Status (optional)
Removed due to bug (see comments).