Validate Consumer(s) Against Various Versions Of OAS Document

Published date: April 15, 2024, Version: 1.0

If it just about testing a happy path of our Consumer-Provider in Pactflow, we could just go ahead and test one version of a Consumer against one version of a Provider.

But, what if we have situation where a single Provider is serving multiple Consumers at a given point in time?

 

So, this document will help us build understanding on how Pactflow manages the validation part when we have the following scenarios to be tested:

Scenario Consumer Name Consumer Version Provider Name Provider Version

Consumer A validating against a single version (1.0) of Provider

get-employee-api-consumer-A

1.0

get-employee-api-provider

1.0

Consumer A validating against a multiple version (1.0 and 2.0) of the same Provider

get-employee-api-consumer-A

1.0

get-employee-api-provider

1.0 and 2.0

Consumer A & B validating against same version (1.0) of OAS / Provider

get-employee-api-consumer-A

 

get-employee-api-consumer-B

1.0

 

 

1.0

get-employee-api-provider

Note:

Providers of the API have maintained two separate version of the API, i.e. V1 and V2 which are documented in the same OAS document

So, in this case publisher would be pushing 1.0 version of the API which has both V1 and V2 running on the separate endpoints. Here, consumer A wants to test against V1 & Consumer B wants to test against V2

1.0

Consumer A wants to test against V1

Consumer B wants to test against V2

SCENARIO 1: Test One Consumer Against One Version Of Provider

In this scenario, a Consumer writes the PACT tests at his end, generates a Contract using PACT mock provider and then publishes it to Pactflow. This published contract successfully reflects on the Pactflow dashboard with details like Consumer name, Consumer app version and branch name, verification status (remains unverified unless Provider Contract is available), etc. Refer to below screen shot:

Then, Provider publishes the very first version of his contract (OAS document and execution results) to Pactflow. And soon as it is done, Pactflow automatically triggers the validation between the Consumer & Provider.

Here, the Consumer Contract is validated against the uploaded version of the Provider and results of validation is shown on the dashboard. Refer to below screen shot.

SCENARIO 2: Test One Consumer Against Multiple Versions of the Same Provider

This scenario is an extension to the previous one. In this case, both the Consumer and Provider would publish their respective contracts to Pactflow (let us assume they both have published 1.0 version). Then, Pactflow would trigger validation of Consumer version 1.0 against Provider version 1.0.

Now, let us assume the Provider has made some changes in his API, so it is his responsibility to publish the new version of his contract to Pactflow (updated OAS document + updated test results).

When Provider publishes this latest/newer version of his contract to Pactflow, a validation should automatically be triggered between Consumer contract (already available in Pactflow) against the new version of Provider contract.

The a look at the below screen shot which clearly shows that the Consumer contract version 1.0 is being validated against Provider version 2.0 (newer / latest version).

Now, what if we want to check the validation results of the two systems based on the previous version of Provider contract, then, we should navigate to the MATRIX SECTION where a detailed analysis of all the versions is available. Refer to below screen shot.

SCENARIO 3: Test Multiple Consumers Against The Same Version Of Provider

By now we are aware of the fact that validation between the Consumer contract and Provider contract is automatically triggered by Pactflow as soon as contracts from both the ends are available.

We must also understand that it is never at a Consumer’s discretion to decide which specific contract version of the Provider it wants to test against and which version to skip.

Whenever a Provider publishes a new contract (OAS document + test results), all the available Consumers would automatically be validated by Pactflow against this latest Provider version(s) to ensure both the Consumer & Provider adhere to the contract.

We have a consumer by the name “Consumer A” and as it is being validated by Pactflow against all the available versions of the Provider. Let us take a look at the below screen shots.

Consumer A validated against Provider version 1.0

Consumer A validated against Provider version 2.0

Now, we have another consumer by the name “Consumer B” and as it is also being validated against all the available versions of the Provider. Let us take a look at the below screen shots.

Question: Till now we have mostly talked about various version of the Provider contract. But where could a Consumer check the details of the API Path it is being validated against?

Answer: If Provider API has maintained 2 separate paths or two separate API versions like V1 and V2, in that case the Consumer should build the contract accordingly by providing a specific path and the Consumer contract would be validated on basis of it.

When you view the comparison details of the contract, you could locate the API path or API version against which a Consumer is being validated. Refer to the below screen shot for details,