Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 79497bc

Browse files
committed
update readme information
1 parent b2398b0 commit 79497bc

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

readme.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,32 @@ composer require karriere/mocky
2222
```
2323

2424
## Configuration
25-
With mocky you can define your test cases via JSON. These JSON files are stored in the `tests` folder. Each test case can contain multiple endpoint definitions.
25+
With mocky you can define your test cases via JSON. The configuration consists of two file types:
2626

27+
* test files
28+
* mock files
29+
30+
A test file contains all your test endpoints (grouped by the request method) and references one or multiple mock files. The mock file defines the mock data to return. This seperation allows you to reuse mock data over multiple tests.
31+
32+
### Writing a test file
33+
A test file is stored in the `tests` folder and has the following basic structure
34+
35+
```json
36+
{
37+
"REQUEST_METHOD": {
38+
"ENDPOINT": {
39+
"content-type": "application/json",
40+
"mock": "mock-file.json"
41+
}
42+
}
43+
}
44+
```
45+
46+
The test file is a map of request methods (GET, POST, PUT, DELETE, ...). Each request method entry contains a map of endpoints as key and the endpoint definition as value.
47+
48+
Each request definition must define a `content-type` and a `mock` field. The mock field is a reference to the mock data file to deliver.
49+
50+
*Example:*
2751
```json
2852
{
2953
"GET": {
@@ -39,16 +63,20 @@ With mocky you can define your test cases via JSON. These JSON files are stored
3963
}
4064
```
4165

42-
The root elements of the test definintion defines the request methods. Each request method can contain multiple route definitions:
66+
#### Structuring your tests
67+
To be able to structure your test json files by feature a test can be stored in a subfolder.
4368

44-
### Request Definition
45-
The key of each request definition is the route (e.g. `/users`). Each request definitions must define a `content-type` and a `mock` field. The mock field is a reference to the mock data file to deliver.
69+
For example to store multiple tests for a user feature you can create a test under `tests/user/a-test.json`. This test has the following setup route `/setup/{scope}/user/a-test`.
4670

47-
### Mock Data
48-
A mock data file contains an array of mock responses. Each mock response must have a `status` and a `response` field. The `status` field defines the HTTP status code and the `response` field the API response in json format.
71+
### Writing a mock file
72+
A mock file contains an array of mock responses. Each mock response must have a `status` and a `response` field. The `status` field defines the HTTP status code and the `response` field the API response in json format.
4973

5074
Use `example/mocks/users/list-users.json` as a reference.
5175

76+
The mock file uses an array of mock response because you often need different data on subsequent requests.
77+
78+
Lets consider a simple example. You want to test a user feature. Your frontend makes an GET api call to `/users` and receives 2 user entries. Then the test sends a POST to `/users` to create a new user and then executes the GET `/users` again. In the second case 3 user entries should be returned.
79+
5280
## Using mocky
5381

5482
To deliver your mock data you need to setup your test case. To do so you call the mocky setup endpoint `/setup/{scope}/{test-name}`.

0 commit comments

Comments
 (0)