Skip to content

Commit

Permalink
fix(cts): make the testName optional APIC-226 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Dec 14, 2021
1 parent a8af9b1 commit fba3068
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion doc/CTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The test generation script requires a JSON file name from the `operationId` (e.g
```json
[
{
"testName": "the name of the test (e.g. test('search endpoint'))",
"testName": "the name of the test (e.g. test('search endpoint')) (default: 'method')",
"method": "the method to call (e.g. search)",
"parameters": [
"indexName",
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/clients/search/clearAllSynonyms.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"testName": "clearAllSynonyms",
"method": "clearAllSynonyms",
"parameters": [
"indexName"
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/clients/search/deleteSynonym.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"testName": "deleteSynonym",
"method": "deleteSynonym",
"parameters": [
"indexName",
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/clients/search/getSynonym.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"testName": "getSynonym",
"method": "getSynonym",
"parameters": [
"indexName",
Expand Down
17 changes: 12 additions & 5 deletions tests/CTS/clients/search/saveSynonym.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
[
{
"testName": "saveSynonym",
"method": "saveSynonym",
"parameters": [
"indexName",
"id1",
{
"objectID" : "id1",
"objectID": "id1",
"type": "synonym",
"synonyms": ["car", "vehicule", "auto"]
"synonyms": [
"car",
"vehicule",
"auto"
]
},
true
],
"request": {
"path": "/1/indexes/indexName/synonyms/id1",
"method": "PUT",
"data": {
"objectID" : "id1",
"objectID": "id1",
"type": "synonym",
"synonyms": ["car", "vehicule", "auto"]
"synonyms": [
"car",
"vehicule",
"auto"
]
}
}
}
Expand Down
33 changes: 24 additions & 9 deletions tests/CTS/clients/search/saveSynonyms.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
[
{
"testName": "saveSynonyms",
"method": "saveSynonyms",
"parameters": [
"indexName",
[
{
"objectID" : "id1",
"objectID": "id1",
"type": "synonym",
"synonyms": ["car", "vehicule", "auto"]
"synonyms": [
"car",
"vehicule",
"auto"
]
},
{
"objectID" : "id2",
"objectID": "id2",
"type": "onewaysynonym",
"input": "iphone",
"synonyms": ["ephone", "aphone", "yphone"]
"synonyms": [
"ephone",
"aphone",
"yphone"
]
}
],
true,
Expand All @@ -25,15 +32,23 @@
"method": "POST",
"data": [
{
"objectID" : "id1",
"objectID": "id1",
"type": "synonym",
"synonyms": ["car", "vehicule", "auto"]
"synonyms": [
"car",
"vehicule",
"auto"
]
},
{
"objectID" : "id2",
"objectID": "id2",
"type": "onewaysynonym",
"input": "iphone",
"synonyms": ["ephone", "aphone", "yphone"]
"synonyms": [
"ephone",
"aphone",
"yphone"
]
}
]
}
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/clients/search/search.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"testName": "search",
"method": "search",
"parameters": [
"indexName",
Expand Down
1 change: 0 additions & 1 deletion tests/CTS/clients/search/searchSynonyms.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
{
"testName": "searchSynonyms",
"method": "searchSynonyms",
"parameters": [
"indexName",
Expand Down
2 changes: 1 addition & 1 deletion tests/CTS/templates/javascript.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Common Test Suite', () => {
expect(req).toMatchObject({
path: '{{{request.path}}}',
method: '{{{request.method}}}',
{{#request.data}}data: {{{request.data}}},{{/request.data}}
{{#request.data}}data: {{{.}}},{{/request.data}}
})
});

Expand Down
10 changes: 7 additions & 3 deletions tests/generateCTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const availableLanguages = ['javascript'] as const;
type Language = typeof availableLanguages[number];

type CTSBlock = {
name: string;
testName?: string;
method: string;
parameters: any[];
request: {
path: string;
method: string;
data: string;
data?: string;
};
};

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

// for now we stringify all params for mustache to render them properly
for (const test of tests) {
if (test.testName === undefined) {
test.testName = test.method;
}

// for now we stringify all params for mustache to render them properly
for (let i = 0; i < test.parameters.length; i++) {
// delete the object name for now, but it could be use for `new $objectName(params)`
delete test.parameters[i].$objectName;
Expand Down
39 changes: 16 additions & 23 deletions tests/output/javascript/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,19 @@ describe('Common Test Suite', () => {
expect(req).toMatchObject({
path: '/1/indexes/indexName/synonyms/batch',
method: 'POST',
data: {
synonymHit: [
{
objectID: 'id1',
type: 'synonym',
synonyms: ['car', 'vehicule', 'auto'],
},
{
objectID: 'id2',
type: 'onewaysynonym',
input: 'iphone',
synonyms: ['ephone', 'aphone', 'yphone'],
},
],
ForwardToReplicas: true,
ReplaceExistingSynonyms: false,
},
data: [
{
objectID: 'id1',
type: 'synonym',
synonyms: ['car', 'vehicule', 'auto'],
},
{
objectID: 'id2',
type: 'onewaysynonym',
input: 'iphone',
synonyms: ['ephone', 'aphone', 'yphone'],
},
],
});
});

Expand Down Expand Up @@ -110,12 +106,9 @@ describe('Common Test Suite', () => {
path: '/1/indexes/indexName/synonyms/id1',
method: 'PUT',
data: {
synonymHit: {
objectID: 'id1',
type: 'synonym',
synonyms: ['car', 'vehicule', 'auto'],
},
ForwardToReplicas: true,
objectID: 'id1',
type: 'synonym',
synonyms: ['car', 'vehicule', 'auto'],
},
});
});
Expand Down

0 comments on commit fba3068

Please sign in to comment.