diff --git a/.github/.cache_version b/.github/.cache_version index 0ee843cc60..10e598c19c 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -7.2.0 +7.2.1.0.1 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/.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/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index b4e88bfc27..bfc8fd126e 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -170,6 +170,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 +184,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/package.json b/package.json index 4b86699f9f..1801d79155 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/", 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/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 new file mode 100644 index 0000000000..fcb8830de1 --- /dev/null +++ b/tests/CTS/methods/requests/common/del.json @@ -0,0 +1,30 @@ +[ + { + "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" + } + }, + "request": { + "path": "/1/test/all", + "method": "DELETE", + "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..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 @@ -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,50 @@ 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); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + 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 +862,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 +967,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 +1002,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 +1175,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 +1222,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 +1247,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 +1458,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 +1746,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 +1812,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 +1912,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 +2308,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..750dff432d 100644 --- a/tests/output/javascript/src/methods/requests/abtesting.test.ts +++ b/tests/output/javascript/src/methods/requests/abtesting.test.ts @@ -34,6 +34,31 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteABTest', () => { test('deleteABTest', async () => { const req = (await client.deleteABTest({ @@ -47,6 +72,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 +122,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..bdbd9a3471 100644 --- a/tests/output/javascript/src/methods/requests/analytics.test.ts +++ b/tests/output/javascript/src/methods/requests/analytics.test.ts @@ -9,6 +9,56 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + 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 +671,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..4562d36486 100644 --- a/tests/output/javascript/src/methods/requests/insights.test.ts +++ b/tests/output/javascript/src/methods/requests/insights.test.ts @@ -7,6 +7,82 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + 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 +153,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..4f35ddd9d5 100644 --- a/tests/output/javascript/src/methods/requests/personalization.test.ts +++ b/tests/output/javascript/src/methods/requests/personalization.test.ts @@ -9,6 +9,31 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteUserProfile', () => { test('delete deleteUserProfile', async () => { const req = (await client.deleteUserProfile({ @@ -22,6 +47,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 +97,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..4f3a90b08e 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,31 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteConfig', () => { test('deleteConfig', async () => { const req = (await client.deleteConfig({ @@ -55,6 +80,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 +155,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..d4aba81a2e 100644 --- a/tests/output/javascript/src/methods/requests/recommend.test.ts +++ b/tests/output/javascript/src/methods/requests/recommend.test.ts @@ -7,6 +7,56 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + 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 +287,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..3774dbee6d 100644 --- a/tests/output/javascript/src/methods/requests/search.test.ts +++ b/tests/output/javascript/src/methods/requests/search.test.ts @@ -313,6 +313,31 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + expect(req.searchParams).toEqual({ query: 'parameters' }); + }); +}); + describe('deleteApiKey', () => { test('deleteApiKey', async () => { const req = (await client.deleteApiKey({ @@ -408,6 +433,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 +812,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..60ba9e7561 100644 --- a/tests/output/javascript/src/methods/requests/sources.test.ts +++ b/tests/output/javascript/src/methods/requests/sources.test.ts @@ -7,6 +7,82 @@ 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' }, + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/1/test/all'); + expect(req.method).toEqual('DELETE'); + expect(req.data).toEqual(undefined); + 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 +128,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' }); + }); +});