From a56fbab5b8041f5787a7c8914e6fd566a4638a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Thu, 31 Mar 2022 14:16:05 +0200 Subject: [PATCH 1/8] feat(cts): add custom request tests --- .../codegen/cts/AlgoliaCtsGenerator.java | 17 ++ .../codegen/cts/ParametersWithDataType.java | 43 ++- tests/CTS/methods/requests/common/del.json | 36 +++ tests/CTS/methods/requests/common/get.json | 30 ++ tests/CTS/methods/requests/common/post.json | 36 +++ tests/CTS/methods/requests/common/put.json | 36 +++ .../requests/templates/java/requests.mustache | 4 +- .../algolia/methods/requests/search.test.java | 273 ++++++++++++++++-- .../src/methods/requests/abtesting.test.ts | 103 +++++++ .../src/methods/requests/analytics.test.ts | 103 +++++++ .../src/methods/requests/insights.test.ts | 103 +++++++ .../methods/requests/personalization.test.ts | 103 +++++++ .../requests/query-suggestions.test.ts | 103 +++++++ .../src/methods/requests/recommend.test.ts | 103 +++++++ .../src/methods/requests/search.test.ts | 103 +++++++ .../src/methods/requests/sources.test.ts | 103 +++++++ 16 files changed, 1264 insertions(+), 35 deletions(-) create mode 100644 tests/CTS/methods/requests/common/del.json create mode 100644 tests/CTS/methods/requests/common/get.json create mode 100644 tests/CTS/methods/requests/common/post.json create mode 100644 tests/CTS/methods/requests/common/put.json diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index b4e88bfc27..1d277e3f69 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableMap.Builder; import com.samskivert.mustache.Mustache.Lambda; import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.media.Schema; import java.io.File; import java.io.IOException; import java.util.*; @@ -170,6 +171,9 @@ public Map postProcessSupportingFileData( System.out.println(e.getMessage()); System.exit(0); } + + System.out.println(e.getMessage()); + System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); @@ -181,15 +185,28 @@ private Map loadCTS() throws JsonParseException, JsonMappingException, IOException, CTSException { TreeMap cts = new TreeMap<>(); File dir = new File("tests/CTS/methods/requests/" + client); + File commonTestDir = new File("tests/CTS/methods/requests/common"); if (!dir.exists()) { throw new CTSException("CTS not found at " + dir.getAbsolutePath(), true); } + if (!commonTestDir.exists()) { + throw new CTSException( + "CTS not found at " + commonTestDir.getAbsolutePath(), + true + ); + } for (File f : dir.listFiles()) { cts.put( f.getName().replace(".json", ""), Json.mapper().readValue(f, Request[].class) ); } + for (File f : commonTestDir.listFiles()) { + cts.put( + f.getName().replace(".json", ""), + Json.mapper().readValue(f, Request[].class) + ); + } return cts; } diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index ae4ade5780..9c247f4c83 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -200,8 +200,13 @@ private void handleModel( String parent, int suffix ) throws CTSException { - assert (spec.getHasVars()); - assert (spec.getItems() == null); + if (!spec.getHasVars()) { + throw new CTSException("Spec has no vars."); + } + + if (spec.getItems() != null) { + throw new CTSException("Spec has items."); + } if ( spec instanceof CodegenModel && ((CodegenModel) spec).oneOf.size() > 0 @@ -269,8 +274,13 @@ private void handleObject( IJsonSchemaValidationProperties spec, int suffix ) throws CTSException { - assert (!spec.getHasVars()); - assert (spec.getItems() == null); + if (spec.getHasVars()) { + throw new CTSException("Spec has vars."); + } + + if (spec.getItems() != null) { + throw new CTSException("Spec has items."); + } Map vars = (Map) param; @@ -300,18 +310,37 @@ private void handleMap( IJsonSchemaValidationProperties spec, int suffix ) throws CTSException { - assert (!spec.getHasVars()); - assert (spec.getItems() != null); + if (spec.getHasVars()) { + throw new CTSException("Spec has vars."); + } Map vars = (Map) param; List values = new ArrayList<>(); + + CodegenProperty items = spec.getItems(); + for (Entry entry : vars.entrySet()) { + IJsonSchemaValidationProperties itemType = items; + + // The generator consider a free form object type as an `object`, which + // is wrong in our case, so we infer it. + if ( + items == null || + (items.openApiType.equals("object") && items.isFreeFormObject) + ) { + CodegenParameter maybeMatch = new CodegenParameter(); + String paramType = inferDataType(entry.getValue(), maybeMatch, null); + + maybeMatch.dataType = paramType; + itemType = maybeMatch; + } + values.add( traverseParams( entry.getKey(), entry.getValue(), - spec.getItems(), + itemType, paramName, suffix + 1 ) diff --git a/tests/CTS/methods/requests/common/del.json b/tests/CTS/methods/requests/common/del.json new file mode 100644 index 0000000000..8e9e368194 --- /dev/null +++ b/tests/CTS/methods/requests/common/del.json @@ -0,0 +1,36 @@ +[ + { + "method": "del", + "testName": "allow del method for a custom path with minimal parameters", + "parameters": { + "path": "/test/minimal" + }, + "request": { + "path": "/1/test/minimal", + "method": "DELETE" + } + }, + { + "method": "del", + "testName": "allow del method for a custom path with all parameters", + "parameters": { + "path": "/test/all", + "parameters": { + "query": "parameters" + }, + "body": { + "body": "parameters" + } + }, + "request": { + "path": "/1/test/all", + "method": "DELETE", + "data": { + "body": "parameters" + }, + "searchParams": { + "query": "parameters" + } + } + } +] diff --git a/tests/CTS/methods/requests/common/get.json b/tests/CTS/methods/requests/common/get.json new file mode 100644 index 0000000000..50834e8318 --- /dev/null +++ b/tests/CTS/methods/requests/common/get.json @@ -0,0 +1,30 @@ +[ + { + "method": "get", + "testName": "allow get method for a custom path with minimal parameters", + "parameters": { + "path": "/test/minimal" + }, + "request": { + "path": "/1/test/minimal", + "method": "GET" + } + }, + { + "method": "get", + "testName": "allow get method for a custom path with all parameters", + "parameters": { + "path": "/test/all", + "parameters": { + "query": "parameters" + } + }, + "request": { + "path": "/1/test/all", + "method": "GET", + "searchParams": { + "query": "parameters" + } + } + } +] diff --git a/tests/CTS/methods/requests/common/post.json b/tests/CTS/methods/requests/common/post.json new file mode 100644 index 0000000000..931b06b532 --- /dev/null +++ b/tests/CTS/methods/requests/common/post.json @@ -0,0 +1,36 @@ +[ + { + "method": "post", + "testName": "allow post method for a custom path with minimal parameters", + "parameters": { + "path": "/test/minimal" + }, + "request": { + "path": "/1/test/minimal", + "method": "POST" + } + }, + { + "method": "post", + "testName": "allow post method for a custom path with all parameters", + "parameters": { + "path": "/test/all", + "parameters": { + "query": "parameters" + }, + "body": { + "body": "parameters" + } + }, + "request": { + "path": "/1/test/all", + "method": "POST", + "data": { + "body": "parameters" + }, + "searchParams": { + "query": "parameters" + } + } + } +] diff --git a/tests/CTS/methods/requests/common/put.json b/tests/CTS/methods/requests/common/put.json new file mode 100644 index 0000000000..dfffd8577a --- /dev/null +++ b/tests/CTS/methods/requests/common/put.json @@ -0,0 +1,36 @@ +[ + { + "method": "put", + "testName": "allow put method for a custom path with minimal parameters", + "parameters": { + "path": "/test/minimal" + }, + "request": { + "path": "/1/test/minimal", + "method": "PUT" + } + }, + { + "method": "put", + "testName": "allow put method for a custom path with all parameters", + "parameters": { + "path": "/test/all", + "parameters": { + "query": "parameters" + }, + "body": { + "body": "parameters" + } + }, + "request": { + "path": "/1/test/all", + "method": "PUT", + "data": { + "body": "parameters" + }, + "searchParams": { + "query": "parameters" + } + } + } +] diff --git a/tests/CTS/methods/requests/templates/java/requests.mustache b/tests/CTS/methods/requests/templates/java/requests.mustache index 9e5b990d18..47318abbe7 100644 --- a/tests/CTS/methods/requests/templates/java/requests.mustache +++ b/tests/CTS/methods/requests/templates/java/requests.mustache @@ -50,8 +50,8 @@ class {{client}}Tests { {{#request.searchParams}} HashMap expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.searchParams}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } {{/request.searchParams}} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index a8940c1571..f839a870e4 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -172,8 +172,8 @@ void assignUserIdTest0() { "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -271,8 +271,8 @@ void batchAssignUserIdsTest0() { "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -602,8 +602,8 @@ void batchRulesTest0() { "{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -696,6 +696,65 @@ void clearRulesTest0() { assertEquals(req.getMethod(), "POST"); } + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + HashMap parameters0 = new HashMap(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + HashMap body0 = new HashMap(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + HashMap expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { + assertEquals(expectedQuery.get(p.getName()), p.getValue()); + } + } + @Test @DisplayName("deleteApiKey") void deleteApiKeyTest0() { @@ -818,6 +877,50 @@ void deleteSynonymTest0() { assertEquals(req.getMethod(), "DELETE"); } + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + HashMap parameters0 = new HashMap(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + HashMap expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { + assertEquals(expectedQuery.get(p.getName()), p.getValue()); + } + } + @Test @DisplayName("getApiKey") void getApiKeyTest0() { @@ -879,8 +982,8 @@ void getLogsTest0() { "{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -914,8 +1017,8 @@ void getObjectTest0() { "{\"attributesToRetrieve\":\"attr1,attr2\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1087,8 +1190,8 @@ void hasPendingMappingsTest0() { "{\"getClusters\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1134,8 +1237,8 @@ void listIndicesTest0() { "{\"page\":\"8\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1159,8 +1262,8 @@ void listUserIdsTest0() { "{\"page\":\"8\",\"hitsPerPage\":\"100\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1370,8 +1473,126 @@ void partialUpdateObjectTest0() { "{\"createIfNotExists\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { + assertEquals(expectedQuery.get(p.getName()), p.getValue()); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + HashMap parameters0 = new HashMap(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + HashMap body0 = new HashMap(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + HashMap expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { + assertEquals(expectedQuery.get(p.getName()), p.getValue()); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + HashMap parameters0 = new HashMap(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + HashMap body0 = new HashMap(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + HashMap expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1540,8 +1761,8 @@ void saveRuleTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1606,8 +1827,8 @@ void saveSynonymTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -1706,8 +1927,8 @@ void saveSynonymsTest0() { "{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } @@ -2102,8 +2323,8 @@ void setSettingsTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - List acutalQuery = req.getQueryParams(); - for (Pair p : acutalQuery) { + List actualQuery = req.getQueryParams(); + for (Pair p : actualQuery) { assertEquals(expectedQuery.get(p.getName()), p.getValue()); } } diff --git a/tests/output/javascript/src/methods/requests/abtesting.test.ts b/tests/output/javascript/src/methods/requests/abtesting.test.ts index 1209c77d27..095021a692 100644 --- a/tests/output/javascript/src/methods/requests/abtesting.test.ts +++ b/tests/output/javascript/src/methods/requests/abtesting.test.ts @@ -34,6 +34,32 @@ describe('addABTests', () => { }); }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteABTest', () => { test('deleteABTest', async () => { const req = (await client.deleteABTest({ @@ -47,6 +73,31 @@ describe('deleteABTest', () => { }); }); +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getABTest', () => { test('getABTest', async () => { const req = (await client.getABTest({ id: 42 })) as unknown as EchoResponse; @@ -72,6 +123,58 @@ describe('listABTests', () => { }); }); +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('stopABTest', () => { test('stopABTest', async () => { const req = (await client.stopABTest({ diff --git a/tests/output/javascript/src/methods/requests/analytics.test.ts b/tests/output/javascript/src/methods/requests/analytics.test.ts index 7b48696c3a..b183b75200 100644 --- a/tests/output/javascript/src/methods/requests/analytics.test.ts +++ b/tests/output/javascript/src/methods/requests/analytics.test.ts @@ -9,6 +9,57 @@ const client = analyticsApi(appId, apiKey, 'us', { requester: echoRequester(), }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getAverageClickPosition', () => { test('get getAverageClickPosition with minimal parameters', async () => { const req = (await client.getAverageClickPosition({ @@ -621,3 +672,55 @@ describe('getUsersCount', () => { }); }); }); + +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); diff --git a/tests/output/javascript/src/methods/requests/insights.test.ts b/tests/output/javascript/src/methods/requests/insights.test.ts index af2488fb82..59ae38b3d4 100644 --- a/tests/output/javascript/src/methods/requests/insights.test.ts +++ b/tests/output/javascript/src/methods/requests/insights.test.ts @@ -7,6 +7,83 @@ const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; const client = insightsApi(appId, apiKey, 'us', { requester: echoRequester() }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('pushEvents', () => { test('pushEvents', async () => { const req = (await client.pushEvents({ @@ -77,3 +154,29 @@ describe('pushEvents', () => { expect(req.searchParams).toEqual(undefined); }); }); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); diff --git a/tests/output/javascript/src/methods/requests/personalization.test.ts b/tests/output/javascript/src/methods/requests/personalization.test.ts index 179238c9a7..e85ed804ec 100644 --- a/tests/output/javascript/src/methods/requests/personalization.test.ts +++ b/tests/output/javascript/src/methods/requests/personalization.test.ts @@ -9,6 +9,32 @@ const client = personalizationApi(appId, apiKey, 'us', { requester: echoRequester(), }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteUserProfile', () => { test('delete deleteUserProfile', async () => { const req = (await client.deleteUserProfile({ @@ -22,6 +48,31 @@ describe('deleteUserProfile', () => { }); }); +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getPersonalizationStrategy', () => { test('get getPersonalizationStrategy', async () => { const req = @@ -47,6 +98,58 @@ describe('getUserTokenProfile', () => { }); }); +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('setPersonalizationStrategy', () => { test('set setPersonalizationStrategy', async () => { const req = (await client.setPersonalizationStrategy({ diff --git a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts index 1fcf6a3033..e2c75f93a1 100644 --- a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts +++ b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts @@ -42,6 +42,32 @@ describe('createConfig', () => { }); }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteConfig', () => { test('deleteConfig', async () => { const req = (await client.deleteConfig({ @@ -55,6 +81,31 @@ describe('deleteConfig', () => { }); }); +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getAllConfigs', () => { test('getAllConfigs', async () => { const req = (await client.getAllConfigs()) as unknown as EchoResponse; @@ -105,6 +156,58 @@ describe('getLogFile', () => { }); }); +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('updateConfig', () => { test('updateConfig', async () => { const req = (await client.updateConfig({ diff --git a/tests/output/javascript/src/methods/requests/recommend.test.ts b/tests/output/javascript/src/methods/requests/recommend.test.ts index 8f7ca89789..0f066bb13f 100644 --- a/tests/output/javascript/src/methods/requests/recommend.test.ts +++ b/tests/output/javascript/src/methods/requests/recommend.test.ts @@ -7,6 +7,57 @@ const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; const client = recommendApi(appId, apiKey, { requester: echoRequester() }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getRecommendations', () => { test('get recommendations for recommend model with minimal parameters', async () => { const req = (await client.getRecommendations({ @@ -237,3 +288,55 @@ describe('getRecommendations', () => { expect(req.searchParams).toEqual(undefined); }); }); + +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); diff --git a/tests/output/javascript/src/methods/requests/search.test.ts b/tests/output/javascript/src/methods/requests/search.test.ts index 99ede71a0a..152f2b8a2a 100644 --- a/tests/output/javascript/src/methods/requests/search.test.ts +++ b/tests/output/javascript/src/methods/requests/search.test.ts @@ -313,6 +313,32 @@ describe('clearRules', () => { }); }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteApiKey', () => { test('deleteApiKey', async () => { const req = (await client.deleteApiKey({ @@ -408,6 +434,31 @@ describe('deleteSynonym', () => { }); }); +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('getApiKey', () => { test('getApiKey', async () => { const req = (await client.getApiKey({ @@ -762,6 +813,58 @@ describe('partialUpdateObject', () => { }); }); +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('removeUserId', () => { test('removeUserId', async () => { const req = (await client.removeUserId({ diff --git a/tests/output/javascript/src/methods/requests/sources.test.ts b/tests/output/javascript/src/methods/requests/sources.test.ts index 2c144665cf..8ed408eb62 100644 --- a/tests/output/javascript/src/methods/requests/sources.test.ts +++ b/tests/output/javascript/src/methods/requests/sources.test.ts @@ -7,6 +7,83 @@ const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key'; const client = sourcesApi(appId, apiKey, 'us', { requester: echoRequester() }); +describe('del', () => { + test('allow del method for a custom path with minimal parameters', async () => { + const req = (await client.del({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow del method for a custom path with all parameters', async () => { + const req = (await client.del({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('get', () => { + test('allow get method for a custom path with minimal parameters', async () => { + const req = (await client.get({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow get method for a custom path with all parameters', async () => { + const req = (await client.get({ + path: '/test/all', + parameters: { query: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('GET'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + +describe('post', () => { + test('allow post method for a custom path with minimal parameters', async () => { + const req = (await client.post({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow post method for a custom path with all parameters', async () => { + const req = (await client.post({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('postIngestUrl', () => { test('post postIngestUrl with minimal parameters', async () => { const req = (await client.postIngestUrl({ @@ -52,3 +129,29 @@ describe('postIngestUrl', () => { expect(req.searchParams).toEqual(undefined); }); }); + +describe('put', () => { + test('allow put method for a custom path with minimal parameters', async () => { + const req = (await client.put({ + path: '/test/minimal', + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/minimal'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual(undefined); + }); + + test('allow put method for a custom path with all parameters', async () => { + const req = (await client.put({ + path: '/test/all', + parameters: { query: 'parameters' }, + body: { body: 'parameters' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('PUT'); + expect(req.data).toEqual({ body: 'parameters' }); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); From 7cb03cbcb5a3b5b7453e71e70823511c3e0e193d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Tue, 12 Apr 2022 15:45:11 +0200 Subject: [PATCH 2/8] lint --- .../main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index 1d277e3f69..bfc8fd126e 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -7,7 +7,6 @@ import com.google.common.collect.ImmutableMap.Builder; import com.samskivert.mustache.Mustache.Lambda; import io.swagger.v3.core.util.Json; -import io.swagger.v3.oas.models.media.Schema; import java.io.File; import java.io.IOException; import java.util.*; From cf915d55ba9861f0790665e639f0c0e871bc0e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 13 Apr 2022 09:41:48 +0200 Subject: [PATCH 3/8] remove `requestBody` from `DELETE` operations --- specs/common/paths/customRequest.yml | 6 ------ tests/CTS/methods/requests/common/del.json | 6 ------ .../algolia/methods/requests/search.test.java | 17 +---------------- .../src/methods/requests/abtesting.test.ts | 3 +-- .../src/methods/requests/analytics.test.ts | 3 +-- .../src/methods/requests/insights.test.ts | 3 +-- .../methods/requests/personalization.test.ts | 3 +-- .../methods/requests/query-suggestions.test.ts | 3 +-- .../src/methods/requests/recommend.test.ts | 3 +-- .../src/methods/requests/search.test.ts | 3 +-- .../src/methods/requests/sources.test.ts | 3 +-- 11 files changed, 9 insertions(+), 44 deletions(-) diff --git a/specs/common/paths/customRequest.yml b/specs/common/paths/customRequest.yml index f2f6edd5b5..3bcdd1d542 100644 --- a/specs/common/paths/customRequest.yml +++ b/specs/common/paths/customRequest.yml @@ -24,10 +24,4 @@ put: delete: operationId: del - requestBody: - description: The parameters to send with the custom request. - content: - application/json: - schema: - type: object $ref: '../schemas/CustomRequest.yml#/customRequest' diff --git a/tests/CTS/methods/requests/common/del.json b/tests/CTS/methods/requests/common/del.json index 8e9e368194..fcb8830de1 100644 --- a/tests/CTS/methods/requests/common/del.json +++ b/tests/CTS/methods/requests/common/del.json @@ -17,17 +17,11 @@ "path": "/test/all", "parameters": { "query": "parameters" - }, - "body": { - "body": "parameters" } }, "request": { "path": "/1/test/all", "method": "DELETE", - "data": { - "body": "parameters" - }, "searchParams": { "query": "parameters" } diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index f839a870e4..07978e2488 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -722,29 +722,14 @@ void delTest1() { parameters0.put("query", query1); } - HashMap body0 = new HashMap(); - { - String body1 = "parameters"; - - body0.put("body", body1); - } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0, body0); + return client.del(path0, parameters0); } ); assertEquals(req.getPath(), "/1/test/all"); assertEquals(req.getMethod(), "DELETE"); - assertDoesNotThrow(() -> { - JSONAssert.assertEquals( - "{\"body\":\"parameters\"}", - req.getBody(), - JSONCompareMode.STRICT_ORDER - ); - }); - HashMap expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() diff --git a/tests/output/javascript/src/methods/requests/abtesting.test.ts b/tests/output/javascript/src/methods/requests/abtesting.test.ts index 095021a692..750dff432d 100644 --- a/tests/output/javascript/src/methods/requests/abtesting.test.ts +++ b/tests/output/javascript/src/methods/requests/abtesting.test.ts @@ -50,12 +50,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/analytics.test.ts b/tests/output/javascript/src/methods/requests/analytics.test.ts index b183b75200..bdbd9a3471 100644 --- a/tests/output/javascript/src/methods/requests/analytics.test.ts +++ b/tests/output/javascript/src/methods/requests/analytics.test.ts @@ -25,12 +25,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/insights.test.ts b/tests/output/javascript/src/methods/requests/insights.test.ts index 59ae38b3d4..4562d36486 100644 --- a/tests/output/javascript/src/methods/requests/insights.test.ts +++ b/tests/output/javascript/src/methods/requests/insights.test.ts @@ -23,12 +23,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/personalization.test.ts b/tests/output/javascript/src/methods/requests/personalization.test.ts index e85ed804ec..4f35ddd9d5 100644 --- a/tests/output/javascript/src/methods/requests/personalization.test.ts +++ b/tests/output/javascript/src/methods/requests/personalization.test.ts @@ -25,12 +25,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts index e2c75f93a1..4f3a90b08e 100644 --- a/tests/output/javascript/src/methods/requests/query-suggestions.test.ts +++ b/tests/output/javascript/src/methods/requests/query-suggestions.test.ts @@ -58,12 +58,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/recommend.test.ts b/tests/output/javascript/src/methods/requests/recommend.test.ts index 0f066bb13f..d4aba81a2e 100644 --- a/tests/output/javascript/src/methods/requests/recommend.test.ts +++ b/tests/output/javascript/src/methods/requests/recommend.test.ts @@ -23,12 +23,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/search.test.ts b/tests/output/javascript/src/methods/requests/search.test.ts index 152f2b8a2a..3774dbee6d 100644 --- a/tests/output/javascript/src/methods/requests/search.test.ts +++ b/tests/output/javascript/src/methods/requests/search.test.ts @@ -329,12 +329,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); diff --git a/tests/output/javascript/src/methods/requests/sources.test.ts b/tests/output/javascript/src/methods/requests/sources.test.ts index 8ed408eb62..60ba9e7561 100644 --- a/tests/output/javascript/src/methods/requests/sources.test.ts +++ b/tests/output/javascript/src/methods/requests/sources.test.ts @@ -23,12 +23,11 @@ describe('del', () => { const req = (await client.del({ path: '/test/all', parameters: { query: 'parameters' }, - body: { body: 'parameters' }, })) as unknown as EchoResponse; expect(req.path).toEqual('/1/test/all'); expect(req.method).toEqual('DELETE'); - expect(req.data).toEqual({ body: 'parameters' }); + expect(req.data).toEqual(undefined); expect(req.searchParams).toEqual({ query: 'parameters' }); }); }); From b0cf8ebee214445bf825121d573736b0bdce0dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 13 Apr 2022 10:10:33 +0200 Subject: [PATCH 4/8] fix php path --- .github/workflows/check.yml | 1 + .yarnrc.yml | 2 +- package.json | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ac5c48707b..41d7b1173e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -274,6 +274,7 @@ jobs: hashFiles( format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api), format('{0}/lib/Configuration/{1}.php', matrix.client.folder, matrix.client.config), + format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName), format('specs/bundled/{0}.yml', matrix.client.name), 'templates/php/**', 'generators/src/**' diff --git a/.yarnrc.yml b/.yarnrc.yml index c3c72dc450..74cbf37e37 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -2,6 +2,6 @@ nodeLinker: node-modules plugins: - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs - spec: "@yarnpkg/plugin-interactive-tools" + spec: '@yarnpkg/plugin-interactive-tools' yarnPath: .yarn/releases/yarn-3.1.1.cjs diff --git a/package.json b/package.json index ab067c4be2..5c0bf775de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "@algolia/api-client-automation", "version": "0.0.0", + "private": true, "workspaces": [ "clients/algoliasearch-client-javascript/", "playground/javascript/node/", @@ -20,7 +21,7 @@ "docker": "docker exec -it dev yarn cli $*", "github-actions:lint": "eslint --ext=yml .github/", "playground:browser": "yarn workspace javascript-browser-playground start", - "postinstall": "yarn workspace eslint-plugin-automation-custom build", + "postinstall": "echo 'running post install' && yarn workspace eslint-plugin-automation-custom build", "build:eslint": "yarn workspace eslint-plugin-automation-custom build && yarn install", "release": "yarn workspace scripts createReleaseIssue", "scripts:lint": "eslint --ext=ts scripts/", From e3a9a367c4bf7296a83de66878ac660f6a123e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 13 Apr 2022 10:15:01 +0200 Subject: [PATCH 5/8] remove echo, remove model cache --- .github/.cache_version | 2 +- .github/actions/cache/action.yml | 7 ------- .github/workflows/check.yml | 1 - package.json | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 0ee843cc60..b26a34e470 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -7.2.0 +7.2.1 diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 348e879b8b..da739a8253 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -375,7 +375,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/SearchApi.php', 'clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Search/**', 'specs/bundled/search.yml', 'templates/php/**', 'generators/src/**' @@ -393,7 +392,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/RecommendApi.php', 'clients/algoliasearch-client-php/lib/Configuration/RecommendConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Recommend/**', 'specs/bundled/recommend.yml', 'templates/php/**', 'generators/src/**' @@ -411,7 +409,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php', 'clients/algoliasearch-client-php/lib/Configuration/PersonalizationConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Personalization/**', 'specs/bundled/personalization.yml', 'templates/php/**', 'generators/src/**' @@ -429,7 +426,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/AnalyticsConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Analytics/**', 'specs/bundled/analytics.yml', 'templates/php/**', 'generators/src/**' @@ -447,7 +443,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/InsightsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/InsightsConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Insights/**', 'specs/bundled/insights.yml', 'templates/php/**', 'generators/src/**' @@ -465,7 +460,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/AbtestingApi.php', 'clients/algoliasearch-client-php/lib/Configuration/AbtestingConfig.php', - 'clients/algoliasearch-client-php/lib/Model/Abtesting/**', 'specs/bundled/abtesting.yml', 'templates/php/**', 'generators/src/**' @@ -483,7 +477,6 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/QuerySuggestionsConfig.php', - 'clients/algoliasearch-client-php/lib/Model/QuerySuggestions/**', 'specs/bundled/query-suggestions.yml', 'templates/php/**', 'generators/src/**' diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 41d7b1173e..ac5c48707b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -274,7 +274,6 @@ jobs: hashFiles( format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api), format('{0}/lib/Configuration/{1}.php', matrix.client.folder, matrix.client.config), - format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName), format('specs/bundled/{0}.yml', matrix.client.name), 'templates/php/**', 'generators/src/**' diff --git a/package.json b/package.json index 5c0bf775de..13e63f6922 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "docker": "docker exec -it dev yarn cli $*", "github-actions:lint": "eslint --ext=yml .github/", "playground:browser": "yarn workspace javascript-browser-playground start", - "postinstall": "echo 'running post install' && yarn workspace eslint-plugin-automation-custom build", + "postinstall": "yarn workspace eslint-plugin-automation-custom build", "build:eslint": "yarn workspace eslint-plugin-automation-custom build && yarn install", "release": "yarn workspace scripts createReleaseIssue", "scripts:lint": "eslint --ext=ts scripts/", From 86d1cdf8aba43ef4abd1a089a2a3691778ff0676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Wed, 13 Apr 2022 10:33:41 +0200 Subject: [PATCH 6/8] cache was already used?? --- .github/.cache_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.cache_version b/.github/.cache_version index b26a34e470..8e83b1890b 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -7.2.1 +7.2.1.0 From 4efdcd855128f2ad77f3e99f409aa9e729a150af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Thu, 14 Apr 2022 10:27:59 +0200 Subject: [PATCH 7/8] fix wrong path --- .github/.cache_version | 2 +- .github/actions/cache/action.yml | 7 +++++++ .github/workflows/check.yml | 1 + scripts/ci/createMatrix.ts | 5 ++++- scripts/generate.ts | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 8e83b1890b..10e598c19c 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -7.2.1.0 +7.2.1.0.1 diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index da739a8253..348e879b8b 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -375,6 +375,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/SearchApi.php', 'clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Search/**', 'specs/bundled/search.yml', 'templates/php/**', 'generators/src/**' @@ -392,6 +393,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/RecommendApi.php', 'clients/algoliasearch-client-php/lib/Configuration/RecommendConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Recommend/**', 'specs/bundled/recommend.yml', 'templates/php/**', 'generators/src/**' @@ -409,6 +411,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php', 'clients/algoliasearch-client-php/lib/Configuration/PersonalizationConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Personalization/**', 'specs/bundled/personalization.yml', 'templates/php/**', 'generators/src/**' @@ -426,6 +429,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/AnalyticsConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Analytics/**', 'specs/bundled/analytics.yml', 'templates/php/**', 'generators/src/**' @@ -443,6 +447,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/InsightsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/InsightsConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Insights/**', 'specs/bundled/insights.yml', 'templates/php/**', 'generators/src/**' @@ -460,6 +465,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/AbtestingApi.php', 'clients/algoliasearch-client-php/lib/Configuration/AbtestingConfig.php', + 'clients/algoliasearch-client-php/lib/Model/Abtesting/**', 'specs/bundled/abtesting.yml', 'templates/php/**', 'generators/src/**' @@ -477,6 +483,7 @@ runs: hashFiles( 'clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php', 'clients/algoliasearch-client-php/lib/Configuration/QuerySuggestionsConfig.php', + 'clients/algoliasearch-client-php/lib/Model/QuerySuggestions/**', 'specs/bundled/query-suggestions.yml', 'templates/php/**', 'generators/src/**' diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 40b29984ad..305e0e14c7 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -277,6 +277,7 @@ jobs: hashFiles( format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api), format('{0}/lib/Configuration/{1}.php', matrix.client.folder, matrix.client.config), + format('{0}/lib/Model/{1}/**', matrix.client.folder, matrix.client.capitalizedName), format('specs/bundled/{0}.yml', matrix.client.name), 'templates/php/**', 'generators/src/**' diff --git a/scripts/ci/createMatrix.ts b/scripts/ci/createMatrix.ts index 86c009690b..d7d59d8f61 100644 --- a/scripts/ci/createMatrix.ts +++ b/scripts/ci/createMatrix.ts @@ -72,7 +72,10 @@ async function getClientMatrix({ 'Config', 'Api' ); - matchedGenerator.capitalizedName = createClientName(client, 'php'); + matchedGenerator.capitalizedName = createClientName( + client, + 'php' + ).replace('Api', ''); } matrix.client.push(matchedGenerator); diff --git a/scripts/generate.ts b/scripts/generate.ts index 226866ea00..463c10f119 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -35,7 +35,7 @@ async function removeExistingModel( clientModel = client; break; case 'php': - clientModel = createClientName(client, 'php'); + clientModel = createClientName(client, 'php').replace('Api', ''); break; default: break; From 42ed0a5f9de5d3a3ba213492a1720e15ac309d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Thu, 14 Apr 2022 11:10:04 +0200 Subject: [PATCH 8/8] remove Api from createClientName --- scripts/ci/createMatrix.ts | 5 +---- scripts/cts/client/generate.ts | 4 ++-- scripts/cts/utils.test.ts | 14 ++++++-------- scripts/cts/utils.ts | 3 ++- scripts/generate.ts | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/ci/createMatrix.ts b/scripts/ci/createMatrix.ts index d7d59d8f61..86c009690b 100644 --- a/scripts/ci/createMatrix.ts +++ b/scripts/ci/createMatrix.ts @@ -72,10 +72,7 @@ async function getClientMatrix({ 'Config', 'Api' ); - matchedGenerator.capitalizedName = createClientName( - client, - 'php' - ).replace('Api', ''); + matchedGenerator.capitalizedName = createClientName(client, 'php'); } matrix.client.push(matchedGenerator); diff --git a/scripts/cts/client/generate.ts b/scripts/cts/client/generate.ts index e18f93bb40..db218426df 100644 --- a/scripts/cts/client/generate.ts +++ b/scripts/cts/client/generate.ts @@ -7,10 +7,10 @@ import { createSpinner } from '../../oraLog'; import type { Generator } from '../../types'; import { walk, - createClientName, createOutputDir, getOutputPath, loadTemplates, + createClientName, } from '../utils'; import type { TestsBlock, Test, ModifiedStepForMustache } from './types'; @@ -98,7 +98,7 @@ export async function generateClientTests( template, { import: packageName, - client: createClientName(client, language), + client: `${createClientName(client, language)}Api`, blocks: modifyForMustache(testsBlocks), hasRegionalHost: hasRegionalHost ? true : undefined, }, diff --git a/scripts/cts/utils.test.ts b/scripts/cts/utils.test.ts index ff9302b001..314ddc5d5a 100644 --- a/scripts/cts/utils.test.ts +++ b/scripts/cts/utils.test.ts @@ -20,22 +20,20 @@ describe('utils', () => { describe('createClientName', () => { it('does not capitalize every part for JavaScript', () => { - expect(createClientName('search', 'javascript')).toEqual('searchApi'); + expect(createClientName('search', 'javascript')).toEqual('search'); expect(createClientName('search-client', 'javascript')).toEqual( - 'searchClientApi' + 'searchClient' ); expect(createClientName('search-cli!nt-complex', 'javascript')).toEqual( - 'searchCli!ntComplexApi' + 'searchCli!ntComplex' ); }); it('capitalize every part for other languages', () => { - expect(createClientName('search', 'java')).toEqual('SearchApi'); - expect(createClientName('search-client', 'java')).toEqual( - 'SearchClientApi' - ); + expect(createClientName('search', 'java')).toEqual('Search'); + expect(createClientName('search-client', 'java')).toEqual('SearchClient'); expect(createClientName('search-cli!nt-complex', 'java')).toEqual( - 'SearchCli!ntComplexApi' + 'SearchCli!ntComplex' ); }); }); diff --git a/scripts/cts/utils.ts b/scripts/cts/utils.ts index a2abc733db..18968d7b20 100644 --- a/scripts/cts/utils.ts +++ b/scripts/cts/utils.ts @@ -30,8 +30,9 @@ export function createClientName(client: string, language: string): string { }) .join(''); - return `${clientName}Api`; + return clientName; } + export async function createOutputDir({ language, testPath, diff --git a/scripts/generate.ts b/scripts/generate.ts index 463c10f119..226866ea00 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -35,7 +35,7 @@ async function removeExistingModel( clientModel = client; break; case 'php': - clientModel = createClientName(client, 'php').replace('Api', ''); + clientModel = createClientName(client, 'php'); break; default: break;