Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdietrich committed May 13, 2024
1 parent 7ac9df5 commit 0ecde81
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# NOTE from jcdietrich
I am maintaining all of my changes to this fork in the [jcd-all](https://github.com/jdietrich-tc/mmock/tree/jcd_all) branch

![Mmock](/docs/logo.png "Mmock logo")
=========

Expand Down Expand Up @@ -185,7 +182,10 @@ Mock definition:
"not_started (default state)",
"another_state_name"
],
"newState": "new_stat_neme"
"newState": "new_stat_neme",
"values": {
"value_name": "string (value value)"
}
},
"proxyBaseURL": "string (original URL endpoint)",
"delay": "string (response delay in s,ms)",
Expand Down Expand Up @@ -287,6 +287,71 @@ You can extract information from the request body too, using a dot notation path
- request.body."*key*" (support for `application/json`, `application/xml` and `application/x-www-form-urlencoded` requests)
- request.body."*deep*"."*key*" (support for `application/json`, `application/xml` requests)

**Response data:** you can reference any value you have assigned to the response
in order to mirror the same value in the Callback or as a Scenario value (see below).

- response.headers."*key*"
- response.cookies."*key*"
- response.body."*key*"

**Scenario values:**
You can store a value in the scenario at one state,
and then reference it later. For instance, if you need a random
value returned with the first request, and then referenced in a
future one. For example:

Mock definition 1 response and control blocks (state: not_started)
The value generated by `fake.SimplePassword` is added to the response,
but is also stored for future use in the `scenario.random` variable.

```
response:
statusCode: 200
headers:
Content-Type:
- application/json
body: >-
{
"random": "{{fake.SimplePassword}}"
}
control:
scenario:
name: test_scene
values:
var1: '001'
var2: '002'
random: "{{response.body.random}}"
newState: loaded
requiredState:
- 'not_started'
```

Mock definition 2, response and control blocks (state: loaded)
This is the second state in the series, and here the response
can return the same random value generated in state 1, by
referencing `scenario.random`

```
response:
statusCode: 200
headers:
Content-Type:
- application/json
body: >-
{
"value_1": "{{scenario.var1}}",
"random_from_scenario": "{{scenario.random}}"
}
control:
scenario:
name: test_scene
newState: not_started
requiredState:
- 'loaded'
```

Quick overview of the path syntax available to extract values form the request: [https://github.com/tidwall/gjson#path-syntax](https://github.com/tidwall/gjson#path-syntax)

You can also use "regex" and "concat" commands to complement GJson query:
Expand Down Expand Up @@ -634,6 +699,8 @@ You can always disable this behavior adding the following flag `-server-statisti
- Improved logging with levels thanks to [@jcdietrich](https://github.com/jcdietrich) [@jdietrich-tc](https://github.com/jdietrich-tc)
- Support for Regular Expressions for QueryStringParameters [@jcdietrich](https://github.com/jcdietrich) [@jdietrich-tc](https://github.com/jdietrich-tc)
- Support for URI and Description tags [@jcdietrich](https://github.com/jcdietrich) [@jdietrich-tc](https://github.com/jdietrich-tc)
- Support for response.* tags [@jcdietrich](https://github.com/jcdietrich) [@jdietrich-tc](https://github.com/jdietrich-tc)
- Support for storing and recalling scenario values (scenario.* tags) [@jcdietrich](https://github.com/jcdietrich) [@jdietrich-tc](https://github.com/jdietrich-tc)

### Contributing

Expand Down

0 comments on commit 0ecde81

Please sign in to comment.