From 73e7f1ecf6e908c7059a018a9e743b7aa3745ada Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 14 Dec 2021 15:39:41 +0100 Subject: [PATCH 1/4] make testName optional --- .github/workflows/check.yml | 3 ++ doc/CTS.md | 2 +- .../CTS/clients/search/clearAllSynonyms.json | 1 - tests/CTS/clients/search/deleteSynonym.json | 1 - tests/CTS/clients/search/getSynonym.json | 1 - tests/CTS/clients/search/saveSynonym.json | 17 +++++++--- tests/CTS/clients/search/saveSynonyms.json | 33 ++++++++++++++----- tests/CTS/clients/search/search.json | 1 - tests/CTS/clients/search/searchSynonyms.json | 1 - tests/CTS/templates/javascript.mustache | 2 +- tests/generateCTS.ts | 10 ++++-- 11 files changed, 48 insertions(+), 24 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index edf70c449e..a772c251f8 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -80,5 +80,8 @@ jobs: - name: Generate CTS run: yarn cts:generate + - name: Check commited generation + run: git status --porcelain + - name: Run CTS run: yarn cts:test diff --git a/doc/CTS.md b/doc/CTS.md index 7abc99681e..b5fb67e974 100644 --- a/doc/CTS.md +++ b/doc/CTS.md @@ -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", diff --git a/tests/CTS/clients/search/clearAllSynonyms.json b/tests/CTS/clients/search/clearAllSynonyms.json index a1d6dbb09e..aef6c4f841 100644 --- a/tests/CTS/clients/search/clearAllSynonyms.json +++ b/tests/CTS/clients/search/clearAllSynonyms.json @@ -1,6 +1,5 @@ [ { - "testName": "clearAllSynonyms", "method": "clearAllSynonyms", "parameters": [ "indexName" diff --git a/tests/CTS/clients/search/deleteSynonym.json b/tests/CTS/clients/search/deleteSynonym.json index 7e0d7d698b..dd4ded6712 100644 --- a/tests/CTS/clients/search/deleteSynonym.json +++ b/tests/CTS/clients/search/deleteSynonym.json @@ -1,6 +1,5 @@ [ { - "testName": "deleteSynonym", "method": "deleteSynonym", "parameters": [ "indexName", diff --git a/tests/CTS/clients/search/getSynonym.json b/tests/CTS/clients/search/getSynonym.json index 53a36a3f2a..d9744d14e6 100644 --- a/tests/CTS/clients/search/getSynonym.json +++ b/tests/CTS/clients/search/getSynonym.json @@ -1,6 +1,5 @@ [ { - "testName": "getSynonym", "method": "getSynonym", "parameters": [ "indexName", diff --git a/tests/CTS/clients/search/saveSynonym.json b/tests/CTS/clients/search/saveSynonym.json index ecec571c2e..b09dac23cd 100644 --- a/tests/CTS/clients/search/saveSynonym.json +++ b/tests/CTS/clients/search/saveSynonym.json @@ -1,14 +1,17 @@ [ { - "testName": "saveSynonym", "method": "saveSynonym", "parameters": [ "indexName", "id1", { - "objectID" : "id1", + "objectID": "id1", "type": "synonym", - "synonyms": ["car", "vehicule", "auto"] + "synonyms": [ + "car", + "vehicule", + "auto" + ] }, true ], @@ -16,9 +19,13 @@ "path": "/1/indexes/indexName/synonyms/id1", "method": "PUT", "data": { - "objectID" : "id1", + "objectID": "id1", "type": "synonym", - "synonyms": ["car", "vehicule", "auto"] + "synonyms": [ + "car", + "vehicule", + "auto" + ] } } } diff --git a/tests/CTS/clients/search/saveSynonyms.json b/tests/CTS/clients/search/saveSynonyms.json index 531ed9e517..3823d93b44 100644 --- a/tests/CTS/clients/search/saveSynonyms.json +++ b/tests/CTS/clients/search/saveSynonyms.json @@ -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, @@ -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" + ] } ] } diff --git a/tests/CTS/clients/search/search.json b/tests/CTS/clients/search/search.json index 8e0eac0e92..0ce82a8ef1 100644 --- a/tests/CTS/clients/search/search.json +++ b/tests/CTS/clients/search/search.json @@ -1,6 +1,5 @@ [ { - "testName": "search", "method": "search", "parameters": [ "indexName", diff --git a/tests/CTS/clients/search/searchSynonyms.json b/tests/CTS/clients/search/searchSynonyms.json index 3836ec7860..758967861f 100644 --- a/tests/CTS/clients/search/searchSynonyms.json +++ b/tests/CTS/clients/search/searchSynonyms.json @@ -1,6 +1,5 @@ [ { - "testName": "searchSynonyms", "method": "searchSynonyms", "parameters": [ "indexName", diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index a9279f15c4..68fdf74ac2 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -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}} }) }); diff --git a/tests/generateCTS.ts b/tests/generateCTS.ts index de22b9180e..b7aaa437e0 100644 --- a/tests/generateCTS.ts +++ b/tests/generateCTS.ts @@ -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; }; }; @@ -90,8 +90,12 @@ async function loadCTSForClient(client: string): Promise { ); } - // 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; From a0c24f4187f753593afcd39997af00ed8f22d889 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 14 Dec 2021 15:48:23 +0100 Subject: [PATCH 2/4] check if the cts was correctly generated --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a772c251f8..c485f1a101 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -81,7 +81,7 @@ jobs: run: yarn cts:generate - name: Check commited generation - run: git status --porcelain + run: git diff --exit-code - name: Run CTS run: yarn cts:test From 9bc7079bc6632add91fb170c2121197968b4cc2c Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 14 Dec 2021 15:59:58 +0100 Subject: [PATCH 3/4] generate cts --- tests/output/javascript/search.test.ts | 39 +++++++++++--------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/tests/output/javascript/search.test.ts b/tests/output/javascript/search.test.ts index fee71e30f6..30891f9aca 100644 --- a/tests/output/javascript/search.test.ts +++ b/tests/output/javascript/search.test.ts @@ -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'], + }, + ], }); }); @@ -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'], }, }); }); From cc2223e601d00fc5b9f721538264dde92e149e00 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Tue, 14 Dec 2021 16:23:27 +0100 Subject: [PATCH 4/4] remove git diff --- .github/workflows/check.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c485f1a101..edf70c449e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -80,8 +80,5 @@ jobs: - name: Generate CTS run: yarn cts:generate - - name: Check commited generation - run: git diff --exit-code - - name: Run CTS run: yarn cts:test