Skip to content

Commit f53f351

Browse files
committed
chore: updates to AI demo
1 parent c3e2f22 commit f53f351

File tree

3 files changed

+577
-670
lines changed

3 files changed

+577
-670
lines changed

README.md

+97-27
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,116 @@
11
# Example Consumer
22

3-
![Build](https://github.com/pactflow/example-consumer/workflows/Build/badge.svg)
4-
5-
[![Pact Status](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest) (latest pact)
6-
7-
[![Can I deploy Status](https://test.pactflow.io/pacticipants/pactflow-example-consumer/branches/master/latest-version/can-i-deploy/to-environment/production/badge)](https://test.pactflow.io/pacticipants/pactflow-example-consumer/branches/master/latest-version/can-i-deploy/to-environment/production/badge)
8-
9-
This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [PactFlow](https://pactflow.io).
10-
11-
It is using a public tenant on PactFlow, which you can access [here](https://test.pactflow.io/) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest).
12-
13-
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
14-
15-
* Test
16-
* Run tests (including the pact tests that generate the contract)
17-
* Publish pacts, associating the consumer version with the name of the current branch
18-
* Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)
19-
* Deploy (only from master)
20-
* Deploy app (just pretend for the purposes of this example!)
21-
* Record the deployment in the Pact Broker
22-
23-
## Usage
24-
25-
See the [PactFlow CI/CD Workshop](https://github.com/pactflow/ci-cd-workshop).
3+
See the main branch for background, prerequisites and more.
264

275
### Pre-requisites
286

297
**Software**:
308

319
* Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/
3210
* A pactflow.io account with an valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token)
11+
* `pactflow-ai` installed
12+
* Quick install: `curl https://download.pactflow.io/ai/get.sh | sh`
13+
* [Instructions](https://docs.pactflow.io/docs/ai/quick-start)
3314

3415
#### Environment variables
3516

36-
To be able to run some of the commands locally, you will need to export the following environment variables into your shell:
17+
You will need to export the following environment variables into your shell:
3718

3819
* `PACT_BROKER_TOKEN`: a valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token) for PactFlow
3920
* `PACT_BROKER_BASE_URL`: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io
4021

41-
### Usage
42-
43-
#### Pact use case
22+
### AI Demo
23+
24+
#### Recommended arguments
25+
26+
The best output combines the input of code + the OAD (comprehension of the system), a code template (to produce consistent output) and additional instructions (use-case specific guidance):
27+
```
28+
pactflow-ai generate \
29+
--output ./src/api.pact.spec.ts \
30+
--language typescript \
31+
--openapi ./products.yml \
32+
--endpoint "/product/{id}" \
33+
--code ./src/product.js \
34+
--code ./src/api.js \
35+
--template ./src/pact.test.template \
36+
--instructions "Write test cases for the positive (HTTP 200) scenario and negative scenarios, specifically the case of 400, 401 and 404"
37+
```
38+
39+
#### Other variations
40+
41+
**With OpenAPI + Code**
42+
```
43+
pactflow-ai generate \
44+
--output ./src/api.pact.spec.ts \
45+
--language typescript \
46+
--openapi ./products.yml \
47+
--endpoint "/products" \
48+
--code ./src/product.js \
49+
--code ./src/api.js
50+
```
51+
52+
**With Code**
53+
```
54+
pactflow-ai generate \
55+
--output ./src/api.pact.spec.ts \
56+
--language typescript \
57+
--code ./src/product.js \
58+
--code ./src/api.js
59+
```
60+
61+
**With OpenAPI**
62+
```
63+
pactflow-ai generate \
64+
--output ./src/api.pact.spec.ts \
65+
--language typescript \
66+
--openapi ./products.yml \
67+
--endpoint "/products" \
68+
--code ./src/product.js \
69+
--code ./src/api.js
70+
```
71+
72+
**With HTTP captures**
73+
```
74+
pactflow-ai generate \
75+
--request ./capture/get.request.http \
76+
--response ./capture/get.response.http \
77+
--language typescript \
78+
--output ./src/api.pact.spec.ts
79+
```
80+
81+
**With a test template**
82+
```
83+
pactflow-ai generate \
84+
--output ./src/api.pact.spec.ts \
85+
--language typescript \
86+
--code ./src/product.js \
87+
--code ./src/api.js \
88+
--template ./src/pact.test.template \
89+
```
90+
91+
**With additional instructions (inline)**
92+
```
93+
pactflow-ai generate \
94+
--output ./src/api.pact.spec.ts \
95+
--language typescript \
96+
--code ./src/product.js \
97+
--code ./src/api.js \
98+
--template ./src/pact.test.template \
99+
--instructions "Write test cases for the positive (HTTP 200) scenario and negative scenarios, specifically the case of 400, 401 and 404"
100+
```
101+
102+
**With additional instructions (as a file)**
103+
```
104+
pactflow-ai generate \
105+
--output ./src/api.pact.spec.ts \
106+
--language typescript \
107+
--code ./src/product.js \
108+
--code ./src/api.js \
109+
--template ./src/pact.test.template \
110+
--instructions ./src/test.instructions.txt
111+
```
112+
113+
### Running Tests
44114

45115
* `make test` - run the pact test locally
46116
* `make fake_ci` - run the CI process locally

0 commit comments

Comments
 (0)