-
Notifications
You must be signed in to change notification settings - Fork 377
Fixtures command
Thor 雷神 edited this page Mar 20, 2020
·
5 revisions
The fixtures
command lets you run a json
file as a series of API requests. This can be useful for things like filling data, executing specific flows, or testing API behavior.
Fixtures live in a json
file and map to requests. An example file looks like:
{
"_meta": {
"template_version": 0
},
"fixtures": [
{
"name": "cust_bender",
"path": "/v1/customers",
"method": "post",
"params": {
"name": "Bender Bending Rodriguez",
"email": "[email protected]",
"phone": "${.env:PHONE}",
"source": "tok_amex",
"address": {
"line1": "1 Planet Express St",
"city": "New New York"
}
}
},
{
"name": "char_bender",
"path": "/v1/charges",
"method": "post",
"params": {
"customer": "${cust_bender:id}",
"amount": 100,
"currency": "usd",
"capture": false
}
},
{
"name": "capt_bender",
"path": "/v1/charges/${char_bender:id}/capture",
"method": "post"
}
]
}
-
_meta
- contains information specifically for the CLI to read -
_meta.template_version
tells the CLI which version of the template is running (allowing us to support possible backwards-incompatible changes) -
fixtures
is list of requests to execute -
fixtures[].name
is the name of the request, used for reference results later -
fixtures[].path
is the relative Stripe URL to make the request to. This supports URL variables as fixture queries -
fixtures[].method
the HTTP method for the request -
fixtures[].params
an object the API request params to send to Stripe. The values here can be nested JSON objects, strings, integers, booleans, or fixture queries.
When you give a request a name, the CLI will store the response to use in other requests. The structure of this is:
Accessing attributes in responses: ${name:json_path}
Accessing environment variables: ${.env:VARIABLE_NAME}
Queries must start with ${
and end with }
. name
is the name of the request assigned as part of the fixture (fixtures[].name
) and the json_path
is a dot-path to the specific variable requested, for example:
-
${cust_bender:id}
: to access a top-level attribute -
${cust_bender:billing_details.address.country}
: to access nested data -
${cust_bender:subscriptions.data.[0].id}
: to access data within a list -
${.env:PHONE}
: to access environment variables, supports.env
files