Skip to content

Commit a3d9d8b

Browse files
authored
docs: add common test suite schema for snippets (#3302)
1 parent 5c07d4e commit a3d9d8b

File tree

1 file changed

+79
-64
lines changed

1 file changed

+79
-64
lines changed

website/docs/contributing/testing/common-test-suite.md

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,71 +33,86 @@ The list of `queryParameters` must match exactly the actual value, the CTS has t
3333
> See the [browse test file for the search client](https://github.com/algolia/api-clients-automation/blob/main/tests/CTS/requests/search/browse.json)
3434
3535
```json
36-
[
37-
{
38-
"testName": "The name of the test (e.g. 'searches to testIndex with query parameters')",
39-
// The parameters of you'd like to pass to the method
40-
"parameters": {
41-
"indexName": "testIndex",
42-
"searchParams": {
43-
"offset": 42,
44-
"limit": 21,
45-
"query": "the string to search"
46-
},
47-
"facets": ["*"]
48-
},
49-
// Additional options sent with your method
50-
"requestOptions": {
51-
// Merged with transporter query parameters
52-
"queryParameters": {
53-
"anOtherParam": true
54-
},
55-
// Merged with transporter headers
56-
"headers": {
57-
"x-header": "test"
58-
}
59-
},
60-
// The payload of the request
61-
"request": {
62-
"path": "/1/indexes/testIndex/query",
63-
"method": "POST",
64-
"body": { "query": "the string to search" },
65-
"queryParameters": {
66-
"otherParam": "22",
67-
"anOtherParam": "true"
68-
},
69-
"headers": {
70-
"x-header": "test"
71-
}
72-
},
73-
// The expected response - useful for e2e assertions
74-
"response": {
75-
"statusCode": 200,
76-
// This doesn't need to be the full response since we support partial assertions
77-
"body": {
78-
"results": [
79-
{
80-
"hits": [],
81-
"page": 0,
82-
"nbHits": 0,
83-
"nbPages": 0,
84-
"hitsPerPage": 20,
85-
"exhaustiveNbHits": true,
86-
"exhaustiveTypo": true,
87-
"exhaustive": {
88-
"nbHits": true,
89-
"typo": true
36+
{
37+
"$schema": "http://json-schema.org/draft-04/schema#",
38+
"type": "object",
39+
"properties": {
40+
"testName": {
41+
"type": "string",
42+
"description": "The name of the test, defaults to the name of the `operation` (file name). The testName is also used for the documentation snippets as a key to access it inside the snippet JSON object: with a testName equal to `foo` on the `operationIndex` of the `search` client, you can access it from the `search.operationIndex.foo` key."
43+
},
44+
"isSnippet": {
45+
"type": "boolean",
46+
"description": "Whether this test case should also be a documentation code snippet."
47+
},
48+
"parameters": {
49+
"type": "object",
50+
"description": "A free form object that must correspond to the parameters that the method expects."
51+
},
52+
"requestOptions": {
53+
"type": "object",
54+
"description": "The requests options of an Algolia client to send with the current test case.",
55+
"properties": {
56+
"queryParameters": {
57+
"type": "object",
58+
"description": "The extra query parameters to send with your initial request."
59+
},
60+
"headers": {
61+
"type": "object",
62+
"description": "The extra headers to send with your initial request."
63+
}
64+
}
65+
},
66+
"request": {
67+
"type": "object",
68+
"description": "The expected request to be sent by the client.",
69+
"properties": {
70+
"path": {
71+
"type": "string",
72+
"description": "The path of the API client request, e.g. /1/foo/bar."
73+
},
74+
"method": {
75+
"type": "string",
76+
"description": "The HTTP method used to contact the path, e.g. GET."
77+
},
78+
"body": {
79+
"type": "object",
80+
"description": "A free form object that contains the expected payload to be sent for the current test case."
81+
},
82+
"queryParameters": {
83+
"type": "object",
84+
"description": "A free form object that contains the expected query parameters to be sent for the current test case."
85+
},
86+
"headers": {
87+
"type": "object",
88+
"description": "A free form object that contains the expected headers to be sent for the current test case."
89+
}
9090
},
91-
"query": "",
92-
"params": "",
93-
"index": "cts_e2e_search_empty_index",
94-
"renderingContent": {}
95-
}
96-
]
97-
}
98-
}
99-
}
100-
]
91+
"required": [
92+
"path",
93+
"method"
94+
]
95+
},
96+
"response": {
97+
"type": "object",
98+
"description": "The expected response to be returned by the client. Specificying this field indicates an e2e test will be performed, nothing is mocked.",
99+
"properties": {
100+
"statusCode": {
101+
"type": "integer",
102+
"description": "The status code of the response."
103+
},
104+
"body": {
105+
"type": "object",
106+
"description": "A free form object that contains the expected response to be received for the current test case."
107+
}
108+
}
109+
}
110+
},
111+
"required": [
112+
"parameters",
113+
"request"
114+
]
115+
}
101116
```
102117

103118
#### e2e

0 commit comments

Comments
 (0)