pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

Pact files with matchers in request params are not getting matched while using pact-stub-server #11

Closed vini46 closed 6 years ago

vini46 commented 6 years ago

I have a interaction which expects the following request,

withRequest: { method: 'GET', path: '/api/objects', query: { page: somethingLike('1') } }

the pact file generated for this interaction has the following matchers,

"Get object", "request": { "method": "GET", "path": "/api/objects", "query": "page=1", "matchingRules": { "$.query.page[0]": { "match": "type" } } }

while using the stub server, i am getting the response only when i make the call with "/api/objects?page=1", when i change the request parameter value ""/api/objects?page=2" it is not getting matched, because of which no response is returned.

Please find below the logs from pact-stub-server,

===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Postman-Token": "866f0fef-1ecd-122c-801b-4480d74c63d2", "Authorization": "Basic Og==", "Accept": "/", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Host": "localhost:18119", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Connection": "keep-alive", "Content-Type": "application/json", "Cache-Control": "no-cache"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } service | 16:27:40 [INFO] body: '' service | service | 16:27:40 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Type], rule_logic: And }} }} }, generators: Generators { categories: {} } } service | 16:27:40 [WARN] No matching request found, sending 404 Not Found

uglyog commented 6 years ago

I have released version 0.0.9 that hopefully will work for you

uglyog commented 6 years ago

Just as an aside, as query parameters are always strings, using somethingLike('1') will match all query parameter values. Probably better to use a regex matcher to ensure they are numbers.