Currently I have setup a provider test, that actually calls my provider and returns a response, which is then compared in the pact broker to the expected response body. However by calling my provider, it is running internal code that makes an axious call to another external endpoint to get a response, which it then does some mapping and returns a response back to the pact broker. Is there a way I can mock/stub this third party response, so it is not actually hitting the third part end point.
//Inside provider test
it('matches the consumer contract', async () => {
await new Verifier(opts).verifyProvider();
}, 30000);
//Call to third party which then uses the response
const response = await axiosInstance.post(url, input.body, {
headers: {
Authorization: `${input.token}`,
},
});
Can I just mock out axious in jest?
Currently I have setup a provider test, that actually calls my provider and returns a response, which is then compared in the pact broker to the expected response body.
In a consumer test, the Pact Broker is not part of the test at all. In fact, the Pact Broker doesn't do any testing at all - it is the point of collaboration for teams to share contracts, communicate work in progress and more.
However by calling my provider, it is running internal code that makes an axious call to another external endpoint to get a response, which it then does some mapping and returns a response back to the pact broker.
Again, no Pact Broker involved here. It is the Pact framework that is doing the communication to your code (on the consumer side, it acts as the fake provider, and vice versa for a provider test).
Is there a way I can mock/stub this third-party response, so it is not actually hitting the third part endpoint.
As suggested in the comments above, you should stub out this endpoint.
You should treat Pact as a unit testing tool. Strictly speaking, it isn't, but that is the mindset you need to bring to a Pact test. If you can't stub out dependencies in the test, that tells me one of the following is likely going on: