Overview
The implementation and swagger specifications must be aligned during provider side contract testing. Whenever there is a drift, we must fix it.
SwaggerHub serves as a single source of truth for all swagger specifications. The Swagger specification will be shared with FED and other teams via SwaggerHub.
4. Create a file called dredd.yml in the root directory of the repo with the following content
5. Create a folder called contract-test inside /test directory
a .Create a file called /output/report.md inside /test/contract-test/ directory
b. Create a file called hooks.js inside /test/contract-test/ directory
c. In the hooks.js file you can modify the request and response based on the need.
Let’s say, your endpoint returning 404 not found response when you pass invalid id. To handle this case, you can use hooks.
You can also skip some tractions that you don’t want to cover as part of provider side contract testing.
Here is the hooks.js file in category-experience-api
Make the following changes to the repo on your local machine, but don't commit them to Github.
Open tsoa.json file, set yaml to true
Change the blueprint path in dredd.yml file.
Now, we made necessary changes into the repo. Let’s run the dredd.
Open a terminal and start the service by npm start command. Once the service started, open another terminal and issue npm run dredd command.
Or if you want to run all in single command run npm run contract-test:provider command.
Dredd will run api testing and the results will be updated in /test/contract-test/output/report.md file. Make sure all the dredd test cases are passed like below.
Once, we publish the specification into SwaggerHub, its time to publish provider side contracts into Pactflow. For that please run the following command
npm run contract-test:provider:publish
Publishing provider side contracts into Pactflow will be done on the developer's local machine in CDS.
CI/CD configuration
In .github/workflows/build.yml file, add the following configuration at the end