Hello Sorry if this is the wrong channel. Im new t...
# pact-js
k
Hello Sorry if this is the wrong channel. Im new to contract testing I have this situation with my backend where im calling an external intercom api In this a situation should I make a pact test? Im trying to mock the axios call in the beforeAll method with very little success. Has anyone got a code example for this situation or can point me in the correct docs direction.
m
Are you trying to mock it during the provider verification test of
Service
or as its role as the consumer of
Intercom
? The question is valid, and you can run a Pact test in this situation (but just note that you’re unlikely to be able to do a provider verification test of it. If you have an OAS for that provider, you could use that in a BDCT test (see also https://docs.pactflow.io/docs/bi-directional-contract-testing if you’re using PactFlow)
In terms of mocking axios, do you need to mock axios itself or do you have an internal API client you can mock directly? are you using an Intercom SDK or directly talking to their APIs?
k
In terms of mocking axios, do you need to mock axios itself or do you have an internal API client you can mock directly? are you using an Intercom SDK or directly talking to their APIs?
Thank you for your reply! So im directly calling there API from my backend service and satanising the data a bit before returning it. It would be nice for me to skip the api call when my provider runs and I can add some mock data instead of me calling the intercom api every time I run the provider tests.
m
right, yeah. So you should have an API client that wraps the axios call, yes? That’s really the target you should be mocking. But if not, you could use something like
nock
to mock that call
k
Okey thanks for your help 😄
👍 1
m
no probs. What test framework do you use, btw? (e.g. Jest, Mocha etc.)
Jest has decent module mocking as well, assuming your API client is its own module
k
Jest
👍 1