pact-foundation / pact-js-cli

The Broker CLI for Pact, but available to your node scripts
MIT License
1 stars 1 forks source link

Using "term" as query parameter is ignored in stub server #9

Open calvinbayer opened 1 year ago

calvinbayer commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behaviour

I have defined a provider interaction like below. After executing that test and feeding the created PACT file into a stub server, I'd expect to get a successful response for any request in the form of /animals?id=<SOME_NUMBER>.

// Provider interaction in PACT Test
await provider.addInteraction({
  state: "there are animals",
  uponReceiving: "a request for a specific animal",
  withRequest: {
    path: "/animals",
    method: "GET",
    query: {
      id: term({
        generate: "123",
        matcher: "\\d+",
      }),
    },
  },
  willRespondWith: {
    status: 200,
    headers: {
      "Content-Type": "application/json",
    },
    body: {
      id: term({
        generate: "123",
        matcher: "\\d+",
      }),
      name: like("dog"),
    },
  },
});

// ...

// Starting a stub server
import { Stub } from "@pact-foundation/pact-node";

const pactStub = new Stub({ pactUrls: pactFiles, port: 4000, logLevel: "debug" });
await pactStub.start();

Actual behaviour

When the stub server boots, it will print the following error to the console

pact-node@10.17.6: Pact Binary Error: WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>"\\d+"} for path $['query']$['id'][0]

and any request to /animals?id=<SOME_NUMBER> with SOME_NUMBER !== 123 will yield a 500 response. I have found this issue and this seems to have been a problem in the past that has been fixed already. However, I was not able to get it running with the latest version of @pact-foundation/pact-node.

Steps to reproduce

I've uploaded a minimal reproducible example here: https://github.com/calvinbayer/pact-stub-server-repro

Relevant log files

pact_debug_log.txt

mefellows commented 1 year ago

Thanks for this, apologies for the radio silence - I'm not sure why it didn't get a response earlier.

This may be related to https://github.com/pact-foundation/pact-js/issues/1063, but is more likely related to https://github.com/pact-foundation/pact-mock_service/issues/140

github-actions[bot] commented 1 year ago

👋 Thanks, this ticket has been added to the PactFlow team's backlog as PACT-768