From e81ca0a5be47ad3b143527ac827d673eda4837c9 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 1 Feb 2022 11:14:08 +0100 Subject: [PATCH 01/12] chore: add tests for host, user agent, and timeouts --- .../src/requester/EchoRequester.ts | 3 +- tests/CTS/client/search/basic.json | 56 +++++++++++++++++++ .../templates/javascript/expected.mustache | 14 ++++- .../templates/javascript/testSubject.mustache | 7 +++ .../javascript/tests/client/search.test.ts | 50 +++++++++++++++++ tests/src/client/generate.ts | 13 +++++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 tests/CTS/client/search/basic.json create mode 100644 tests/CTS/client/templates/javascript/testSubject.mustache diff --git a/clients/algoliasearch-client-javascript/client-common/src/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-common/src/requester/EchoRequester.ts index f773d0f6379..1897839b044 100644 --- a/clients/algoliasearch-client-javascript/client-common/src/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-common/src/requester/EchoRequester.ts @@ -27,7 +27,7 @@ export class EchoRequester extends Requester { { headers, url, connectTimeout, responseTimeout }: EndRequest, { data, ...originalRequest }: Request ): Promise { - const urlSearchParams = new URL(url).searchParams; + const { host, searchParams: urlSearchParams } = new URL(url); const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; const originalData = data && Object.entries(data).length > 0 ? data : undefined; @@ -35,6 +35,7 @@ export class EchoRequester extends Requester { return Promise.resolve({ content: JSON.stringify({ ...originalRequest, + host, headers, connectTimeout, responseTimeout, diff --git a/tests/CTS/client/search/basic.json b/tests/CTS/client/search/basic.json new file mode 100644 index 00000000000..d7c0644f120 --- /dev/null +++ b/tests/CTS/client/search/basic.json @@ -0,0 +1,56 @@ +[ + { + "testName": "searches with correct host", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "search", + "parameters": [{ "indexName": "my-index", "searchParams": {} }], + "expected": { + "match": { + "objectContaining": { + "host": "algolia-api-key.algolia.net" + } + } + } + } + ] + }, + { + "testName": "searches with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "search", + "parameters": [{ "indexName": "my-index", "searchParams": {} }], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "searches with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "search", + "parameters": [{ "indexName": "my-index", "searchParams": {} }], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/templates/javascript/expected.mustache b/tests/CTS/client/templates/javascript/expected.mustache index 83136041259..408fbe57c65 100644 --- a/tests/CTS/client/templates/javascript/expected.mustache +++ b/tests/CTS/client/templates/javascript/expected.mustache @@ -1,3 +1,13 @@ {{#length}} - expect(actual).toHaveLength({{length}}); -{{/length}} \ No newline at end of file + expect({{> testSubject}}).toHaveLength({{length}}); +{{/length}} + +{{#match}} + {{#objectContaining}} + expect({{> testSubject}}).toEqual(expect.objectContaining({{{objectContaining}}})); + {{/objectContaining}} + + {{#regexp}} + expect({{> testSubject}}).toMatch({{{regexp}}}); + {{/regexp}} +{{/match}} \ No newline at end of file diff --git a/tests/CTS/client/templates/javascript/testSubject.mustache b/tests/CTS/client/templates/javascript/testSubject.mustache new file mode 100644 index 00000000000..ffa50baad3d --- /dev/null +++ b/tests/CTS/client/templates/javascript/testSubject.mustache @@ -0,0 +1,7 @@ +{{#testSubject}} + {{{testSubject}}} +{{/testSubject}} + +{{^testSubject}} + actual +{{/testSubject}} \ No newline at end of file diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index 6001f04cbfb..686d72c5335 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -8,6 +8,56 @@ function createClient(): SearchApi { return new SearchApi(appId, apiKey, { requester: new EchoRequester() }); } +describe('basic', () => { + test('searches with correct host', async () => { + const $client = createClient(); + + let actual; + + actual = $client.search({ indexName: 'my-index', searchParams: {} }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'algolia-api-key.algolia.net' }) + ); + }); + + test('searches with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.search({ indexName: 'my-index', searchParams: {} }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('searches with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.search({ indexName: 'my-index', searchParams: {} }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); + describe('parameters', () => { test('constructor throws with invalid parameters', async () => { let actual; diff --git a/tests/src/client/generate.ts b/tests/src/client/generate.ts index c5d05b18ffc..44fd43d5304 100644 --- a/tests/src/client/generate.ts +++ b/tests/src/client/generate.ts @@ -148,6 +148,7 @@ function modifyForMustache( type: step.type, object: step.object, path: step.path, + expected: step.expected, parameters: step.parameters && serializeParameters(step.parameters), ...base, }; @@ -163,6 +164,18 @@ function modifyForMustache( modified.expectedNoError = true; } + if (step.expected?.match?.objectContaining) { + if (!modified.expected) { + modified.expected = {}; + } + + modified.expected.match = { + objectContaining: JSON.stringify( + step.expected?.match?.objectContaining + ), + }; + } + return modified; }), })), From 4639c12029e71b21a726d5afbbc71c52fa84e6bd Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 1 Feb 2022 11:17:42 +0100 Subject: [PATCH 02/12] chore: rename test --- tests/CTS/client/search/parameters.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CTS/client/search/parameters.json b/tests/CTS/client/search/parameters.json index f80fe060e5d..b23e13d3407 100644 --- a/tests/CTS/client/search/parameters.json +++ b/tests/CTS/client/search/parameters.json @@ -1,6 +1,6 @@ [ { - "testName": "constructor throws with invalid parameters", + "testName": "client throws with invalid parameters", "autoCreateClient": false, "steps": [ { From df19ea05b409ce183c0559b1b252cce3d189a74d Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 1 Feb 2022 15:10:51 +0100 Subject: [PATCH 03/12] chore: add more tests --- tests/CTS/client/abtesting/basic.json | 50 +++++++++++++++++ tests/CTS/client/analytics/basic.json | 31 ++++++----- tests/CTS/client/analytics/parameters.json | 33 ++++++++++++ tests/CTS/client/insights/basic.json | 46 ++++++++++++++++ tests/CTS/client/personalization/basic.json | 38 +++++++++++++ tests/CTS/client/query-suggestions/basic.json | 38 +++++++++++++ tests/CTS/client/recommend/basic.json | 38 +++++++++++++ tests/CTS/client/search/basic.json | 6 +-- tests/CTS/client/sources/basic.json | 38 +++++++++++++ .../javascript/tests/client/abtesting.test.ts | 53 +++++++++++++++++++ .../javascript/tests/client/analytics.test.ts | 34 ++++++++++++ .../javascript/tests/client/insights.test.ts | 43 +++++++++++++++ .../tests/client/personalization.test.ts | 48 +++++++++++++++++ .../tests/client/query-suggestions.test.ts | 48 +++++++++++++++++ .../javascript/tests/client/recommend.test.ts | 43 +++++++++++++++ .../javascript/tests/client/sources.test.ts | 45 ++++++++++++++++ 16 files changed, 616 insertions(+), 16 deletions(-) create mode 100644 tests/CTS/client/abtesting/basic.json create mode 100644 tests/CTS/client/analytics/parameters.json create mode 100644 tests/CTS/client/insights/basic.json create mode 100644 tests/CTS/client/personalization/basic.json create mode 100644 tests/CTS/client/query-suggestions/basic.json create mode 100644 tests/CTS/client/recommend/basic.json create mode 100644 tests/CTS/client/sources/basic.json create mode 100644 tests/output/javascript/tests/client/abtesting.test.ts create mode 100644 tests/output/javascript/tests/client/insights.test.ts create mode 100644 tests/output/javascript/tests/client/personalization.test.ts create mode 100644 tests/output/javascript/tests/client/query-suggestions.test.ts create mode 100644 tests/output/javascript/tests/client/recommend.test.ts create mode 100644 tests/output/javascript/tests/client/sources.test.ts diff --git a/tests/CTS/client/abtesting/basic.json b/tests/CTS/client/abtesting/basic.json new file mode 100644 index 00000000000..99eee49c34b --- /dev/null +++ b/tests/CTS/client/abtesting/basic.json @@ -0,0 +1,50 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "addABTests", + "parameters": [ + { + "name": "test", + "variant": [{ "index": "my-test-index", "trafficPercentage": 90 }], + "endAt": "2022-02-01T13:37:01Z" + } + ], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "addABTests", + "parameters": [ + { + "name": "test", + "variant": [{ "index": "my-test-index", "trafficPercentage": 90 }], + "endAt": "2022-02-01T13:37:01Z" + } + ], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/analytics/basic.json b/tests/CTS/client/analytics/basic.json index 7d539ef3c3d..ae0c75c2b4e 100644 --- a/tests/CTS/client/analytics/basic.json +++ b/tests/CTS/client/analytics/basic.json @@ -1,31 +1,36 @@ [ { - "testName": "does not throw when region is not given", - "autoCreateClient": false, + "testName": "calls api with correct user agent", "steps": [ { - "type": "createClient", - "parameters": { - "appId": "my-app-id", - "apiKey": "my-api-key", - "region": "" - }, + "type": "method", + "object": "$client", + "path": "getAverageClickPosition", + "parameters": [{ "index": "my-index" }], "expected": { - "error": false + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } } } ] }, { - "testName": "getAverageClickPosition throws without index", + "testName": "calls api with correct timeouts", "steps": [ { "type": "method", "object": "$client", - "path": "getClickPositions", - "parameters": [{}], + "path": "getAverageClickPosition", + "parameters": [{ "index": "my-index" }], "expected": { - "error": "Parameter `index` is required when calling `getClickPositions`." + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 5 + } + } } } ] diff --git a/tests/CTS/client/analytics/parameters.json b/tests/CTS/client/analytics/parameters.json new file mode 100644 index 00000000000..7d539ef3c3d --- /dev/null +++ b/tests/CTS/client/analytics/parameters.json @@ -0,0 +1,33 @@ +[ + { + "testName": "does not throw when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": false + } + } + ] + }, + { + "testName": "getAverageClickPosition throws without index", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getClickPositions", + "parameters": [{}], + "expected": { + "error": "Parameter `index` is required when calling `getClickPositions`." + } + } + ] + } +] diff --git a/tests/CTS/client/insights/basic.json b/tests/CTS/client/insights/basic.json new file mode 100644 index 00000000000..1256ff24a4a --- /dev/null +++ b/tests/CTS/client/insights/basic.json @@ -0,0 +1,46 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "pushEvents", + "parameters": [ + { + "events": [] + } + ], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "pushEvents", + "parameters": [ + { + "events": [] + } + ], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/personalization/basic.json b/tests/CTS/client/personalization/basic.json new file mode 100644 index 00000000000..fa8e43d7faa --- /dev/null +++ b/tests/CTS/client/personalization/basic.json @@ -0,0 +1,38 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getPersonalizationStrategy", + "parameters": [], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getPersonalizationStrategy", + "parameters": [], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 5 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/query-suggestions/basic.json b/tests/CTS/client/query-suggestions/basic.json new file mode 100644 index 00000000000..ea3f7ab0571 --- /dev/null +++ b/tests/CTS/client/query-suggestions/basic.json @@ -0,0 +1,38 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "createConfig", + "parameters": [{}], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "createConfig", + "parameters": [{}], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/recommend/basic.json b/tests/CTS/client/recommend/basic.json new file mode 100644 index 00000000000..ae75ea92ae0 --- /dev/null +++ b/tests/CTS/client/recommend/basic.json @@ -0,0 +1,38 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getRecommendations", + "parameters": [{ "requests": [] }], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getRecommendations", + "parameters": [{ "requests": [] }], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/search/basic.json b/tests/CTS/client/search/basic.json index d7c0644f120..fc788c36eec 100644 --- a/tests/CTS/client/search/basic.json +++ b/tests/CTS/client/search/basic.json @@ -1,6 +1,6 @@ [ { - "testName": "searches with correct host", + "testName": "calls api with correct host", "steps": [ { "type": "method", @@ -18,7 +18,7 @@ ] }, { - "testName": "searches with correct user agent", + "testName": "calls api with correct user agent", "steps": [ { "type": "method", @@ -35,7 +35,7 @@ ] }, { - "testName": "searches with correct timeouts", + "testName": "calls api with correct timeouts", "steps": [ { "type": "method", diff --git a/tests/CTS/client/sources/basic.json b/tests/CTS/client/sources/basic.json new file mode 100644 index 00000000000..292dd86ea2f --- /dev/null +++ b/tests/CTS/client/sources/basic.json @@ -0,0 +1,38 @@ +[ + { + "testName": "calls api with correct user agent", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "postIngestUrl", + "parameters": [{ "type": "csv", "input": { "url": "..." } }], + "expected": { + "testSubject": "actual.userAgent", + "match": { + "regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/" + } + } + } + ] + }, + { + "testName": "calls api with correct timeouts", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "postIngestUrl", + "parameters": [{ "type": "csv", "input": { "url": "..." } }], + "expected": { + "match": { + "objectContaining": { + "connectTimeout": 2, + "responseTimeout": 30 + } + } + } + } + ] + } +] diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts new file mode 100644 index 00000000000..d04476ce82e --- /dev/null +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -0,0 +1,53 @@ +// @ts-nocheck +import { AbtestingApi, EchoRequester } from '@algolia/client-abtesting'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): AbtestingApi { + return new AbtestingApi(appId, apiKey, 'us', { + requester: new EchoRequester(), + }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.addABTests({ + name: 'test', + variant: [{ index: 'my-test-index', trafficPercentage: 90 }], + endAt: '2022-02-01T13:37:01Z', + }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.addABTests({ + name: 'test', + variant: [{ index: 'my-test-index', trafficPercentage: 90 }], + endAt: '2022-02-01T13:37:01Z', + }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index bb53b0a94fb..5a5457f89c3 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -11,6 +11,40 @@ function createClient(): AnalyticsApi { } describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getAverageClickPosition({ index: 'my-index' }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getAverageClickPosition({ index: 'my-index' }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) + ); + }); +}); + +describe('parameters', () => { test('does not throw when region is not given', async () => { let actual; diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts new file mode 100644 index 00000000000..ff034e99982 --- /dev/null +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -0,0 +1,43 @@ +// @ts-nocheck +import { InsightsApi, EchoRequester } from '@algolia/client-insights'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): InsightsApi { + return new InsightsApi(appId, apiKey, { requester: new EchoRequester() }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.pushEvents({ events: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.pushEvents({ events: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts new file mode 100644 index 00000000000..a6df15b5b17 --- /dev/null +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -0,0 +1,48 @@ +// @ts-nocheck +import { + PersonalizationApi, + EchoRequester, +} from '@algolia/client-personalization'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): PersonalizationApi { + return new PersonalizationApi(appId, apiKey, 'us', { + requester: new EchoRequester(), + }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getPersonalizationStrategy(); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getPersonalizationStrategy(); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts new file mode 100644 index 00000000000..47ff388d416 --- /dev/null +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -0,0 +1,48 @@ +// @ts-nocheck +import { + QuerySuggestionsApi, + EchoRequester, +} from '@algolia/client-query-suggestions'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): QuerySuggestionsApi { + return new QuerySuggestionsApi(appId, apiKey, 'us', { + requester: new EchoRequester(), + }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.createConfig({}); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.createConfig({}); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts new file mode 100644 index 00000000000..2d79db432fb --- /dev/null +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -0,0 +1,43 @@ +// @ts-nocheck +import { RecommendApi, EchoRequester } from '@algolia/recommend'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): RecommendApi { + return new RecommendApi(appId, apiKey, { requester: new EchoRequester() }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getRecommendations({ requests: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.getRecommendations({ requests: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts new file mode 100644 index 00000000000..d06f6db27b8 --- /dev/null +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -0,0 +1,45 @@ +// @ts-nocheck +import { SourcesApi, EchoRequester } from '@algolia/client-sources'; + +const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; + +function createClient(): SourcesApi { + return new SourcesApi(appId, apiKey, 'us', { + requester: new EchoRequester(), + }); +} + +describe('basic', () => { + test('calls api with correct user agent', async () => { + const $client = createClient(); + + let actual; + + actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual.userAgent).toMatch( + /Algolia%20for%20(.+)%20\(\d+\.\d+\.\d+\)/ + ); + }); + + test('calls api with correct timeouts', async () => { + const $client = createClient(); + + let actual; + + actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + ); + }); +}); From 6980d5754a37a983d696688b0a0a12b96e4e70c4 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 2 Feb 2022 14:27:05 +0100 Subject: [PATCH 04/12] fix: add host to EchoResponse --- .../algoliasearch-client-javascript/client-common/src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/clients/algoliasearch-client-javascript/client-common/src/types.ts b/clients/algoliasearch-client-javascript/client-common/src/types.ts index 20136fe367b..db445cf0142 100644 --- a/clients/algoliasearch-client-javascript/client-common/src/types.ts +++ b/clients/algoliasearch-client-javascript/client-common/src/types.ts @@ -45,6 +45,7 @@ export type Response = { export type EchoResponse = Request & { connectTimeout: number; + host: string; headers: Record; responseTimeout: number; searchParams?: Record; From 4a61b974c59ddb0eb248b6ccd46135b68fafb0b9 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 2 Feb 2022 14:27:17 +0100 Subject: [PATCH 05/12] chore: rename tests --- tests/CTS/client/abtesting/{basic.json => api.json} | 0 tests/CTS/client/analytics/{basic.json => api.json} | 0 tests/CTS/client/insights/{basic.json => api.json} | 0 .../client/personalization/{basic.json => api.json} | 0 .../query-suggestions/{basic.json => api.json} | 0 tests/CTS/client/recommend/{basic.json => api.json} | 0 tests/CTS/client/search/{basic.json => api.json} | 0 tests/CTS/client/sources/{basic.json => api.json} | 0 .../javascript/tests/client/abtesting.test.ts | 2 +- .../javascript/tests/client/analytics.test.ts | 2 +- .../output/javascript/tests/client/insights.test.ts | 2 +- .../javascript/tests/client/personalization.test.ts | 2 +- .../tests/client/query-suggestions.test.ts | 2 +- .../javascript/tests/client/recommend.test.ts | 2 +- tests/output/javascript/tests/client/search.test.ts | 13 ++++++------- .../output/javascript/tests/client/sources.test.ts | 2 +- 16 files changed, 13 insertions(+), 14 deletions(-) rename tests/CTS/client/abtesting/{basic.json => api.json} (100%) rename tests/CTS/client/analytics/{basic.json => api.json} (100%) rename tests/CTS/client/insights/{basic.json => api.json} (100%) rename tests/CTS/client/personalization/{basic.json => api.json} (100%) rename tests/CTS/client/query-suggestions/{basic.json => api.json} (100%) rename tests/CTS/client/recommend/{basic.json => api.json} (100%) rename tests/CTS/client/search/{basic.json => api.json} (100%) rename tests/CTS/client/sources/{basic.json => api.json} (100%) diff --git a/tests/CTS/client/abtesting/basic.json b/tests/CTS/client/abtesting/api.json similarity index 100% rename from tests/CTS/client/abtesting/basic.json rename to tests/CTS/client/abtesting/api.json diff --git a/tests/CTS/client/analytics/basic.json b/tests/CTS/client/analytics/api.json similarity index 100% rename from tests/CTS/client/analytics/basic.json rename to tests/CTS/client/analytics/api.json diff --git a/tests/CTS/client/insights/basic.json b/tests/CTS/client/insights/api.json similarity index 100% rename from tests/CTS/client/insights/basic.json rename to tests/CTS/client/insights/api.json diff --git a/tests/CTS/client/personalization/basic.json b/tests/CTS/client/personalization/api.json similarity index 100% rename from tests/CTS/client/personalization/basic.json rename to tests/CTS/client/personalization/api.json diff --git a/tests/CTS/client/query-suggestions/basic.json b/tests/CTS/client/query-suggestions/api.json similarity index 100% rename from tests/CTS/client/query-suggestions/basic.json rename to tests/CTS/client/query-suggestions/api.json diff --git a/tests/CTS/client/recommend/basic.json b/tests/CTS/client/recommend/api.json similarity index 100% rename from tests/CTS/client/recommend/basic.json rename to tests/CTS/client/recommend/api.json diff --git a/tests/CTS/client/search/basic.json b/tests/CTS/client/search/api.json similarity index 100% rename from tests/CTS/client/search/basic.json rename to tests/CTS/client/search/api.json diff --git a/tests/CTS/client/sources/basic.json b/tests/CTS/client/sources/api.json similarity index 100% rename from tests/CTS/client/sources/basic.json rename to tests/CTS/client/sources/api.json diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index d04476ce82e..f2808f4d4ef 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -10,7 +10,7 @@ function createClient(): AbtestingApi { }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index 5a5457f89c3..2b9e4ce98e4 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -10,7 +10,7 @@ function createClient(): AnalyticsApi { }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index ff034e99982..99e6de941a5 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -8,7 +8,7 @@ function createClient(): InsightsApi { return new InsightsApi(appId, apiKey, { requester: new EchoRequester() }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts index a6df15b5b17..304f68801db 100644 --- a/tests/output/javascript/tests/client/personalization.test.ts +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -13,7 +13,7 @@ function createClient(): PersonalizationApi { }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts index 47ff388d416..008042621d0 100644 --- a/tests/output/javascript/tests/client/query-suggestions.test.ts +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -13,7 +13,7 @@ function createClient(): QuerySuggestionsApi { }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index 2d79db432fb..f123acb6d8e 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -8,7 +8,7 @@ function createClient(): RecommendApi { return new RecommendApi(appId, apiKey, { requester: new EchoRequester() }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index 686d72c5335..dcddd4750a9 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -1,4 +1,3 @@ -// @ts-nocheck import { SearchApi, EchoRequester } from '@algolia/client-search'; const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; @@ -8,8 +7,8 @@ function createClient(): SearchApi { return new SearchApi(appId, apiKey, { requester: new EchoRequester() }); } -describe('basic', () => { - test('searches with correct host', async () => { +describe('api', () => { + test('calls api with correct host', async () => { const $client = createClient(); let actual; @@ -25,7 +24,7 @@ describe('basic', () => { ); }); - test('searches with correct user agent', async () => { + test('calls api with correct user agent', async () => { const $client = createClient(); let actual; @@ -41,7 +40,7 @@ describe('basic', () => { ); }); - test('searches with correct timeouts', async () => { + test('calls api with correct timeouts', async () => { const $client = createClient(); let actual; @@ -59,7 +58,7 @@ describe('basic', () => { }); describe('parameters', () => { - test('constructor throws with invalid parameters', async () => { + test('client throws with invalid parameters', async () => { let actual; await expect( new Promise((resolve, reject) => { @@ -190,7 +189,7 @@ describe('parameters', () => { ); await expect( - new Promise((resolve, reject) => { + new Promise((resolve, reject) => { actual = $client.addOrUpdateObject({ indexName: 'my-index-name', objectID: 'my-object-id', diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index d06f6db27b8..8334a381f45 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -10,7 +10,7 @@ function createClient(): SourcesApi { }); } -describe('basic', () => { +describe('api', () => { test('calls api with correct user agent', async () => { const $client = createClient(); From 09a64884cea28b4b84c4a2e9f1b71837a7d20c62 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 2 Feb 2022 15:11:33 +0100 Subject: [PATCH 06/12] chore: fix host test and add region test --- tests/CTS/client/abtesting/parameters.json | 36 ++++++++++++++ .../client/personalization/parameters.json | 36 ++++++++++++++ .../client/query-suggestions/parameters.json | 36 ++++++++++++++ tests/CTS/client/search/api.json | 2 +- .../templates/javascript/suite.mustache | 4 +- .../javascript/tests/client/abtesting.test.ts | 43 ++++++++++++++++- .../javascript/tests/client/analytics.test.ts | 4 +- .../javascript/tests/client/insights.test.ts | 4 +- .../tests/client/personalization.test.ts | 48 ++++++++++++++++++- .../tests/client/query-suggestions.test.ts | 48 ++++++++++++++++++- .../javascript/tests/client/recommend.test.ts | 4 +- .../javascript/tests/client/search.test.ts | 9 ++-- .../javascript/tests/client/sources.test.ts | 4 +- 13 files changed, 257 insertions(+), 21 deletions(-) create mode 100644 tests/CTS/client/abtesting/parameters.json create mode 100644 tests/CTS/client/personalization/parameters.json create mode 100644 tests/CTS/client/query-suggestions/parameters.json diff --git a/tests/CTS/client/abtesting/parameters.json b/tests/CTS/client/abtesting/parameters.json new file mode 100644 index 00000000000..5f097fb0ab4 --- /dev/null +++ b/tests/CTS/client/abtesting/parameters.json @@ -0,0 +1,36 @@ +[ + { + "testName": "throws when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": "`region` is missing." + } + } + ] + }, + { + "testName": "does not throw when region is given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "us" + }, + "expected": { + "error": false + } + } + ] + } +] diff --git a/tests/CTS/client/personalization/parameters.json b/tests/CTS/client/personalization/parameters.json new file mode 100644 index 00000000000..5f097fb0ab4 --- /dev/null +++ b/tests/CTS/client/personalization/parameters.json @@ -0,0 +1,36 @@ +[ + { + "testName": "throws when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": "`region` is missing." + } + } + ] + }, + { + "testName": "does not throw when region is given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "us" + }, + "expected": { + "error": false + } + } + ] + } +] diff --git a/tests/CTS/client/query-suggestions/parameters.json b/tests/CTS/client/query-suggestions/parameters.json new file mode 100644 index 00000000000..5f097fb0ab4 --- /dev/null +++ b/tests/CTS/client/query-suggestions/parameters.json @@ -0,0 +1,36 @@ +[ + { + "testName": "throws when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": "`region` is missing." + } + } + ] + }, + { + "testName": "does not throw when region is given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "us" + }, + "expected": { + "error": false + } + } + ] + } +] diff --git a/tests/CTS/client/search/api.json b/tests/CTS/client/search/api.json index fc788c36eec..b0513a010f1 100644 --- a/tests/CTS/client/search/api.json +++ b/tests/CTS/client/search/api.json @@ -10,7 +10,7 @@ "expected": { "match": { "objectContaining": { - "host": "algolia-api-key.algolia.net" + "host": "test-app-id.algolia.net" } } } diff --git a/tests/CTS/client/templates/javascript/suite.mustache b/tests/CTS/client/templates/javascript/suite.mustache index d863e23a70c..b63f4f9c5f9 100644 --- a/tests/CTS/client/templates/javascript/suite.mustache +++ b/tests/CTS/client/templates/javascript/suite.mustache @@ -4,8 +4,8 @@ // @ts-nocheck import { {{client}}, EchoRequester } from '{{{import}}}'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): {{client}} { return new {{client}}(appId, apiKey, {{#hasRegionalHost}}'us', {{/hasRegionalHost}}{ requester: new EchoRequester() }); diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index f2808f4d4ef..b9b05683a40 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -1,8 +1,8 @@ // @ts-nocheck import { AbtestingApi, EchoRequester } from '@algolia/client-abtesting'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): AbtestingApi { return new AbtestingApi(appId, apiKey, 'us', { @@ -51,3 +51,42 @@ describe('api', () => { ); }); }); + +describe('parameters', () => { + test('throws when region is not given', async () => { + let actual; + await expect( + new Promise((resolve, reject) => { + const $client = new AbtestingApi('my-app-id', 'my-api-key', '', { + requester: new EchoRequester(), + }); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).rejects.toThrow('`region` is missing.'); + }); + + test('does not throw when region is given', async () => { + let actual; + + await expect( + new Promise((resolve, reject) => { + const $client = new AbtestingApi('my-app-id', 'my-api-key', 'us', { + requester: new EchoRequester(), + }); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).resolves.not.toThrow(); + }); +}); diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index 2b9e4ce98e4..e6ace5395ca 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -1,8 +1,8 @@ // @ts-nocheck import { AnalyticsApi, EchoRequester } from '@algolia/client-analytics'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): AnalyticsApi { return new AnalyticsApi(appId, apiKey, 'us', { diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index 99e6de941a5..dcc106ae0d0 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -1,8 +1,8 @@ // @ts-nocheck import { InsightsApi, EchoRequester } from '@algolia/client-insights'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): InsightsApi { return new InsightsApi(appId, apiKey, { requester: new EchoRequester() }); diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts index 304f68801db..08658ebc592 100644 --- a/tests/output/javascript/tests/client/personalization.test.ts +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -4,8 +4,8 @@ import { EchoRequester, } from '@algolia/client-personalization'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): PersonalizationApi { return new PersonalizationApi(appId, apiKey, 'us', { @@ -46,3 +46,47 @@ describe('api', () => { ); }); }); + +describe('parameters', () => { + test('throws when region is not given', async () => { + let actual; + await expect( + new Promise((resolve, reject) => { + const $client = new PersonalizationApi('my-app-id', 'my-api-key', '', { + requester: new EchoRequester(), + }); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).rejects.toThrow('`region` is missing.'); + }); + + test('does not throw when region is given', async () => { + let actual; + + await expect( + new Promise((resolve, reject) => { + const $client = new PersonalizationApi( + 'my-app-id', + 'my-api-key', + 'us', + { + requester: new EchoRequester(), + } + ); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).resolves.not.toThrow(); + }); +}); diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts index 008042621d0..6745d0cd635 100644 --- a/tests/output/javascript/tests/client/query-suggestions.test.ts +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -4,8 +4,8 @@ import { EchoRequester, } from '@algolia/client-query-suggestions'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): QuerySuggestionsApi { return new QuerySuggestionsApi(appId, apiKey, 'us', { @@ -46,3 +46,47 @@ describe('api', () => { ); }); }); + +describe('parameters', () => { + test('throws when region is not given', async () => { + let actual; + await expect( + new Promise((resolve, reject) => { + const $client = new QuerySuggestionsApi('my-app-id', 'my-api-key', '', { + requester: new EchoRequester(), + }); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).rejects.toThrow('`region` is missing.'); + }); + + test('does not throw when region is given', async () => { + let actual; + + await expect( + new Promise((resolve, reject) => { + const $client = new QuerySuggestionsApi( + 'my-app-id', + 'my-api-key', + 'us', + { + requester: new EchoRequester(), + } + ); + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).resolves.not.toThrow(); + }); +}); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index f123acb6d8e..8d1768eb0e8 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -1,8 +1,8 @@ // @ts-nocheck import { RecommendApi, EchoRequester } from '@algolia/recommend'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): RecommendApi { return new RecommendApi(appId, apiKey, { requester: new EchoRequester() }); diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index dcddd4750a9..848178086e0 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -1,7 +1,8 @@ +// @ts-nocheck import { SearchApi, EchoRequester } from '@algolia/client-search'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): SearchApi { return new SearchApi(appId, apiKey, { requester: new EchoRequester() }); @@ -20,7 +21,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ host: 'algolia-api-key.algolia.net' }) + expect.objectContaining({ host: 'test-app-id.algolia.net' }) ); }); @@ -189,7 +190,7 @@ describe('parameters', () => { ); await expect( - new Promise((resolve, reject) => { + new Promise((resolve, reject) => { actual = $client.addOrUpdateObject({ indexName: 'my-index-name', objectID: 'my-object-id', diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index 8334a381f45..b9348fbfe64 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -1,8 +1,8 @@ // @ts-nocheck import { SourcesApi, EchoRequester } from '@algolia/client-sources'; -const appId = process.env.ALGOLIA_APPLICATION_ID || 'Algolia-API-Key'; -const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'Algolia-Application-Id'; +const appId = 'test-app-id'; +const apiKey = 'test-api-key'; function createClient(): SourcesApi { return new SourcesApi(appId, apiKey, 'us', { From a3a42489d2795bf496f2e84f762cfcc4f03bac6b Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Wed, 2 Feb 2022 17:03:07 +0100 Subject: [PATCH 07/12] Update suite.mustache --- tests/CTS/client/templates/javascript/suite.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CTS/client/templates/javascript/suite.mustache b/tests/CTS/client/templates/javascript/suite.mustache index b63f4f9c5f9..c9ecd6e2890 100644 --- a/tests/CTS/client/templates/javascript/suite.mustache +++ b/tests/CTS/client/templates/javascript/suite.mustache @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable require-await */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -// @ts-nocheck +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { {{client}}, EchoRequester } from '{{{import}}}'; const appId = 'test-app-id'; From 46fba38e6082c811b896f8198ca72fb3d3dce617 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Mon, 7 Feb 2022 15:03:26 +0100 Subject: [PATCH 08/12] chore: update generated tests --- .../javascript/tests/client/abtesting.test.ts | 18 ++++++------ .../javascript/tests/client/analytics.test.ts | 2 +- .../javascript/tests/client/insights.test.ts | 10 ++++--- .../tests/client/personalization.test.ts | 28 ++++++++----------- .../tests/client/query-suggestions.test.ts | 28 ++++++++----------- .../javascript/tests/client/recommend.test.ts | 10 ++++--- .../javascript/tests/client/search.test.ts | 2 +- .../javascript/tests/client/sources.test.ts | 12 ++++---- 8 files changed, 54 insertions(+), 56 deletions(-) diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index b9b05683a40..b7226b1e01b 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -1,13 +1,13 @@ -// @ts-nocheck -import { AbtestingApi, EchoRequester } from '@algolia/client-abtesting'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { abtestingApi } from '@algolia/client-abtesting'; +import { EchoRequester } from '@algolia/client-common'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): AbtestingApi { - return new AbtestingApi(appId, apiKey, 'us', { - requester: new EchoRequester(), - }); +function createClient() { + return abtestingApi(appId, apiKey, 'us', { requester: new EchoRequester() }); } describe('api', () => { @@ -57,9 +57,10 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - const $client = new AbtestingApi('my-app-id', 'my-api-key', '', { + const $client = abtestingApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); + actual = $client; if (actual instanceof Promise) { @@ -76,9 +77,10 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - const $client = new AbtestingApi('my-app-id', 'my-api-key', 'us', { + const $client = abtestingApi('my-app-id', 'my-api-key', 'us', { requester: new EchoRequester(), }); + actual = $client; if (actual instanceof Promise) { diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index 0092d3e6f0d..f874ec51a67 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -// @ts-nocheck +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { analyticsApi } from '@algolia/client-analytics'; import { EchoRequester } from '@algolia/client-common'; diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index dcc106ae0d0..c56e4fa996e 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -1,11 +1,13 @@ -// @ts-nocheck -import { InsightsApi, EchoRequester } from '@algolia/client-insights'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { EchoRequester } from '@algolia/client-common'; +import { insightsApi } from '@algolia/client-insights'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): InsightsApi { - return new InsightsApi(appId, apiKey, { requester: new EchoRequester() }); +function createClient() { + return insightsApi(appId, apiKey, 'us', { requester: new EchoRequester() }); } describe('api', () => { diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts index 08658ebc592..23972df0939 100644 --- a/tests/output/javascript/tests/client/personalization.test.ts +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -1,14 +1,13 @@ -// @ts-nocheck -import { - PersonalizationApi, - EchoRequester, -} from '@algolia/client-personalization'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { EchoRequester } from '@algolia/client-common'; +import { personalizationApi } from '@algolia/client-personalization'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): PersonalizationApi { - return new PersonalizationApi(appId, apiKey, 'us', { +function createClient() { + return personalizationApi(appId, apiKey, 'us', { requester: new EchoRequester(), }); } @@ -52,9 +51,10 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - const $client = new PersonalizationApi('my-app-id', 'my-api-key', '', { + const $client = personalizationApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); + actual = $client; if (actual instanceof Promise) { @@ -71,14 +71,10 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - const $client = new PersonalizationApi( - 'my-app-id', - 'my-api-key', - 'us', - { - requester: new EchoRequester(), - } - ); + const $client = personalizationApi('my-app-id', 'my-api-key', 'us', { + requester: new EchoRequester(), + }); + actual = $client; if (actual instanceof Promise) { diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts index 6745d0cd635..c6ebc774cce 100644 --- a/tests/output/javascript/tests/client/query-suggestions.test.ts +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -1,14 +1,13 @@ -// @ts-nocheck -import { - QuerySuggestionsApi, - EchoRequester, -} from '@algolia/client-query-suggestions'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { EchoRequester } from '@algolia/client-common'; +import { querySuggestionsApi } from '@algolia/client-query-suggestions'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): QuerySuggestionsApi { - return new QuerySuggestionsApi(appId, apiKey, 'us', { +function createClient() { + return querySuggestionsApi(appId, apiKey, 'us', { requester: new EchoRequester(), }); } @@ -52,9 +51,10 @@ describe('parameters', () => { let actual; await expect( new Promise((resolve, reject) => { - const $client = new QuerySuggestionsApi('my-app-id', 'my-api-key', '', { + const $client = querySuggestionsApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); + actual = $client; if (actual instanceof Promise) { @@ -71,14 +71,10 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - const $client = new QuerySuggestionsApi( - 'my-app-id', - 'my-api-key', - 'us', - { - requester: new EchoRequester(), - } - ); + const $client = querySuggestionsApi('my-app-id', 'my-api-key', 'us', { + requester: new EchoRequester(), + }); + actual = $client; if (actual instanceof Promise) { diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index 8d1768eb0e8..0ec2cf21aca 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -1,11 +1,13 @@ -// @ts-nocheck -import { RecommendApi, EchoRequester } from '@algolia/recommend'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { EchoRequester } from '@algolia/client-common'; +import { recommendApi } from '@algolia/recommend'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): RecommendApi { - return new RecommendApi(appId, apiKey, { requester: new EchoRequester() }); +function createClient() { + return recommendApi(appId, apiKey, { requester: new EchoRequester() }); } describe('api', () => { diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index 35311705e5e..9fe55a4f764 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -// @ts-nocheck +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { searchApi } from '@algolia/client-search'; diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index b9348fbfe64..259d966e7cd 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -1,13 +1,13 @@ -// @ts-nocheck -import { SourcesApi, EchoRequester } from '@algolia/client-sources'; +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. +import { EchoRequester } from '@algolia/client-common'; +import { sourcesApi } from '@algolia/client-sources'; const appId = 'test-app-id'; const apiKey = 'test-api-key'; -function createClient(): SourcesApi { - return new SourcesApi(appId, apiKey, 'us', { - requester: new EchoRequester(), - }); +function createClient() { + return sourcesApi(appId, apiKey, 'us', { requester: new EchoRequester() }); } describe('api', () => { From b3c0b263e28482ed7e5f44d2530040400b05916b Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Mon, 7 Feb 2022 16:07:10 +0100 Subject: [PATCH 09/12] update tests for region --- tests/CTS/client/abtesting/api.json | 2 +- tests/CTS/client/abtesting/parameters.json | 4 ++-- tests/CTS/client/analytics/api.json | 4 ++-- tests/CTS/client/insights/api.json | 2 +- tests/CTS/client/personalization/api.json | 4 ++-- tests/CTS/client/query-suggestions/api.json | 2 +- tests/CTS/client/recommend/api.json | 2 +- tests/CTS/client/search/api.json | 2 +- tests/CTS/client/sources/api.json | 2 +- tests/output/javascript/tests/client/abtesting.test.ts | 7 ++++--- tests/output/javascript/tests/client/analytics.test.ts | 2 +- tests/output/javascript/tests/client/insights.test.ts | 2 +- .../output/javascript/tests/client/personalization.test.ts | 2 +- .../javascript/tests/client/query-suggestions.test.ts | 2 +- tests/output/javascript/tests/client/recommend.test.ts | 2 +- tests/output/javascript/tests/client/search.test.ts | 2 +- tests/output/javascript/tests/client/sources.test.ts | 2 +- 17 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/CTS/client/abtesting/api.json b/tests/CTS/client/abtesting/api.json index 99eee49c34b..ac93bca3867 100644 --- a/tests/CTS/client/abtesting/api.json +++ b/tests/CTS/client/abtesting/api.json @@ -39,7 +39,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/CTS/client/abtesting/parameters.json b/tests/CTS/client/abtesting/parameters.json index 5f097fb0ab4..ee186bbb52c 100644 --- a/tests/CTS/client/abtesting/parameters.json +++ b/tests/CTS/client/abtesting/parameters.json @@ -1,6 +1,6 @@ [ { - "testName": "throws when region is not given", + "testName": "does not throw when region is not given", "autoCreateClient": false, "steps": [ { @@ -11,7 +11,7 @@ "region": "" }, "expected": { - "error": "`region` is missing." + "error": false } } ] diff --git a/tests/CTS/client/analytics/api.json b/tests/CTS/client/analytics/api.json index ae0c75c2b4e..0e4ff3a3ed8 100644 --- a/tests/CTS/client/analytics/api.json +++ b/tests/CTS/client/analytics/api.json @@ -27,8 +27,8 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, - "responseTimeout": 5 + "connectTimeout": 1, + "responseTimeout": 2 } } } diff --git a/tests/CTS/client/insights/api.json b/tests/CTS/client/insights/api.json index 1256ff24a4a..dcfe5c85742 100644 --- a/tests/CTS/client/insights/api.json +++ b/tests/CTS/client/insights/api.json @@ -35,7 +35,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/CTS/client/personalization/api.json b/tests/CTS/client/personalization/api.json index fa8e43d7faa..e461aca0fc6 100644 --- a/tests/CTS/client/personalization/api.json +++ b/tests/CTS/client/personalization/api.json @@ -27,8 +27,8 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, - "responseTimeout": 5 + "connectTimeout": 1, + "responseTimeout": 2 } } } diff --git a/tests/CTS/client/query-suggestions/api.json b/tests/CTS/client/query-suggestions/api.json index ea3f7ab0571..44af4b20ca5 100644 --- a/tests/CTS/client/query-suggestions/api.json +++ b/tests/CTS/client/query-suggestions/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/CTS/client/recommend/api.json b/tests/CTS/client/recommend/api.json index ae75ea92ae0..54cb2e14776 100644 --- a/tests/CTS/client/recommend/api.json +++ b/tests/CTS/client/recommend/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/CTS/client/search/api.json b/tests/CTS/client/search/api.json index b0513a010f1..b92b4deb7d5 100644 --- a/tests/CTS/client/search/api.json +++ b/tests/CTS/client/search/api.json @@ -45,7 +45,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/CTS/client/sources/api.json b/tests/CTS/client/sources/api.json index 292dd86ea2f..efb0220a1e4 100644 --- a/tests/CTS/client/sources/api.json +++ b/tests/CTS/client/sources/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 2, + "connectTimeout": 1, "responseTimeout": 30 } } diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index b7226b1e01b..005cf094d01 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -47,14 +47,15 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); describe('parameters', () => { - test('throws when region is not given', async () => { + test('does not throw when region is not given', async () => { let actual; + await expect( new Promise((resolve, reject) => { const $client = abtestingApi('my-app-id', 'my-api-key', '', { @@ -69,7 +70,7 @@ describe('parameters', () => { resolve(); } }) - ).rejects.toThrow('`region` is missing.'); + ).resolves.not.toThrow(); }); test('does not throw when region is given', async () => { diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index f874ec51a67..a82ff681fcf 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -39,7 +39,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 2 }) ); }); }); diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index c56e4fa996e..c3b91e98b24 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -39,7 +39,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts index 23972df0939..b050fbaf1f5 100644 --- a/tests/output/javascript/tests/client/personalization.test.ts +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -41,7 +41,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 2 }) ); }); }); diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts index c6ebc774cce..23a4c7e01e1 100644 --- a/tests/output/javascript/tests/client/query-suggestions.test.ts +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -41,7 +41,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index 0ec2cf21aca..1ca5ba9f844 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -39,7 +39,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index 9fe55a4f764..c0bbb92a513 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -55,7 +55,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index 259d966e7cd..c8f39116496 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -39,7 +39,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) ); }); }); From 60877e8382b7725f5b9c4b4ff58650452d6cce62 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Mon, 7 Feb 2022 16:16:37 +0100 Subject: [PATCH 10/12] fix wrong timeouts --- tests/CTS/client/abtesting/api.json | 2 +- tests/CTS/client/analytics/api.json | 4 ++-- tests/CTS/client/insights/api.json | 2 +- tests/CTS/client/personalization/api.json | 4 ++-- tests/CTS/client/query-suggestions/api.json | 2 +- tests/CTS/client/recommend/api.json | 2 +- tests/CTS/client/search/api.json | 2 +- tests/CTS/client/sources/api.json | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/CTS/client/abtesting/api.json b/tests/CTS/client/abtesting/api.json index ac93bca3867..99eee49c34b 100644 --- a/tests/CTS/client/abtesting/api.json +++ b/tests/CTS/client/abtesting/api.json @@ -39,7 +39,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } diff --git a/tests/CTS/client/analytics/api.json b/tests/CTS/client/analytics/api.json index 0e4ff3a3ed8..ae0c75c2b4e 100644 --- a/tests/CTS/client/analytics/api.json +++ b/tests/CTS/client/analytics/api.json @@ -27,8 +27,8 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, - "responseTimeout": 2 + "connectTimeout": 2, + "responseTimeout": 5 } } } diff --git a/tests/CTS/client/insights/api.json b/tests/CTS/client/insights/api.json index dcfe5c85742..1256ff24a4a 100644 --- a/tests/CTS/client/insights/api.json +++ b/tests/CTS/client/insights/api.json @@ -35,7 +35,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } diff --git a/tests/CTS/client/personalization/api.json b/tests/CTS/client/personalization/api.json index e461aca0fc6..fa8e43d7faa 100644 --- a/tests/CTS/client/personalization/api.json +++ b/tests/CTS/client/personalization/api.json @@ -27,8 +27,8 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, - "responseTimeout": 2 + "connectTimeout": 2, + "responseTimeout": 5 } } } diff --git a/tests/CTS/client/query-suggestions/api.json b/tests/CTS/client/query-suggestions/api.json index 44af4b20ca5..ea3f7ab0571 100644 --- a/tests/CTS/client/query-suggestions/api.json +++ b/tests/CTS/client/query-suggestions/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } diff --git a/tests/CTS/client/recommend/api.json b/tests/CTS/client/recommend/api.json index 54cb2e14776..ae75ea92ae0 100644 --- a/tests/CTS/client/recommend/api.json +++ b/tests/CTS/client/recommend/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } diff --git a/tests/CTS/client/search/api.json b/tests/CTS/client/search/api.json index b92b4deb7d5..b0513a010f1 100644 --- a/tests/CTS/client/search/api.json +++ b/tests/CTS/client/search/api.json @@ -45,7 +45,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } diff --git a/tests/CTS/client/sources/api.json b/tests/CTS/client/sources/api.json index efb0220a1e4..292dd86ea2f 100644 --- a/tests/CTS/client/sources/api.json +++ b/tests/CTS/client/sources/api.json @@ -27,7 +27,7 @@ "expected": { "match": { "objectContaining": { - "connectTimeout": 1, + "connectTimeout": 2, "responseTimeout": 30 } } From f31b4b0d53e221743b094ed5896b4a78274a4c77 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 8 Feb 2022 14:43:10 +0100 Subject: [PATCH 11/12] wip --- tests/CTS/client/abtesting/parameters.json | 19 +++++++++++- .../client/templates/javascript/step.mustache | 2 +- .../templates/javascript/suite.mustache | 4 ++- .../javascript/tests/client/abtesting.test.ts | 29 +++++++++++++++---- .../javascript/tests/client/analytics.test.ts | 16 ++++++---- .../javascript/tests/client/insights.test.ts | 9 ++++-- .../tests/client/personalization.test.ts | 17 +++++++---- .../tests/client/query-suggestions.test.ts | 17 +++++++---- .../javascript/tests/client/recommend.test.ts | 9 ++++-- .../javascript/tests/client/search.test.ts | 26 +++++++++++------ .../javascript/tests/client/sources.test.ts | 9 ++++-- 11 files changed, 115 insertions(+), 42 deletions(-) diff --git a/tests/CTS/client/abtesting/parameters.json b/tests/CTS/client/abtesting/parameters.json index ee186bbb52c..45579c14d13 100644 --- a/tests/CTS/client/abtesting/parameters.json +++ b/tests/CTS/client/abtesting/parameters.json @@ -1,6 +1,6 @@ [ { - "testName": "does not throw when region is not given", + "testName": "fallbacks to the alias when region is not given", "autoCreateClient": false, "steps": [ { @@ -13,6 +13,23 @@ "expected": { "error": false } + }, + { + "type": "method", + "object": "$client", + "path": "getABTest", + "parameters": [ + { + "id": "test" + } + ], + "expected": { + "match": { + "objectContaining": { + "host": "analytics.us.algolia.com" + } + } + } } ] }, diff --git a/tests/CTS/client/templates/javascript/step.mustache b/tests/CTS/client/templates/javascript/step.mustache index 7b1854b3d4f..d03394f619f 100644 --- a/tests/CTS/client/templates/javascript/step.mustache +++ b/tests/CTS/client/templates/javascript/step.mustache @@ -1,5 +1,5 @@ {{#isCreateClient}} - const $client = {{> createClient}} + $client = {{> createClient}} actual = $client; {{/isCreateClient}} diff --git a/tests/CTS/client/templates/javascript/suite.mustache b/tests/CTS/client/templates/javascript/suite.mustache index 76029137d79..cb8490cc2ed 100644 --- a/tests/CTS/client/templates/javascript/suite.mustache +++ b/tests/CTS/client/templates/javascript/suite.mustache @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable require-await */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { {{client}} } from '{{{import}}}'; import { EchoRequester } from '@algolia/client-common'; @@ -17,8 +18,9 @@ function createClient() { describe('{{operationId}}', () => { {{#tests}} test('{{{testName}}}', async () => { + let $client; {{#autoCreateClient}} - const $client = createClient(); + $client = createClient(); {{/autoCreateClient}} let actual; diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index 005cf094d01..422e88ce4a5 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { abtestingApi } from '@algolia/client-abtesting'; import { EchoRequester } from '@algolia/client-common'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -32,7 +34,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -47,18 +50,20 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); describe('parameters', () => { - test('does not throw when region is not given', async () => { + test('fallbacks to the alias when region is not given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = abtestingApi('my-app-id', 'my-api-key', '', { + $client = abtestingApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); @@ -71,14 +76,26 @@ describe('parameters', () => { } }) ).resolves.not.toThrow(); + + actual = $client.getABTest({ id: 'test' }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'analytics.us.algolia.com' }) + ); }); test('does not throw when region is given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = abtestingApi('my-app-id', 'my-api-key', 'us', { + $client = abtestingApi('my-app-id', 'my-api-key', 'us', { requester: new EchoRequester(), }); diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index a82ff681fcf..be3e91f36a6 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { analyticsApi } from '@algolia/client-analytics'; import { EchoRequester } from '@algolia/client-common'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -28,7 +30,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -39,18 +42,20 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 2 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) ); }); }); describe('parameters', () => { test('does not throw when region is not given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = analyticsApi('my-app-id', 'my-api-key', '', { + $client = analyticsApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); @@ -66,7 +71,8 @@ describe('parameters', () => { }); test('getAverageClickPosition throws without index', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; await expect( diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index c3b91e98b24..3eb65433b81 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { insightsApi } from '@algolia/client-insights'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -28,7 +30,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -39,7 +42,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/personalization.test.ts b/tests/output/javascript/tests/client/personalization.test.ts index b050fbaf1f5..889303cdd8b 100644 --- a/tests/output/javascript/tests/client/personalization.test.ts +++ b/tests/output/javascript/tests/client/personalization.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { personalizationApi } from '@algolia/client-personalization'; @@ -14,7 +15,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -30,7 +32,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -41,17 +44,19 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 2 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 5 }) ); }); }); describe('parameters', () => { test('throws when region is not given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = personalizationApi('my-app-id', 'my-api-key', '', { + $client = personalizationApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); @@ -67,11 +72,13 @@ describe('parameters', () => { }); test('does not throw when region is given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = personalizationApi('my-app-id', 'my-api-key', 'us', { + $client = personalizationApi('my-app-id', 'my-api-key', 'us', { requester: new EchoRequester(), }); diff --git a/tests/output/javascript/tests/client/query-suggestions.test.ts b/tests/output/javascript/tests/client/query-suggestions.test.ts index 23a4c7e01e1..1bcfb930fdf 100644 --- a/tests/output/javascript/tests/client/query-suggestions.test.ts +++ b/tests/output/javascript/tests/client/query-suggestions.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { querySuggestionsApi } from '@algolia/client-query-suggestions'; @@ -14,7 +15,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -30,7 +32,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -41,17 +44,19 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); describe('parameters', () => { test('throws when region is not given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = querySuggestionsApi('my-app-id', 'my-api-key', '', { + $client = querySuggestionsApi('my-app-id', 'my-api-key', '', { requester: new EchoRequester(), }); @@ -67,11 +72,13 @@ describe('parameters', () => { }); test('does not throw when region is given', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = querySuggestionsApi('my-app-id', 'my-api-key', 'us', { + $client = querySuggestionsApi('my-app-id', 'my-api-key', 'us', { requester: new EchoRequester(), }); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index 1ca5ba9f844..2683bc6f9c2 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { recommendApi } from '@algolia/recommend'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -28,7 +30,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -39,7 +42,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); diff --git a/tests/output/javascript/tests/client/search.test.ts b/tests/output/javascript/tests/client/search.test.ts index c0bbb92a513..db91a6dbe03 100644 --- a/tests/output/javascript/tests/client/search.test.ts +++ b/tests/output/javascript/tests/client/search.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { searchApi } from '@algolia/client-search'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct host', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -28,7 +30,8 @@ describe('api', () => { }); test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -44,7 +47,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -55,17 +59,19 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); describe('parameters', () => { test('client throws with invalid parameters', async () => { + let $client; + let actual; await expect( new Promise((resolve, reject) => { - const $client = searchApi('', '', { requester: new EchoRequester() }); + $client = searchApi('', '', { requester: new EchoRequester() }); actual = $client; @@ -79,7 +85,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - const $client = searchApi('', 'my-api-key', { + $client = searchApi('', 'my-api-key', { requester: new EchoRequester(), }); @@ -95,7 +101,7 @@ describe('parameters', () => { await expect( new Promise((resolve, reject) => { - const $client = searchApi('my-app-id', '', { + $client = searchApi('my-app-id', '', { requester: new EchoRequester(), }); @@ -111,7 +117,8 @@ describe('parameters', () => { }); test('`addApiKey` throws with invalid parameters', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; await expect( @@ -142,7 +149,8 @@ describe('parameters', () => { }); test('`addOrUpdateObject` throws with invalid parameters', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; await expect( diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index c8f39116496..92ea941e218 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable prefer-const */ // @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines. import { EchoRequester } from '@algolia/client-common'; import { sourcesApi } from '@algolia/client-sources'; @@ -12,7 +13,8 @@ function createClient() { describe('api', () => { test('calls api with correct user agent', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -28,7 +30,8 @@ describe('api', () => { }); test('calls api with correct timeouts', async () => { - const $client = createClient(); + let $client; + $client = createClient(); let actual; @@ -39,7 +42,7 @@ describe('api', () => { } expect(actual).toEqual( - expect.objectContaining({ connectTimeout: 1, responseTimeout: 30 }) + expect.objectContaining({ connectTimeout: 2, responseTimeout: 30 }) ); }); }); From 835e92afca68a79bb81ccb420fc91a15761b39bd Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Tue, 8 Feb 2022 15:37:41 +0100 Subject: [PATCH 12/12] update region tests --- tests/CTS/client/abtesting/parameters.json | 19 +----- tests/CTS/client/analytics/parameters.json | 15 ++++- tests/CTS/client/insights/parameters.json | 32 ++++++++++ tests/CTS/client/recommend/api.json | 18 ++++++ tests/CTS/client/sources/api.json | 18 ++++++ tests/CTS/client/sources/parameters.json | 36 +++++++++++ .../javascript/tests/client/abtesting.test.ts | 24 +------ .../javascript/tests/client/analytics.test.ts | 12 +++- .../javascript/tests/client/insights.test.ts | 34 ++++++++++ .../javascript/tests/client/recommend.test.ts | 17 +++++ .../javascript/tests/client/sources.test.ts | 62 +++++++++++++++++++ 11 files changed, 244 insertions(+), 43 deletions(-) create mode 100644 tests/CTS/client/insights/parameters.json create mode 100644 tests/CTS/client/sources/parameters.json diff --git a/tests/CTS/client/abtesting/parameters.json b/tests/CTS/client/abtesting/parameters.json index 45579c14d13..ae44b7123b4 100644 --- a/tests/CTS/client/abtesting/parameters.json +++ b/tests/CTS/client/abtesting/parameters.json @@ -26,28 +26,11 @@ "expected": { "match": { "objectContaining": { - "host": "analytics.us.algolia.com" + "host": "analytics.algolia.com" } } } } ] - }, - { - "testName": "does not throw when region is given", - "autoCreateClient": false, - "steps": [ - { - "type": "createClient", - "parameters": { - "appId": "my-app-id", - "apiKey": "my-api-key", - "region": "us" - }, - "expected": { - "error": false - } - } - ] } ] diff --git a/tests/CTS/client/analytics/parameters.json b/tests/CTS/client/analytics/parameters.json index 7d539ef3c3d..df7387b8de3 100644 --- a/tests/CTS/client/analytics/parameters.json +++ b/tests/CTS/client/analytics/parameters.json @@ -1,6 +1,6 @@ [ { - "testName": "does not throw when region is not given", + "testName": "fallbacks to the alias when region is not given", "autoCreateClient": false, "steps": [ { @@ -13,6 +13,19 @@ "expected": { "error": false } + }, + { + "type": "method", + "object": "$client", + "path": "getAverageClickPosition", + "parameters": [{ "index": "my-index" }], + "expected": { + "match": { + "objectContaining": { + "host": "analytics.algolia.com" + } + } + } } ] }, diff --git a/tests/CTS/client/insights/parameters.json b/tests/CTS/client/insights/parameters.json new file mode 100644 index 00000000000..c7ca54f2121 --- /dev/null +++ b/tests/CTS/client/insights/parameters.json @@ -0,0 +1,32 @@ +[ + { + "testName": "fallbacks to the alias when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": false + } + }, + { + "type": "method", + "object": "$client", + "path": "pushEvents", + "parameters": [{ "events": [] }], + "expected": { + "match": { + "objectContaining": { + "host": "insights.algolia.io" + } + } + } + } + ] + } +] diff --git a/tests/CTS/client/recommend/api.json b/tests/CTS/client/recommend/api.json index ae75ea92ae0..b402d3847a5 100644 --- a/tests/CTS/client/recommend/api.json +++ b/tests/CTS/client/recommend/api.json @@ -1,4 +1,22 @@ [ + { + "testName": "calls api with correct host", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "getRecommendations", + "parameters": [{ "requests": [] }], + "expected": { + "match": { + "objectContaining": { + "host": "test-app-id.algolia.net" + } + } + } + } + ] + }, { "testName": "calls api with correct user agent", "steps": [ diff --git a/tests/CTS/client/sources/api.json b/tests/CTS/client/sources/api.json index 292dd86ea2f..ac87c64ead6 100644 --- a/tests/CTS/client/sources/api.json +++ b/tests/CTS/client/sources/api.json @@ -1,4 +1,22 @@ [ + { + "testName": "calls api with correct host", + "steps": [ + { + "type": "method", + "object": "$client", + "path": "postIngestUrl", + "parameters": [{ "type": "csv", "input": { "url": "..." } }], + "expected": { + "match": { + "objectContaining": { + "host": "data.us.algolia.com" + } + } + } + } + ] + }, { "testName": "calls api with correct user agent", "steps": [ diff --git a/tests/CTS/client/sources/parameters.json b/tests/CTS/client/sources/parameters.json new file mode 100644 index 00000000000..5f097fb0ab4 --- /dev/null +++ b/tests/CTS/client/sources/parameters.json @@ -0,0 +1,36 @@ +[ + { + "testName": "throws when region is not given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "" + }, + "expected": { + "error": "`region` is missing." + } + } + ] + }, + { + "testName": "does not throw when region is given", + "autoCreateClient": false, + "steps": [ + { + "type": "createClient", + "parameters": { + "appId": "my-app-id", + "apiKey": "my-api-key", + "region": "us" + }, + "expected": { + "error": false + } + } + ] + } +] diff --git a/tests/output/javascript/tests/client/abtesting.test.ts b/tests/output/javascript/tests/client/abtesting.test.ts index 422e88ce4a5..77cd6a156cb 100644 --- a/tests/output/javascript/tests/client/abtesting.test.ts +++ b/tests/output/javascript/tests/client/abtesting.test.ts @@ -84,29 +84,7 @@ describe('parameters', () => { } expect(actual).toEqual( - expect.objectContaining({ host: 'analytics.us.algolia.com' }) + expect.objectContaining({ host: 'analytics.algolia.com' }) ); }); - - test('does not throw when region is given', async () => { - let $client; - - let actual; - - await expect( - new Promise((resolve, reject) => { - $client = abtestingApi('my-app-id', 'my-api-key', 'us', { - requester: new EchoRequester(), - }); - - actual = $client; - - if (actual instanceof Promise) { - actual.then(resolve).catch(reject); - } else { - resolve(); - } - }) - ).resolves.not.toThrow(); - }); }); diff --git a/tests/output/javascript/tests/client/analytics.test.ts b/tests/output/javascript/tests/client/analytics.test.ts index be3e91f36a6..a3bb0f173e1 100644 --- a/tests/output/javascript/tests/client/analytics.test.ts +++ b/tests/output/javascript/tests/client/analytics.test.ts @@ -48,7 +48,7 @@ describe('api', () => { }); describe('parameters', () => { - test('does not throw when region is not given', async () => { + test('fallbacks to the alias when region is not given', async () => { let $client; let actual; @@ -68,6 +68,16 @@ describe('parameters', () => { } }) ).resolves.not.toThrow(); + + actual = $client.getAverageClickPosition({ index: 'my-index' }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'analytics.algolia.com' }) + ); }); test('getAverageClickPosition throws without index', async () => { diff --git a/tests/output/javascript/tests/client/insights.test.ts b/tests/output/javascript/tests/client/insights.test.ts index 3eb65433b81..4d90bdb5faf 100644 --- a/tests/output/javascript/tests/client/insights.test.ts +++ b/tests/output/javascript/tests/client/insights.test.ts @@ -46,3 +46,37 @@ describe('api', () => { ); }); }); + +describe('parameters', () => { + test('fallbacks to the alias when region is not given', async () => { + let $client; + + let actual; + + await expect( + new Promise((resolve, reject) => { + $client = insightsApi('my-app-id', 'my-api-key', '', { + requester: new EchoRequester(), + }); + + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).resolves.not.toThrow(); + + actual = $client.pushEvents({ events: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'insights.algolia.io' }) + ); + }); +}); diff --git a/tests/output/javascript/tests/client/recommend.test.ts b/tests/output/javascript/tests/client/recommend.test.ts index 2683bc6f9c2..833aacf4e52 100644 --- a/tests/output/javascript/tests/client/recommend.test.ts +++ b/tests/output/javascript/tests/client/recommend.test.ts @@ -12,6 +12,23 @@ function createClient() { } describe('api', () => { + test('calls api with correct host', async () => { + let $client; + $client = createClient(); + + let actual; + + actual = $client.getRecommendations({ requests: [] }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'test-app-id.algolia.net' }) + ); + }); + test('calls api with correct user agent', async () => { let $client; $client = createClient(); diff --git a/tests/output/javascript/tests/client/sources.test.ts b/tests/output/javascript/tests/client/sources.test.ts index 92ea941e218..846f1e1cd27 100644 --- a/tests/output/javascript/tests/client/sources.test.ts +++ b/tests/output/javascript/tests/client/sources.test.ts @@ -12,6 +12,23 @@ function createClient() { } describe('api', () => { + test('calls api with correct host', async () => { + let $client; + $client = createClient(); + + let actual; + + actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } }); + + if (actual instanceof Promise) { + actual = await actual; + } + + expect(actual).toEqual( + expect.objectContaining({ host: 'data.us.algolia.com' }) + ); + }); + test('calls api with correct user agent', async () => { let $client; $client = createClient(); @@ -46,3 +63,48 @@ describe('api', () => { ); }); }); + +describe('parameters', () => { + test('throws when region is not given', async () => { + let $client; + + let actual; + await expect( + new Promise((resolve, reject) => { + $client = sourcesApi('my-app-id', 'my-api-key', '', { + requester: new EchoRequester(), + }); + + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).rejects.toThrow('`region` is missing.'); + }); + + test('does not throw when region is given', async () => { + let $client; + + let actual; + + await expect( + new Promise((resolve, reject) => { + $client = sourcesApi('my-app-id', 'my-api-key', 'us', { + requester: new EchoRequester(), + }); + + actual = $client; + + if (actual instanceof Promise) { + actual.then(resolve).catch(reject); + } else { + resolve(); + } + }) + ).resolves.not.toThrow(); + }); +});