1
votes

We have 2 services where one is the consumer of the other. The consumer is written in Java and the provider is written in JavaScript.

On the consumer side we've defined a consumer-contract-test using pact-jvm and we're able to generate a contract. In this contract the response is defined like:

"response": {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": [
    "test"
  ]
},

On our provider we are now trying to define a provider-contract-test using pact-js but we are hitting a problem where in pact-js we are using a MessageProviderPact to verify the contract. But when running the test, the body is expected to be in a content attribute like this:

Key: - is expected 
            + is actual 
       Matching keys and values are not shown

       -[
       -  "test"
       -]
       +{
       +  "contents": {
       +    "statusCode": 200,
       +    "body": "[test]"
       +  }
       +}

Code used for pact verification

const p = new MessageProviderPact({
        messageProviders: {
            '': handler
        },
        provider: 'provider-service',
        pactUrls: [
            path.resolve(
                process.cwd(),
                'pacts',
                'consumer-service-provider-service.json'
            )
        ]
    });

Any idea's on how to solve this? Is it possible to use a similar message structure with content key on the consumer side? Or can we solve it any other way on the provider side

1
Any update on this? im using similar setup as you. Java providerand JavaScript consumer - WIlkins LIang
As suggested below, the MessageProviderPact was the wrong choice here. Using the standard Verifier class it's working - bvdwater

1 Answers

0
votes

MessageProviderPact is for message queue type interactions, not HTTP interactions. I think you need the standard Verifier class (https://github.com/pact-foundation/pact-js/#provider-api-testing):

const { Verifier } = require('@pact-foundation/pact');
let opts = {
  ...
};

new Verifier(opts).verifyProvider().then(function () {
    // do something
});