Skip to content

Commit 4dd98fe

Browse files
authored
fix: use object for CTS parameters (#61)
1 parent aa9f348 commit 4dd98fe

32 files changed

+589
-409
lines changed

doc/CTS.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ The test generation script requires a JSON file name from the `operationId` (e.g
2525
{
2626
"testName": "the name of the test (e.g. test('search endpoint')) (default: 'method')",
2727
"method": "the method to call (e.g. search)",
28-
"parameters": [
29-
"indexName",
30-
{
31-
"$objectName": "the name of the object for strongly type language",
28+
"parameters": {
29+
"indexName": "testIndex",
30+
"searchParam": {
31+
"$objectName": "the name of the object for strongly type language, should be on every 'object' type",
3232
"query": "the string to search"
3333
}
34-
],
34+
},
3535
"request": {
36-
"path": "/1/indexes/indexName/query",
36+
"path": "/1/indexes/testIndex/query",
3737
"method": "POST",
3838
"data": { "query": "the string to search" }
3939
}
@@ -45,5 +45,45 @@ And that's it! If the name of the file matches a real `operationId` in the spec,
4545

4646
## How to add a new language
4747

48-
- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice
4948
- Add the language in the array `languages` in `tests/generateCTS.ts`.
49+
- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice
50+
51+
When writing your template, here is a list of variables accessible from `mustache`:
52+
```js
53+
{
54+
"import": "the name of the package or library to import",
55+
"client": "the name of the API Client object to instanciate and import",
56+
"blocks": [{
57+
// The list of test to implement
58+
"operationID": "the name of the endpoint and the cts file to test",
59+
"tests": [{
60+
"testName": "the descriptive name test (default to `method`)"
61+
"method": "the method to call on the API Client",
62+
"parameters": {
63+
// Object of all parameters with their name, tobe used for languages that require the parameter name
64+
"parameterName": "value",
65+
...
66+
},
67+
"parametersArray": [
68+
// The same paremeters but passed as an array for other languages
69+
// It includes the `-last` properties used to join the parameters
70+
],
71+
"request": {
72+
"path": "the expected path of the request",
73+
"method": "the expected method: GET, POST, PUT, DELETE or PATCH",
74+
"data": {
75+
// The expected body of the request
76+
}
77+
}
78+
}]
79+
}]
80+
}
81+
```
82+
83+
## Get the list of remaining CTS to implement
84+
85+
To get the list of `operationId` not yet in the CTS but in the spec, run this command:
86+
```bash
87+
rm -rf ./specs/dist
88+
comm -3 <(grep -r operationId ./specs | awk -F: '{gsub(/ /,""); print $NF}' | sort) <(find ./tests/CTS/clients -type f -name '*.json' | awk -F/ '{gsub(/.json/,"");print $NF}' | sort)
89+
```

tests/CTS/clients/insights/pushEvents.json

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
[
22
{
33
"method": "pushEvents",
4-
"parameters": [
5-
{
6-
"insightEvents": {
7-
"events": [
8-
{
9-
"eventType": "click",
10-
"eventName": "Product Clicked",
11-
"index": "products",
12-
"userToken": "user-123456",
13-
"timestamp": 1641290601962,
14-
"objectIDs": ["9780545139700", "9780439784542"],
15-
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
16-
"positions": [7, 6]
17-
},
18-
{
19-
"eventType": "view",
20-
"eventName":"Product Detail Page Viewed",
21-
"index": "products",
22-
"userToken": "user-123456",
23-
"timestamp": 1641290601962,
24-
"objectIDs": ["9780545139700", "9780439784542"]
25-
},
26-
{
27-
"eventType": "conversion",
28-
"eventName": "Product Purchased",
29-
"index": "products",
30-
"userToken": "user-123456",
31-
"timestamp": 1641290601962,
32-
"objectIDs": ["9780545139700", "9780439784542"],
33-
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
34-
}
35-
]
36-
}
4+
"parameters": {
5+
"insightEvents": {
6+
"events": [
7+
{
8+
"eventType": "click",
9+
"eventName": "Product Clicked",
10+
"index": "products",
11+
"userToken": "user-123456",
12+
"timestamp": 1641290601962,
13+
"objectIDs": [
14+
"9780545139700",
15+
"9780439784542"
16+
],
17+
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
18+
"positions": [
19+
7,
20+
6
21+
]
22+
},
23+
{
24+
"eventType": "view",
25+
"eventName": "Product Detail Page Viewed",
26+
"index": "products",
27+
"userToken": "user-123456",
28+
"timestamp": 1641290601962,
29+
"objectIDs": [
30+
"9780545139700",
31+
"9780439784542"
32+
]
33+
},
34+
{
35+
"eventType": "conversion",
36+
"eventName": "Product Purchased",
37+
"index": "products",
38+
"userToken": "user-123456",
39+
"timestamp": 1641290601962,
40+
"objectIDs": [
41+
"9780545139700",
42+
"9780439784542"
43+
],
44+
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
45+
}
46+
]
3747
}
38-
],
48+
},
3949
"request": {
4050
"path": "/1/events",
4151
"method": "POST",
@@ -47,25 +57,37 @@
4757
"index": "products",
4858
"userToken": "user-123456",
4959
"timestamp": 1641290601962,
50-
"objectIDs": ["9780545139700", "9780439784542"],
60+
"objectIDs": [
61+
"9780545139700",
62+
"9780439784542"
63+
],
5164
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
52-
"positions": [7, 6]
65+
"positions": [
66+
7,
67+
6
68+
]
5369
},
5470
{
5571
"eventType": "view",
56-
"eventName":"Product Detail Page Viewed",
72+
"eventName": "Product Detail Page Viewed",
5773
"index": "products",
5874
"userToken": "user-123456",
5975
"timestamp": 1641290601962,
60-
"objectIDs": ["9780545139700", "9780439784542"]
76+
"objectIDs": [
77+
"9780545139700",
78+
"9780439784542"
79+
]
6180
},
6281
{
6382
"eventType": "conversion",
6483
"eventName": "Product Purchased",
6584
"index": "products",
6685
"userToken": "user-123456",
6786
"timestamp": 1641290601962,
68-
"objectIDs": ["9780545139700", "9780439784542"],
87+
"objectIDs": [
88+
"9780545139700",
89+
"9780439784542"
90+
],
6991
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
7092
}
7193
]

0 commit comments

Comments
 (0)