0

I am using Pact-js with Jest, I am trying to get the response that returns the (real) API consumption from the provider side, the code is the following.


describe("Validate pact of identity", () => {


    it("Validate pact of identity creation", () => {
        let opts = {
            providerBaseUrl: baseUrl.BASE_URL,
            changeOrigin: true,
            provider: "Create identity Service",
            logLevel: "DEBUG",
            pactUrls: [
                path.resolve(
                    process.cwd(),
                    `./__tests__/contract/pacts/${requestData.nameConsumerPactFile}-${requestData.nameProviderPactFile}.json`
                ),
            ],
            requestFilter: async (req, res, next) => {
                req.headers["Authorization"] = `Bearer ${await postRequestToken(paths.TOKEN_NON_CDE)}`,
                next()
            },
            consumerVersionTags: ["QA"],
            providerVersionTags: ["QA"],
            publishVerificationResult: false,
            providerVersion: "1.0.0"
        }

        return new Verifier(opts).verifyProvider()
            .then((res) => {
                console.log('pact veryify complete, !!!');
                console.log(res);
            });
    })




})

but the method Verifier(opts).verifyProvider() res variable value does not return the API response, is there any way to get the response after PACT does the verification?

1 Answers1

0

The short answer is no.

The pact provider verification does a few things:

  1. It reads in the given contracts / fetches them from a Pact Broker. These contracts represent the needs of its consumers.
  2. For each interaction in the contract (of which there are usually many), Pact assumes the role of an API client and issues the requests and asserts on the response
  3. It reports back the success or failure of this.

So it doesn't make sense to return the response, because there could be many.

What do you want to do with that response (or responses)?

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18