Skip to content

Commit

Permalink
feat: AI demo
Browse files Browse the repository at this point in the history
Includes:
  * fix: .gitignore is properly ignoring files now
  • Loading branch information
mefellows committed Sep 10, 2024
1 parent 3d8c8b1 commit b60a484
Show file tree
Hide file tree
Showing 10 changed files with 1,819 additions and 381 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ yarn-debug.log*
yarn-error.log*

pacts/
logs/
logs/

# IDE
.vscode
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
4 changes: 4 additions & 0 deletions capture/get.request.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GET /products/10 HTTP/1.1
Host: api.example.com
User-Agent: curl/8.1.2
Accept: application/json; charset=UTF-8
11 changes: 11 additions & 0 deletions capture/get.response.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 96

{
"id": "10",
"name": "Aussie",
"type": "Pizza",
"version": "v1",
"price": 9.99,
}
1,936 changes: 1,690 additions & 246 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
"axios": "^0.27.2"
},
"scripts": {
"test:pact": "cross-env CI=true npx jest --colors --testTimeout 30000 --testMatch \"**/*.pact.spec.js\""
"test:pact": "cross-env CI=true npx jest --colors --testTimeout 30000 --testMatch \"**/*.pact.spec.ts\""
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.24.7",
"@pact-foundation/pact": "^12.1.0",
"@types/jest": "^29.5.12",
"babel-jest": "^29.7.0",
"cross-env": "^7.0.3",
"jest": "^29.7.0"
}
Expand Down
89 changes: 89 additions & 0 deletions products.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
openapi: 3.0.1
info:
title: Product API
description: Pactflow Product API demo
version: 1.0.0
paths:
/products:
get:
summary: List all products
description: Returns all products
operationId: getAllProducts
responses:
"200":
description: successful operation
content:
"application/json; charset=utf-8":
schema:
type: "array"
items:
$ref: '#/components/schemas/Product'
examples:
application/json:
value:
- id: "1234"
type: "food"
price: 42
# name: "pizza"
# version: "1.0.0"
# see https://github.com/apiaryio/dredd/issues/1430 for why
"400":
description: Invalid ID supplied
content: {}
/product/{id}:
get:
summary: Find product by ID
description: Returns a single product
operationId: getProductByID
parameters:
- name: id
in: path
description: ID of product to get
schema:
type: string
required: true
example: 10
responses:
"200":
description: successful operation
content:
"application/json; charset=utf-8":
schema:
$ref: '#/components/schemas/Product'
examples:
application/json:
value:
id: "1234"
type: "food"
price: 42
# name: "pizza"
# version: "1.0.0"
# see https://github.com/apiaryio/dredd/issues/1430 for why
"400":
description: Invalid ID supplied
content: {}
"401":
description: Product not found
content: {}
"404":
description: Product not found
content: {}
components:
schemas:
Product:
type: object
required:
- id
- name
- price
properties:
id:
type: string
type:
type: string
name:
type: string
version:
type: string
price:
type: number
12 changes: 9 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const axios = require("axios").default;
const adapter = require("axios/lib/adapters/http");
const Product = require("./product");

axios.defaults.adapter = adapter;
axios.defaults.headers.common['Accept'] = "application/json";

class API {
export class API {
constructor(url) {
if (url === undefined || url === "") {
url = process.env.REACT_APP_API_BASE_URL;
Expand Down Expand Up @@ -47,4 +47,10 @@ class API {
}
}

module.exports = API
export class Product {
constructor({id, name, type}) {
this.id = id
this.name = name
this.type = type
}
}
121 changes: 0 additions & 121 deletions src/api.pact.spec.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/product.js

This file was deleted.

0 comments on commit b60a484

Please sign in to comment.