Skip to content

Commit

Permalink
test: add ruby/rust impl based DELETE reqs with body
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Nov 18, 2024
1 parent 9c10a50 commit 4a0ef70
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
run: npm i
- name: Test
run: GIT_BRANCH=${GITHUB_REF:11} make test
- name: Test DELETE with ruby
run: PACT_URL=pacts_ruby/pactflow-example-consumer-python-pactflow-example-provider-python.json GIT_BRANCH=${GITHUB_REF:11} make test
- name: Test DELETE with rust
run: PACT_URL=pacts_rust/pactflow-example-consumer-python-v3-pactflow-example-provider-python-v3.json GIT_BRANCH=${GITHUB_REF:11} make test

# Runs on branches as well, so we know the status of our PRs
can-i-deploy:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ ci: test can_i_deploy $(DEPLOY_TARGET)
# Use this for quick feedback when playing around with your workflows.
fake_ci: .env
CI=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false \
make ci

ci_webhook: .env
npm run test:pact

fake_ci_webhook:
CI=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=false \
make ci_webhook

## =====================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"consumer": {
"name": "pactflow-example-consumer-python"
},
"provider": {
"name": "pactflow-example-provider-python"
},
"interactions": [
{
"description": "a request to get a product",
"providerState": "a product with ID 10 exists",
"request": {
"method": "GET",
"path": "/product/10"
},
"response": {
"status": 200,
"headers": {
},
"body": {
"id": "27",
"name": "Margharita",
"type": "Pizza"
},
"matchingRules": {
"$.body": {
"match": "type"
}
}
}
},
{
"description": "a request to delete a product",
"providerState": "a product with ID 10 exists",
"request": {
"method": "DELETE",
"path": "/product/10",
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": "27"
},
"matchingRules": {
"$.body": {
"match": "type"
}
}
},
"response": {
"status": 204,
"headers": {
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"consumer": {
"name": "pactflow-example-consumer-python-v3"
},
"interactions": [

{
"description": "a request to get a product",
"pending": false,
"providerStates": [
{
"name": "a product with ID 10 exists"
}
],
"request": {
"method": "GET",
"path": "/product/10"
},
"response": {
"body": {
"content": {
"id": "27",
"name": "Margharita",
"type": "Pizza"
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json"
]
},
"matchingRules": {
"body": {
"$": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"status": 200
},
"type": "Synchronous/HTTP"
},
{
"description": "a request to delete a product",
"pending": false,
"providerStates": [
{
"name": "a product with ID 10 exists"
}
],
"request": {
"body": {
"content": {
"id": "27"
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json"
]
},
"matchingRules": {
"body": {
"$": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "DELETE",
"path": "/product/10"
},
"response": {
"status": 204
},
"type": "Synchronous/HTTP"
}
],
"metadata": {
"pactRust": {
"ffi": "0.4.22",
"models": "1.2.3"
},
"pactSpecification": {
"version": "4.0"
}
},
"provider": {
"name": "pactflow-example-provider-python-v3"
}
}
4 changes: 2 additions & 2 deletions src/product/pact.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const baseOpts = {

const setupServer = () => {
const app = require("express")();
const authMiddleware = require("../middleware/auth.middleware");
app.use(authMiddleware);
// const authMiddleware = require("../middleware/auth.middleware");
// app.use(authMiddleware);
app.use(require("./product.routes"));
const server = app.listen("8080");
return server;
Expand Down
9 changes: 9 additions & 0 deletions src/product/product.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ exports.getById = async (req, res) => {
const product = await repository.getById(req.params.id);
product ? res.send(product) : res.status(404).send({message: "Product not found"})
};
exports.deleteById = async (req, res) => {
const product = await repository.getById(req.params.id);
if (product) {
await repository.deleteById(req.params.id);
res.status(204).send();
} else {
res.status(404).send({message: "Product not found"});
}
};

exports.repository = repository;
3 changes: 3 additions & 0 deletions src/product/product.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ProductRepository {
async getById(id) {
return this.products.get(id);
}
async deleteById(id) {
return this.products.delete(id);
}
}

module.exports = ProductRepository;
1 change: 1 addition & 0 deletions src/product/product.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const router = require('express').Router();
const controller = require('./product.controller');

router.get("/product/:id", controller.getById);
router.delete("/product/:id", controller.deleteById);
router.get("/products", controller.getAll);

module.exports = router;

0 comments on commit 4a0ef70

Please sign in to comment.