Closed karl0ss closed 6 years ago
If you want to match expectations multiple time you need to specify the number of times you want to match, as shown in the following example: http://mock-server.com/mock_server/getting_started.html#button_match_request_by_path_exactly_twice
Or create an expectation that responds an unlimited number of times, as follows:
var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).mockAnyResponse({
"httpRequest": {
"path": "/some/path"
},
"httpResponse": {
"body": "some_response_body"
},
"times": {
"unlimited": true
},
"timeToLive": {
"unlimited": true
}
}).then(
function () {
console.log("expectation created");
},
function (error) {
console.log(error);
}
);
James was just going to respond to this one as I ran into same thing awhile ago.
Yes have found specifying the times unlimited: true took care of it and can call as many times as I need to ...
Perhaps you chose the "one shot" default for good reason however I think that the more natural expectation would be to make "unlimited" the default (you don't have to specify it at all) and then if you want to specify a limited number of times it can be invoked, that can be done by specifying "times". What do you think?
That is an interesting point and I do agree. I look at changing that to avoid the same confusion in the future. The original logic was much more complex and dynamically change from one shot to unlimited in certain situations but that was removed as it was complex to reason about, so I think the once default was a hang over from that. I'm going to re-open this issue until the default is fixed to unlimited.
Thanks guys :)
James, thats great I think it would be a win for everyone ... Curious why @karl0ss just closed this issue (?) if you changed it to "proposal" status. Maybe I'm just not familiar with this projects workflow yet :). I'd think it would need to be kept open so it can be actioned.
I have now changed the default to unlimited. This will be available in the next release unless you want to use the snapshot version.
Excellent news James! Thanks I'll test it out.
Sorry @jimkohl I didn't see the update in the status
I am running this on Node.JS....I have configured my js as follows using a JSON schema matcher -
When I run the server and post the following json via Postman -
The first response is a 200 with
{ "name": "You Sent JSON" }
As expected, but any posts i do after the first one all come back as 404s and do not work, but nothing has changed??
Any help would be appreciated, kinda pulling my hair out..
UPDATE, I have just done some GET requests tests, and this does the same, the first request works, all the subsequent (repeated) calls all get 404?