Skip to content

Commit

Permalink
fix: use object for CTS parameters (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 6, 2022
1 parent aa0715f commit 1ab7acc
Show file tree
Hide file tree
Showing 32 changed files with 589 additions and 409 deletions.
54 changes: 47 additions & 7 deletions doc/CTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ The test generation script requires a JSON file name from the `operationId` (e.g
{
"testName": "the name of the test (e.g. test('search endpoint')) (default: 'method')",
"method": "the method to call (e.g. search)",
"parameters": [
"indexName",
{
"$objectName": "the name of the object for strongly type language",
"parameters": {
"indexName": "testIndex",
"searchParam": {
"$objectName": "the name of the object for strongly type language, should be on every 'object' type",
"query": "the string to search"
}
],
},
"request": {
"path": "/1/indexes/indexName/query",
"path": "/1/indexes/testIndex/query",
"method": "POST",
"data": { "query": "the string to search" }
}
Expand All @@ -45,5 +45,45 @@ And that's it! If the name of the file matches a real `operationId` in the spec,

## How to add a new language

- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice
- Add the language in the array `languages` in `tests/generateCTS.ts`.
- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice

When writing your template, here is a list of variables accessible from `mustache`:
```js
{
"import": "the name of the package or library to import",
"client": "the name of the API Client object to instanciate and import",
"blocks": [{
// The list of test to implement
"operationID": "the name of the endpoint and the cts file to test",
"tests": [{
"testName": "the descriptive name test (default to `method`)"
"method": "the method to call on the API Client",
"parameters": {
// Object of all parameters with their name, tobe used for languages that require the parameter name
"parameterName": "value",
...
},
"parametersArray": [
// The same paremeters but passed as an array for other languages
// It includes the `-last` properties used to join the parameters
],
"request": {
"path": "the expected path of the request",
"method": "the expected method: GET, POST, PUT, DELETE or PATCH",
"data": {
// The expected body of the request
}
}
}]
}]
}
```

## Get the list of remaining CTS to implement

To get the list of `operationId` not yet in the CTS but in the spec, run this command:
```bash
rm -rf ./specs/dist
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)
```
100 changes: 61 additions & 39 deletions tests/CTS/clients/insights/pushEvents.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
[
{
"method": "pushEvents",
"parameters": [
{
"insightEvents": {
"events": [
{
"eventType": "click",
"eventName": "Product Clicked",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"positions": [7, 6]
},
{
"eventType": "view",
"eventName":"Product Detail Page Viewed",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"]
},
{
"eventType": "conversion",
"eventName": "Product Purchased",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
}
]
}
"parameters": {
"insightEvents": {
"events": [
{
"eventType": "click",
"eventName": "Product Clicked",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": [
"9780545139700",
"9780439784542"
],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"positions": [
7,
6
]
},
{
"eventType": "view",
"eventName": "Product Detail Page Viewed",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": [
"9780545139700",
"9780439784542"
]
},
{
"eventType": "conversion",
"eventName": "Product Purchased",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": [
"9780545139700",
"9780439784542"
],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
}
]
}
],
},
"request": {
"path": "/1/events",
"method": "POST",
Expand All @@ -47,25 +57,37 @@
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"],
"objectIDs": [
"9780545139700",
"9780439784542"
],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"positions": [7, 6]
"positions": [
7,
6
]
},
{
"eventType": "view",
"eventName":"Product Detail Page Viewed",
"eventName": "Product Detail Page Viewed",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"]
"objectIDs": [
"9780545139700",
"9780439784542"
]
},
{
"eventType": "conversion",
"eventName": "Product Purchased",
"index": "products",
"userToken": "user-123456",
"timestamp": 1641290601962,
"objectIDs": ["9780545139700", "9780439784542"],
"objectIDs": [
"9780545139700",
"9780439784542"
],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
}
]
Expand Down
Loading

0 comments on commit 1ab7acc

Please sign in to comment.