Skip to content

Commit fba3068

Browse files
authored
fix(cts): make the testName optional APIC-226 (#37)
1 parent a8af9b1 commit fba3068

11 files changed

+61
-47
lines changed

doc/CTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The test generation script requires a JSON file name from the `operationId` (e.g
2323
```json
2424
[
2525
{
26-
"testName": "the name of the test (e.g. test('search endpoint'))",
26+
"testName": "the name of the test (e.g. test('search endpoint')) (default: 'method')",
2727
"method": "the method to call (e.g. search)",
2828
"parameters": [
2929
"indexName",

tests/CTS/clients/search/clearAllSynonyms.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"testName": "clearAllSynonyms",
43
"method": "clearAllSynonyms",
54
"parameters": [
65
"indexName"

tests/CTS/clients/search/deleteSynonym.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"testName": "deleteSynonym",
43
"method": "deleteSynonym",
54
"parameters": [
65
"indexName",

tests/CTS/clients/search/getSynonym.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"testName": "getSynonym",
43
"method": "getSynonym",
54
"parameters": [
65
"indexName",

tests/CTS/clients/search/saveSynonym.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
[
22
{
3-
"testName": "saveSynonym",
43
"method": "saveSynonym",
54
"parameters": [
65
"indexName",
76
"id1",
87
{
9-
"objectID" : "id1",
8+
"objectID": "id1",
109
"type": "synonym",
11-
"synonyms": ["car", "vehicule", "auto"]
10+
"synonyms": [
11+
"car",
12+
"vehicule",
13+
"auto"
14+
]
1215
},
1316
true
1417
],
1518
"request": {
1619
"path": "/1/indexes/indexName/synonyms/id1",
1720
"method": "PUT",
1821
"data": {
19-
"objectID" : "id1",
22+
"objectID": "id1",
2023
"type": "synonym",
21-
"synonyms": ["car", "vehicule", "auto"]
24+
"synonyms": [
25+
"car",
26+
"vehicule",
27+
"auto"
28+
]
2229
}
2330
}
2431
}

tests/CTS/clients/search/saveSynonyms.json

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
[
22
{
3-
"testName": "saveSynonyms",
43
"method": "saveSynonyms",
54
"parameters": [
65
"indexName",
76
[
87
{
9-
"objectID" : "id1",
8+
"objectID": "id1",
109
"type": "synonym",
11-
"synonyms": ["car", "vehicule", "auto"]
10+
"synonyms": [
11+
"car",
12+
"vehicule",
13+
"auto"
14+
]
1215
},
1316
{
14-
"objectID" : "id2",
17+
"objectID": "id2",
1518
"type": "onewaysynonym",
1619
"input": "iphone",
17-
"synonyms": ["ephone", "aphone", "yphone"]
20+
"synonyms": [
21+
"ephone",
22+
"aphone",
23+
"yphone"
24+
]
1825
}
1926
],
2027
true,
@@ -25,15 +32,23 @@
2532
"method": "POST",
2633
"data": [
2734
{
28-
"objectID" : "id1",
35+
"objectID": "id1",
2936
"type": "synonym",
30-
"synonyms": ["car", "vehicule", "auto"]
37+
"synonyms": [
38+
"car",
39+
"vehicule",
40+
"auto"
41+
]
3142
},
3243
{
33-
"objectID" : "id2",
44+
"objectID": "id2",
3445
"type": "onewaysynonym",
3546
"input": "iphone",
36-
"synonyms": ["ephone", "aphone", "yphone"]
47+
"synonyms": [
48+
"ephone",
49+
"aphone",
50+
"yphone"
51+
]
3752
}
3853
]
3954
}

tests/CTS/clients/search/search.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"testName": "search",
43
"method": "search",
54
"parameters": [
65
"indexName",

tests/CTS/clients/search/searchSynonyms.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
{
3-
"testName": "searchSynonyms",
43
"method": "searchSynonyms",
54
"parameters": [
65
"indexName",

tests/CTS/templates/javascript.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Common Test Suite', () => {
1010
expect(req).toMatchObject({
1111
path: '{{{request.path}}}',
1212
method: '{{{request.method}}}',
13-
{{#request.data}}data: {{{request.data}}},{{/request.data}}
13+
{{#request.data}}data: {{{.}}},{{/request.data}}
1414
})
1515
});
1616

tests/generateCTS.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const availableLanguages = ['javascript'] as const;
1212
type Language = typeof availableLanguages[number];
1313

1414
type CTSBlock = {
15-
name: string;
15+
testName?: string;
1616
method: string;
1717
parameters: any[];
1818
request: {
1919
path: string;
2020
method: string;
21-
data: string;
21+
data?: string;
2222
};
2323
};
2424

@@ -90,8 +90,12 @@ async function loadCTSForClient(client: string): Promise<CTSBlock[]> {
9090
);
9191
}
9292

93-
// for now we stringify all params for mustache to render them properly
9493
for (const test of tests) {
94+
if (test.testName === undefined) {
95+
test.testName = test.method;
96+
}
97+
98+
// for now we stringify all params for mustache to render them properly
9599
for (let i = 0; i < test.parameters.length; i++) {
96100
// delete the object name for now, but it could be use for `new $objectName(params)`
97101
delete test.parameters[i].$objectName;

tests/output/javascript/search.test.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,19 @@ describe('Common Test Suite', () => {
4242
expect(req).toMatchObject({
4343
path: '/1/indexes/indexName/synonyms/batch',
4444
method: 'POST',
45-
data: {
46-
synonymHit: [
47-
{
48-
objectID: 'id1',
49-
type: 'synonym',
50-
synonyms: ['car', 'vehicule', 'auto'],
51-
},
52-
{
53-
objectID: 'id2',
54-
type: 'onewaysynonym',
55-
input: 'iphone',
56-
synonyms: ['ephone', 'aphone', 'yphone'],
57-
},
58-
],
59-
ForwardToReplicas: true,
60-
ReplaceExistingSynonyms: false,
61-
},
45+
data: [
46+
{
47+
objectID: 'id1',
48+
type: 'synonym',
49+
synonyms: ['car', 'vehicule', 'auto'],
50+
},
51+
{
52+
objectID: 'id2',
53+
type: 'onewaysynonym',
54+
input: 'iphone',
55+
synonyms: ['ephone', 'aphone', 'yphone'],
56+
},
57+
],
6258
});
6359
});
6460

@@ -110,12 +106,9 @@ describe('Common Test Suite', () => {
110106
path: '/1/indexes/indexName/synonyms/id1',
111107
method: 'PUT',
112108
data: {
113-
synonymHit: {
114-
objectID: 'id1',
115-
type: 'synonym',
116-
synonyms: ['car', 'vehicule', 'auto'],
117-
},
118-
ForwardToReplicas: true,
109+
objectID: 'id1',
110+
type: 'synonym',
111+
synonyms: ['car', 'vehicule', 'auto'],
119112
},
120113
});
121114
});

0 commit comments

Comments
 (0)