Skip to content

Commit b60a484

Browse files
committed
feat: AI demo
Includes: * fix: .gitignore is properly ignoring files now
1 parent 3d8c8b1 commit b60a484

File tree

10 files changed

+1819
-381
lines changed

10 files changed

+1819
-381
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ yarn-debug.log*
2626
yarn-error.log*
2727

2828
pacts/
29-
logs/
29+
logs/
30+
31+
# IDE
32+
.vscode

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript',
5+
],
6+
};

capture/get.request.http

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /products/10 HTTP/1.1
2+
Host: api.example.com
3+
User-Agent: curl/8.1.2
4+
Accept: application/json; charset=UTF-8

capture/get.response.http

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json; charset=utf-8
3+
Content-Length: 96
4+
5+
{
6+
"id": "10",
7+
"name": "Aussie",
8+
"type": "Pizza",
9+
"version": "v1",
10+
"price": 9.99,
11+
}

package-lock.json

Lines changed: 1690 additions & 246 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
"axios": "^0.27.2"
77
},
88
"scripts": {
9-
"test:pact": "cross-env CI=true npx jest --colors --testTimeout 30000 --testMatch \"**/*.pact.spec.js\""
9+
"test:pact": "cross-env CI=true npx jest --colors --testTimeout 30000 --testMatch \"**/*.pact.spec.ts\""
1010
},
1111
"devDependencies": {
12+
"@babel/core": "^7.25.2",
13+
"@babel/preset-env": "^7.25.3",
1214
"@babel/preset-react": "^7.18.6",
15+
"@babel/preset-typescript": "^7.24.7",
1316
"@pact-foundation/pact": "^12.1.0",
17+
"@types/jest": "^29.5.12",
18+
"babel-jest": "^29.7.0",
1419
"cross-env": "^7.0.3",
1520
"jest": "^29.7.0"
1621
}

products.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Product API
4+
description: Pactflow Product API demo
5+
version: 1.0.0
6+
paths:
7+
/products:
8+
get:
9+
summary: List all products
10+
description: Returns all products
11+
operationId: getAllProducts
12+
responses:
13+
"200":
14+
description: successful operation
15+
content:
16+
"application/json; charset=utf-8":
17+
schema:
18+
type: "array"
19+
items:
20+
$ref: '#/components/schemas/Product'
21+
examples:
22+
application/json:
23+
value:
24+
- id: "1234"
25+
type: "food"
26+
price: 42
27+
# name: "pizza"
28+
# version: "1.0.0"
29+
# see https://github.com/apiaryio/dredd/issues/1430 for why
30+
"400":
31+
description: Invalid ID supplied
32+
content: {}
33+
/product/{id}:
34+
get:
35+
summary: Find product by ID
36+
description: Returns a single product
37+
operationId: getProductByID
38+
parameters:
39+
- name: id
40+
in: path
41+
description: ID of product to get
42+
schema:
43+
type: string
44+
required: true
45+
example: 10
46+
responses:
47+
"200":
48+
description: successful operation
49+
content:
50+
"application/json; charset=utf-8":
51+
schema:
52+
$ref: '#/components/schemas/Product'
53+
examples:
54+
application/json:
55+
value:
56+
id: "1234"
57+
type: "food"
58+
price: 42
59+
# name: "pizza"
60+
# version: "1.0.0"
61+
# see https://github.com/apiaryio/dredd/issues/1430 for why
62+
"400":
63+
description: Invalid ID supplied
64+
content: {}
65+
"401":
66+
description: Product not found
67+
content: {}
68+
"404":
69+
description: Product not found
70+
content: {}
71+
components:
72+
schemas:
73+
Product:
74+
type: object
75+
required:
76+
- id
77+
- name
78+
- price
79+
properties:
80+
id:
81+
type: string
82+
type:
83+
type: string
84+
name:
85+
type: string
86+
version:
87+
type: string
88+
price:
89+
type: number

src/api.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const axios = require("axios").default;
22
const adapter = require("axios/lib/adapters/http");
3-
const Product = require("./product");
43

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

7-
class API {
7+
export class API {
88
constructor(url) {
99
if (url === undefined || url === "") {
1010
url = process.env.REACT_APP_API_BASE_URL;
@@ -47,4 +47,10 @@ class API {
4747
}
4848
}
4949

50-
module.exports = API
50+
export class Product {
51+
constructor({id, name, type}) {
52+
this.id = id
53+
this.name = name
54+
this.type = type
55+
}
56+
}

src/api.pact.spec.js

Lines changed: 0 additions & 121 deletions
This file was deleted.

src/product.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)