Skip to content

Commit a7089ae

Browse files
authored
feat(cts): add tests for analytics (#69)
1 parent f0d8b07 commit a7089ae

35 files changed

+1459
-31
lines changed

clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,12 @@ export type GetTopSearchesProps = {
16191619
clickAnalytics?: boolean;
16201620
startDate?: Date;
16211621
endDate?: Date;
1622-
orderBy?: Record<string, any>;
1623-
direction?: Record<string, any>;
1622+
orderBy?:
1623+
| 'averageClickPosition'
1624+
| 'clickThroughRate'
1625+
| 'conversionRate'
1626+
| 'searchCount';
1627+
direction?: 'asc' | 'desc';
16241628
limit?: number;
16251629
offset?: number;
16261630
tags?: string;

doc/CTS.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ And that's it! If the name of the file matches a real `operationId` in the spec,
4949
- Create a template in `test/CTS/templates/<your language>.mustache` that parse a array of test into your test framework of choice
5050

5151
When writing your template, here is a list of variables accessible from `mustache`:
52+
5253
```js
5354
{
5455
"import": "the name of the package or library to import",
@@ -60,14 +61,25 @@ When writing your template, here is a list of variables accessible from `mustach
6061
"testName": "the descriptive name test (default to `method`)"
6162
"method": "the method to call on the API Client",
6263
"parameters": {
63-
// Object of all parameters with their name, tobe used for languages that require the parameter name
64+
// Object of all parameters with their name, to be used for languages that require the parameter name
6465
"parameterName": "value",
6566
...
6667
},
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
68+
"parametersWithDataType": [
69+
{
70+
"key": "key",
71+
"value": "value",
72+
// booleans indicating the data type
73+
"isDate": "false",
74+
"isArray": "false",
75+
"isObject": "true",
76+
"isString": "false",
77+
// boolean indicating if it is the last parameter
78+
"-last": "false",
79+
}
7080
],
81+
// boolean indicating if the method has parameters, useful for `GET` requests
82+
"hasParameters": "true",
7183
"request": {
7284
"path": "the expected path of the request",
7385
"method": "the expected method: GET, POST, PUT, DELETE or PATCH",
@@ -83,6 +95,7 @@ When writing your template, here is a list of variables accessible from `mustach
8395
## Get the list of remaining CTS to implement
8496

8597
To get the list of `operationId` not yet in the CTS but in the spec, run this command:
98+
8699
```bash
87100
rm -rf ./specs/dist
88101
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)

playground/javascript/analytics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const client = new AnalyticsApi(appId, apiKey, 'de');
1414

1515
async function testAnalytics() {
1616
try {
17-
const res = await client.getSearchesNoResults({
17+
const res = await client.getTopFilterForAttribute({
18+
attribute: 'myAttribute1,myAttribute2',
1819
index: analyticsIndex,
1920
});
2021

playground/javascript/recommend.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ const client = new RecommendApi(appId, apiKey);
1818

1919
async function testRecommend() {
2020
try {
21-
const request = {
21+
const res = await client.getRecommendations({
2222
getRecommendations: {
2323
requests: [
2424
{
2525
indexName: searchIndex,
26-
model: RecommendationRequest.ModelEnum['BoughtTogether'],
26+
model: 'bought-together',
2727
objectID: searchQuery,
2828
threshold: 0,
2929
},
3030
],
3131
},
32-
};
33-
34-
const res = await client.getRecommendations(request);
32+
});
3533

3634
console.log(`[OK]`, res);
3735
} catch (e) {

specs/analytics/paths/common/parameters.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ OrderBy:
1313
name: orderBy
1414
description: Reorder the results.
1515
schema:
16+
type: string
1617
enum: [searchCount, clickThroughRate, conversionRate, averageClickPosition]
1718
default: searchCount
1819

@@ -21,6 +22,7 @@ Direction:
2122
name: direction
2223
description: The sorting of the result.
2324
schema:
25+
type: string
2426
enum: [asc, desc]
2527
default: asc
2628

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getAverageClickPosition",
4+
"testName": "get getAverageClickPosition with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/clicks/averageClickPosition",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getAverageClickPosition",
15+
"testName": "get getAverageClickPosition with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/clicks/averageClickPosition",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getClickPositions",
4+
"testName": "get getClickPositions with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/clicks/positions",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getClickPositions",
15+
"testName": "get getClickPositions with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/clicks/positions",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getClickThroughRate",
4+
"testName": "get getClickThroughRate with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/clicks/clickThroughRate",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getClickThroughRate",
15+
"testName": "get getClickThroughRate with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/clicks/clickThroughRate",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getConversationRate",
4+
"testName": "get getConversationRate with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/conversions/conversionRate",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getConversationRate",
15+
"testName": "get getConversationRate with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/conversions/conversionRate",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getNoClickRate",
4+
"testName": "get getNoClickRate with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/searches/noClickRate",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getNoClickRate",
15+
"testName": "get getNoClickRate with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/searches/noClickRate",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getNoResultsRate",
4+
"testName": "get getNoResultsRate with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/searches/noResultRate",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getNoResultsRate",
15+
"testName": "get getNoResultsRate with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/searches/noResultRate",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"method": "getSearchesCount",
4+
"testName": "get getSearchesCount with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/searches/count",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getSearchesCount",
15+
"testName": "get getSearchesCount with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"tags": "tag"
21+
},
22+
"request": {
23+
"path": "/2/searches/count",
24+
"method": "GET"
25+
}
26+
}
27+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[
2+
{
3+
"method": "getSearchesNoClicks",
4+
"testName": "get getSearchesNoClicks with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/searches/noClicks",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getSearchesNoClicks",
15+
"testName": "get getSearchesNoClicks with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"limit": 21,
21+
"offset": 42,
22+
"tags": "tag"
23+
},
24+
"request": {
25+
"path": "/2/searches/noClicks",
26+
"method": "GET"
27+
}
28+
}
29+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[
2+
{
3+
"method": "getSearchesNoResults",
4+
"testName": "get getSearchesNoResults with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/searches/noResults",
10+
"method": "GET"
11+
}
12+
},
13+
{
14+
"method": "getSearchesNoResults",
15+
"testName": "get getSearchesNoResults with all parameters",
16+
"parameters": {
17+
"index": "index",
18+
"startDate": "1999-09-19",
19+
"endDate": "2001-01-01",
20+
"limit": 21,
21+
"offset": 42,
22+
"tags": "tag"
23+
},
24+
"request": {
25+
"path": "/2/searches/noResults",
26+
"method": "GET"
27+
}
28+
}
29+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"method": "getStatus",
4+
"testName": "get getStatus with minimal parameters",
5+
"parameters": {
6+
"index": "index"
7+
},
8+
"request": {
9+
"path": "/2/status",
10+
"method": "GET"
11+
}
12+
}
13+
]

0 commit comments

Comments
 (0)