hey friends! I am new to Pact and recently put tog...
# pact-js
h
hey friends! I am new to Pact and recently put together a working example.
What I need help with is there a way to "spy" on the actual outgoing request url
? I already verified the following: • My Pact generated the "URL" from the local json file that gets created as a result of running the pact tests. I passed this in the
pactUrls
object • I passed in the correct "base url" in the
providerBaseUrl
object e.g.
<https://api.mytestpacturl.com>
• within the
requestFilter
hook, i was able to log out the
req.url
which seems correct e.g.
/myTestEndpoint/123
◦ i'd expect the complete request url to be ``https://api.mytestpacturl.com/myTestEndpoint/123`` Despite the correct logs, it looks like the actual endpoint under the hood might send something different? I got a 404 error back my endpoint. here's my code:
Copy code
test("my test pact complies with the contract", async () => {
  const pactUrls = await glob("pacts/*-mytest.json");
  const verifier = new Verifier({
// omitted the beforeEach hook since I do not think it is relevant to the question here
    failIfNoPactsFound: true,
    providerBaseUrl: '<https://api.mytestpacturl.com>',
    pactUrls,
    requestFilter: (req, res, next) => {
      console.log("req.url ", req.url); // logs out /myTestEndpoint/123
      next();
    },
  });

  await verifier.verifyProvider();
});
m
I’m not sure I follow sorry. If you’re getting
404
it means your provider doesn’t know how to respond to the request
h
hmm interesting! I grabbed the
path
from the pactUrls (pact generated json file), and constructed it with what I gave in the
providerBaseUrl
and made requests in postman and got back successful responses from the endpoint. But when I run the actual test which should use the correct parameters, i got back a 404 which is why I was wondering if there's a hook or something to spy to intercept the actual requests url that goes out to the real world @Matt (pactflow.io / pact-js / pact-go)
m
If you set log level to DEBUG, you should see all of the requests to/from your provider. Also, presumably your provider logs would be helpful too?
> providerBaseUrl: ‘https://api.mytestpacturl.com’, just so we’re clear - this is pointed at your provider API, yes?
h
yes, i have triple triple check that the provider API is correct.
m
what do the logs of your API provider say? What do the DEBUG logs say?
h
the logs was helpful! I was able to figure out my issue. I had to set a header in the request and i forgot to return the next() in my if block. There was another next() outside so my code was calling next() 2 times. Appreciate your help on helping me resolve this issue Matt!
m
nice! Yes, classic middleware problems 😛