From c4950a886300ac31dc3fcae6c83353285f45e3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 7 Jan 2022 10:29:15 +0100 Subject: [PATCH 1/9] feat(cts): add tests for `analytics` --- .../clients/analytics/getSearchesCount.json | 4 ++ tests/output/javascript/analytics.test.ts | 52 +++++++++---------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/tests/CTS/clients/analytics/getSearchesCount.json b/tests/CTS/clients/analytics/getSearchesCount.json index 4c6a1d0aad..eae971cdd0 100644 --- a/tests/CTS/clients/analytics/getSearchesCount.json +++ b/tests/CTS/clients/analytics/getSearchesCount.json @@ -15,7 +15,11 @@ "testName": "get getSearchesCount with all parameters", "parameters": { "index": "index", +<<<<<<< HEAD "startDate": "1999-09-19", +======= + "startDate": "1999-19-09", +>>>>>>> b51ff01... feat(cts): add tests for `analytics` "endDate": "2001-01-01", "tags": "tag" }, diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 6e8db81ee1..fd37154b93 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -22,7 +22,7 @@ describe('getAverageClickPosition', () => { test('get getAverageClickPosition with all parameters', async () => { const req = await client.getAverageClickPosition({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -49,7 +49,7 @@ describe('getClickPositions', () => { test('get getClickPositions with all parameters', async () => { const req = await client.getClickPositions({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -76,7 +76,7 @@ describe('getClickThroughRate', () => { test('get getClickThroughRate with all parameters', async () => { const req = await client.getClickThroughRate({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -103,7 +103,7 @@ describe('getConversationRate', () => { test('get getConversationRate with all parameters', async () => { const req = await client.getConversationRate({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -130,7 +130,7 @@ describe('getNoClickRate', () => { test('get getNoClickRate with all parameters', async () => { const req = await client.getNoClickRate({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -157,7 +157,7 @@ describe('getNoResultsRate', () => { test('get getNoResultsRate with all parameters', async () => { const req = await client.getNoResultsRate({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -184,7 +184,7 @@ describe('getSearchesCount', () => { test('get getSearchesCount with all parameters', async () => { const req = await client.getSearchesCount({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -211,7 +211,7 @@ describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with all parameters', async () => { const req = await client.getSearchesNoClicks({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -240,7 +240,7 @@ describe('getSearchesNoResults', () => { test('get getSearchesNoResults with all parameters', async () => { const req = await client.getSearchesNoResults({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -282,7 +282,7 @@ describe('getTopCountries', () => { test('get getTopCountries with all parameters', async () => { const req = await client.getTopCountries({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -311,7 +311,7 @@ describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with all parameters', async () => { const req = await client.getTopFilterAttributes({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -342,7 +342,7 @@ describe('getTopFilterAttributesForSearch', () => { const req = await client.getTopFilterAttributesForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -376,7 +376,7 @@ describe('getTopFilterForAttribute', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2', + path: '/2/filters/myAttribute1,myAttribute2', method: 'GET', }); }); @@ -385,7 +385,7 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -402,7 +402,7 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -410,7 +410,7 @@ describe('getTopFilterForAttribute', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2', + path: '/2/filters/myAttribute1,myAttribute2', method: 'GET', }); }); @@ -438,7 +438,7 @@ describe('getTopFiltersForAttributesSearch', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', + path: '/2/filters/myAttribute1,myAttribute2?search=mySearch', method: 'GET', }); }); @@ -448,7 +448,7 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute', index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -466,7 +466,7 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute1,myAttribute2', index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -474,7 +474,7 @@ describe('getTopFiltersForAttributesSearch', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', + path: '/2/filters/myAttribute1,myAttribute2?search=mySearch', method: 'GET', }); }); @@ -495,7 +495,7 @@ describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with all parameters', async () => { const req = await client.getTopFiltersNoResults({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -526,7 +526,7 @@ describe('getTopFiltersNoResultsForSearch', () => { const req = await client.getTopFiltersNoResultsForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -556,7 +556,7 @@ describe('getTopHits', () => { const req = await client.getTopHits({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -588,7 +588,7 @@ describe('getTopHitsForSearch', () => { index: 'index', search: 'mySearch', clickAnalytics: true, - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -618,7 +618,7 @@ describe('getTopSearches', () => { const req = await client.getTopSearches({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), orderBy: 'searchCount', direction: 'asc', @@ -649,7 +649,7 @@ describe('getUsersCount', () => { test('get getUsersCount with all parameters', async () => { const req = await client.getUsersCount({ index: 'index', - startDate: new Date('1999-09-19'), + startDate: new Date('1999-19-09'), endDate: new Date('2001-01-01'), tags: 'tag', }); From bfbf975c21a58c00645b2b475ceff7f64e89d2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 7 Jan 2022 13:47:40 +0100 Subject: [PATCH 2/9] fix: tests, date --- .../clients/analytics/getSearchesCount.json | 4 -- tests/output/javascript/analytics.test.ts | 52 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/tests/CTS/clients/analytics/getSearchesCount.json b/tests/CTS/clients/analytics/getSearchesCount.json index eae971cdd0..4c6a1d0aad 100644 --- a/tests/CTS/clients/analytics/getSearchesCount.json +++ b/tests/CTS/clients/analytics/getSearchesCount.json @@ -15,11 +15,7 @@ "testName": "get getSearchesCount with all parameters", "parameters": { "index": "index", -<<<<<<< HEAD "startDate": "1999-09-19", -======= - "startDate": "1999-19-09", ->>>>>>> b51ff01... feat(cts): add tests for `analytics` "endDate": "2001-01-01", "tags": "tag" }, diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index fd37154b93..6e8db81ee1 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -22,7 +22,7 @@ describe('getAverageClickPosition', () => { test('get getAverageClickPosition with all parameters', async () => { const req = await client.getAverageClickPosition({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -49,7 +49,7 @@ describe('getClickPositions', () => { test('get getClickPositions with all parameters', async () => { const req = await client.getClickPositions({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -76,7 +76,7 @@ describe('getClickThroughRate', () => { test('get getClickThroughRate with all parameters', async () => { const req = await client.getClickThroughRate({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -103,7 +103,7 @@ describe('getConversationRate', () => { test('get getConversationRate with all parameters', async () => { const req = await client.getConversationRate({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -130,7 +130,7 @@ describe('getNoClickRate', () => { test('get getNoClickRate with all parameters', async () => { const req = await client.getNoClickRate({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -157,7 +157,7 @@ describe('getNoResultsRate', () => { test('get getNoResultsRate with all parameters', async () => { const req = await client.getNoResultsRate({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -184,7 +184,7 @@ describe('getSearchesCount', () => { test('get getSearchesCount with all parameters', async () => { const req = await client.getSearchesCount({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); @@ -211,7 +211,7 @@ describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with all parameters', async () => { const req = await client.getSearchesNoClicks({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -240,7 +240,7 @@ describe('getSearchesNoResults', () => { test('get getSearchesNoResults with all parameters', async () => { const req = await client.getSearchesNoResults({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -282,7 +282,7 @@ describe('getTopCountries', () => { test('get getTopCountries with all parameters', async () => { const req = await client.getTopCountries({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -311,7 +311,7 @@ describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with all parameters', async () => { const req = await client.getTopFilterAttributes({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -342,7 +342,7 @@ describe('getTopFilterAttributesForSearch', () => { const req = await client.getTopFilterAttributesForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -376,7 +376,7 @@ describe('getTopFilterForAttribute', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1,myAttribute2', + path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', }); }); @@ -385,7 +385,7 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -402,7 +402,7 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -410,7 +410,7 @@ describe('getTopFilterForAttribute', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1,myAttribute2', + path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', }); }); @@ -438,7 +438,7 @@ describe('getTopFiltersForAttributesSearch', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1,myAttribute2?search=mySearch', + path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', method: 'GET', }); }); @@ -448,7 +448,7 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute', index: 'index', search: 'mySearch', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -466,7 +466,7 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute1,myAttribute2', index: 'index', search: 'mySearch', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -474,7 +474,7 @@ describe('getTopFiltersForAttributesSearch', () => { }); expect(req).toMatchObject({ - path: '/2/filters/myAttribute1,myAttribute2?search=mySearch', + path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', method: 'GET', }); }); @@ -495,7 +495,7 @@ describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with all parameters', async () => { const req = await client.getTopFiltersNoResults({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -526,7 +526,7 @@ describe('getTopFiltersNoResultsForSearch', () => { const req = await client.getTopFiltersNoResultsForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -556,7 +556,7 @@ describe('getTopHits', () => { const req = await client.getTopHits({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -588,7 +588,7 @@ describe('getTopHitsForSearch', () => { index: 'index', search: 'mySearch', clickAnalytics: true, - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), limit: 21, offset: 42, @@ -618,7 +618,7 @@ describe('getTopSearches', () => { const req = await client.getTopSearches({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), orderBy: 'searchCount', direction: 'asc', @@ -649,7 +649,7 @@ describe('getUsersCount', () => { test('get getUsersCount with all parameters', async () => { const req = await client.getUsersCount({ index: 'index', - startDate: new Date('1999-19-09'), + startDate: new Date('1999-09-19'), endDate: new Date('2001-01-01'), tags: 'tag', }); From a14b79210ab5c19073b71f18e65945a82e9a6fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 7 Jan 2022 13:37:48 +0100 Subject: [PATCH 3/9] feat(js): pass `searchParams` to `EchoRequester`, update CTS --- .../utils/requester/EchoRequester.ts | 43 +- .../utils/requester/EchoRequester.ts | 43 +- .../utils/requester/EchoRequester.ts | 43 +- .../utils/requester/EchoRequester.ts | 43 +- .../utils/requester/EchoRequester.ts | 43 +- .../utils/requester/EchoRequester.ts | 43 +- tests/CTS/templates/javascript.mustache | 6 +- tests/generateCTS.ts | 7 +- tests/output/javascript/analytics.test.ts | 452 +++++++++------- tests/output/javascript/insights.test.ts | 72 +-- .../output/javascript/personalization.test.ts | 52 +- tests/output/javascript/recommend.test.ts | 198 +++---- tests/output/javascript/search.test.ts | 508 ++++++++++-------- 13 files changed, 985 insertions(+), 568 deletions(-) diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts index 41a3dd9041..1eec310f8c 100644 --- a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts @@ -2,14 +2,53 @@ import type { EndRequest, Request, Response } from '../types'; import { Requester } from './Requester'; +type AdditionalContent = { + headers: Record; + searchParams: string | undefined; + userAgent: string | undefined; + connectTimeout: number; + responseTimeout: number; +}; + +function searchParamsWithoutUA(params: URLSearchParams): string | undefined { + let searchParams = '?'; + + for (const [k, v] of params) { + if (k === 'x-algolia-agent') { + continue; + } + + searchParams += encodeURI(`${k}=${v}&`); + } + + if (searchParams === '?') { + return undefined; + } + + return searchParams.replace(/&$/, ''); +} + export class EchoRequester extends Requester { constructor(private status = 200) { super(); } - send(_request: EndRequest, originalRequest: Request): Promise { + send( + { headers, url, connectTimeout, responseTimeout }: EndRequest, + originalRequest: Request + ): Promise { + const urlSearchParams = new URL(url).searchParams; + const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const additionalContent: AdditionalContent = { + headers, + connectTimeout, + responseTimeout, + userAgent: userAgent ? encodeURI(userAgent) : undefined, + searchParams: searchParamsWithoutUA(urlSearchParams), + }; + return Promise.resolve({ - content: JSON.stringify(originalRequest), + content: JSON.stringify({ ...originalRequest, ...additionalContent }), isTimedOut: false, status: this.status, }); diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index fdbd45f751..49afd3a14e 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -17,11 +17,11 @@ describe('{{operationId}}', () => { }{{/hasParameters}} ); - expect(req).toMatchObject({ + expect(req).toEqual(expect.objectContaining({ path: '{{{request.path}}}', method: '{{{request.method}}}', - {{#request.data}}data: {{{.}}},{{/request.data}} - }) + {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: {{{.}}},{{/request.searchParams}} + })) }); {{/tests}} diff --git a/tests/generateCTS.ts b/tests/generateCTS.ts index d362f8b14f..e829b6f5ae 100644 --- a/tests/generateCTS.ts +++ b/tests/generateCTS.ts @@ -30,7 +30,10 @@ type Tests = { request: { path: string; method: string; + headers: string; + userAgent: string; data?: string; + searchParams?: string; }; }; @@ -128,9 +131,11 @@ async function loadCTSForClient(client: string): Promise { if (test.testName === undefined) { test.testName = test.method; } - // stringify request.data too test.request.data = JSON.stringify(test.request.data); + test.request.headers = JSON.stringify(test.request.headers); + test.request.searchParams = JSON.stringify(test.request.searchParams); + test.request.userAgent = JSON.stringify(test.request.userAgent); if (Object.keys(test.parameters).length === 0) { test.parameters = undefined; diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 6e8db81ee1..83b1828011 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -13,10 +13,12 @@ describe('getAverageClickPosition', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/clicks/averageClickPosition', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/averageClickPosition', + method: 'GET', + }) + ); }); test('get getAverageClickPosition with all parameters', async () => { @@ -27,10 +29,12 @@ describe('getAverageClickPosition', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/clicks/averageClickPosition', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/averageClickPosition', + method: 'GET', + }) + ); }); }); @@ -40,10 +44,12 @@ describe('getClickPositions', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/clicks/positions', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/positions', + method: 'GET', + }) + ); }); test('get getClickPositions with all parameters', async () => { @@ -54,10 +60,12 @@ describe('getClickPositions', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/clicks/positions', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/positions', + method: 'GET', + }) + ); }); }); @@ -67,10 +75,12 @@ describe('getClickThroughRate', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/clicks/clickThroughRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/clickThroughRate', + method: 'GET', + }) + ); }); test('get getClickThroughRate with all parameters', async () => { @@ -81,10 +91,12 @@ describe('getClickThroughRate', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/clicks/clickThroughRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/clicks/clickThroughRate', + method: 'GET', + }) + ); }); }); @@ -94,10 +106,12 @@ describe('getConversationRate', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/conversions/conversionRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/conversions/conversionRate', + method: 'GET', + }) + ); }); test('get getConversationRate with all parameters', async () => { @@ -108,10 +122,12 @@ describe('getConversationRate', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/conversions/conversionRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/conversions/conversionRate', + method: 'GET', + }) + ); }); }); @@ -121,10 +137,12 @@ describe('getNoClickRate', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches/noClickRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noClickRate', + method: 'GET', + }) + ); }); test('get getNoClickRate with all parameters', async () => { @@ -135,10 +153,12 @@ describe('getNoClickRate', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches/noClickRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noClickRate', + method: 'GET', + }) + ); }); }); @@ -148,10 +168,12 @@ describe('getNoResultsRate', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches/noResultRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noResultRate', + method: 'GET', + }) + ); }); test('get getNoResultsRate with all parameters', async () => { @@ -162,10 +184,12 @@ describe('getNoResultsRate', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches/noResultRate', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noResultRate', + method: 'GET', + }) + ); }); }); @@ -175,10 +199,12 @@ describe('getSearchesCount', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches/count', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/count', + method: 'GET', + }) + ); }); test('get getSearchesCount with all parameters', async () => { @@ -189,10 +215,12 @@ describe('getSearchesCount', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches/count', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/count', + method: 'GET', + }) + ); }); }); @@ -202,10 +230,12 @@ describe('getSearchesNoClicks', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches/noClicks', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noClicks', + method: 'GET', + }) + ); }); test('get getSearchesNoClicks with all parameters', async () => { @@ -218,10 +248,12 @@ describe('getSearchesNoClicks', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches/noClicks', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noClicks', + method: 'GET', + }) + ); }); }); @@ -231,10 +263,12 @@ describe('getSearchesNoResults', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches/noResults', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noResults', + method: 'GET', + }) + ); }); test('get getSearchesNoResults with all parameters', async () => { @@ -247,10 +281,12 @@ describe('getSearchesNoResults', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches/noResults', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches/noResults', + method: 'GET', + }) + ); }); }); @@ -260,10 +296,12 @@ describe('getStatus', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/status', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/status', + method: 'GET', + }) + ); }); }); @@ -273,10 +311,12 @@ describe('getTopCountries', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/countries', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/countries', + method: 'GET', + }) + ); }); test('get getTopCountries with all parameters', async () => { @@ -289,10 +329,12 @@ describe('getTopCountries', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/countries', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/countries', + method: 'GET', + }) + ); }); }); @@ -302,10 +344,12 @@ describe('getTopFilterAttributes', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/filters', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters', + method: 'GET', + }) + ); }); test('get getTopFilterAttributes with all parameters', async () => { @@ -318,10 +362,12 @@ describe('getTopFilterAttributes', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters', + method: 'GET', + }) + ); }); }); @@ -332,10 +378,12 @@ describe('getTopFilterAttributesForSearch', () => { search: 'mySearch', }); - expect(req).toMatchObject({ - path: '/2/filters?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopFilterAttributesForSearch with all parameters', async () => { @@ -349,10 +397,12 @@ describe('getTopFilterAttributesForSearch', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters?search=mySearch', + method: 'GET', + }) + ); }); }); @@ -363,10 +413,12 @@ describe('getTopFilterForAttribute', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute', + method: 'GET', + }) + ); }); test('get getTopFilterForAttribute with minimal parameters and multiple attributes', async () => { @@ -375,10 +427,12 @@ describe('getTopFilterForAttribute', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute1%2CmyAttribute2', + method: 'GET', + }) + ); }); test('get getTopFilterForAttribute with all parameters', async () => { @@ -392,10 +446,12 @@ describe('getTopFilterForAttribute', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute', + method: 'GET', + }) + ); }); test('get getTopFilterForAttribute with all parameters and multiple attributes', async () => { @@ -409,10 +465,12 @@ describe('getTopFilterForAttribute', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute1%2CmyAttribute2', + method: 'GET', + }) + ); }); }); @@ -424,10 +482,12 @@ describe('getTopFiltersForAttributesSearch', () => { search: 'mySearch', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopFiltersForAttributesSearch with minimal parameters and multiple attributes', async () => { @@ -437,10 +497,12 @@ describe('getTopFiltersForAttributesSearch', () => { search: 'mySearch', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopFiltersForAttributesSearch with all parameters', async () => { @@ -455,10 +517,12 @@ describe('getTopFiltersForAttributesSearch', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopFiltersForAttributesSearch with all parameters and multiple attributes', async () => { @@ -473,10 +537,12 @@ describe('getTopFiltersForAttributesSearch', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', + method: 'GET', + }) + ); }); }); @@ -486,10 +552,12 @@ describe('getTopFiltersNoResults', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/filters/noResults', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/noResults', + method: 'GET', + }) + ); }); test('get getTopFiltersNoResults with all parameters', async () => { @@ -502,10 +570,12 @@ describe('getTopFiltersNoResults', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/noResults', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/noResults', + method: 'GET', + }) + ); }); }); @@ -516,10 +586,12 @@ describe('getTopFiltersNoResultsForSearch', () => { search: 'mySearch', }); - expect(req).toMatchObject({ - path: '/2/filters/noResults?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/noResults?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopFiltersNoResultsForSearch with all parameters', async () => { @@ -533,10 +605,12 @@ describe('getTopFiltersNoResultsForSearch', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/filters/noResults?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/filters/noResults?search=mySearch', + method: 'GET', + }) + ); }); }); @@ -546,10 +620,12 @@ describe('getTopHits', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/hits', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/hits', + method: 'GET', + }) + ); }); test('get getTopHits with all parameters', async () => { @@ -563,10 +639,12 @@ describe('getTopHits', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/hits', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/hits', + method: 'GET', + }) + ); }); }); @@ -577,10 +655,12 @@ describe('getTopHitsForSearch', () => { search: 'mySearch', }); - expect(req).toMatchObject({ - path: '/2/hits?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/hits?search=mySearch', + method: 'GET', + }) + ); }); test('get getTopHitsForSearch with all parameters', async () => { @@ -595,10 +675,12 @@ describe('getTopHitsForSearch', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/hits?search=mySearch', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/hits?search=mySearch', + method: 'GET', + }) + ); }); }); @@ -608,10 +690,12 @@ describe('getTopSearches', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/searches', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches', + method: 'GET', + }) + ); }); test('get getTopSearches with all parameters', async () => { @@ -627,10 +711,12 @@ describe('getTopSearches', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/searches', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/searches', + method: 'GET', + }) + ); }); }); @@ -640,10 +726,12 @@ describe('getUsersCount', () => { index: 'index', }); - expect(req).toMatchObject({ - path: '/2/users/count', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/users/count', + method: 'GET', + }) + ); }); test('get getUsersCount with all parameters', async () => { @@ -654,9 +742,13 @@ describe('getUsersCount', () => { tags: 'tag', }); - expect(req).toMatchObject({ - path: '/2/users/count', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/2/users/count', + method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + }) + ); }); }); diff --git a/tests/output/javascript/insights.test.ts b/tests/output/javascript/insights.test.ts index c0f228c75f..399adea745 100644 --- a/tests/output/javascript/insights.test.ts +++ b/tests/output/javascript/insights.test.ts @@ -43,40 +43,42 @@ describe('pushEvents', () => { }, }); - expect(req).toMatchObject({ - path: '/1/events', - method: 'POST', - data: { - events: [ - { - eventType: 'click', - eventName: 'Product Clicked', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - queryID: '43b15df305339e827f0ac0bdc5ebcaa7', - positions: [7, 6], - }, - { - eventType: 'view', - eventName: 'Product Detail Page Viewed', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - }, - { - eventType: 'conversion', - eventName: 'Product Purchased', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - queryID: '43b15df305339e827f0ac0bdc5ebcaa7', - }, - ], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/events', + method: 'POST', + data: { + events: [ + { + eventType: 'click', + eventName: 'Product Clicked', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + queryID: '43b15df305339e827f0ac0bdc5ebcaa7', + positions: [7, 6], + }, + { + eventType: 'view', + eventName: 'Product Detail Page Viewed', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + }, + { + eventType: 'conversion', + eventName: 'Product Purchased', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + queryID: '43b15df305339e827f0ac0bdc5ebcaa7', + }, + ], + }, + }) + ); }); }); diff --git a/tests/output/javascript/personalization.test.ts b/tests/output/javascript/personalization.test.ts index 7ad9662f9a..b4005be18e 100644 --- a/tests/output/javascript/personalization.test.ts +++ b/tests/output/javascript/personalization.test.ts @@ -16,10 +16,12 @@ describe('deleteUserProfile', () => { userToken: 'UserToken', }); - expect(req).toMatchObject({ - path: '/1/profiles/UserToken', - method: 'DELETE', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/profiles/UserToken', + method: 'DELETE', + }) + ); }); }); @@ -27,10 +29,12 @@ describe('getPersonalizationStrategy', () => { test('get getPersonalizationStrategy', async () => { const req = await client.getPersonalizationStrategy(); - expect(req).toMatchObject({ - path: '/1/strategies/personalization', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/strategies/personalization', + method: 'GET', + }) + ); }); }); @@ -40,10 +44,12 @@ describe('getUserTokenProfile', () => { userToken: 'UserToken', }); - expect(req).toMatchObject({ - path: '/1/profiles/personalization/UserToken', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/profiles/personalization/UserToken', + method: 'GET', + }) + ); }); }); @@ -57,14 +63,18 @@ describe('setPersonalizationStrategy', () => { }, }); - expect(req).toMatchObject({ - path: '/1/strategies/personalization', - method: 'POST', - data: { - eventScoring: [{ score: 42, eventName: 'Algolia', eventType: 'Event' }], - facetScoring: [{ score: 42, facetName: 'Event' }], - personalizationImpact: 42, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/strategies/personalization', + method: 'POST', + data: { + eventScoring: [ + { score: 42, eventName: 'Algolia', eventType: 'Event' }, + ], + facetScoring: [{ score: 42, facetName: 'Event' }], + personalizationImpact: 42, + }, + }) + ); }); }); diff --git a/tests/output/javascript/recommend.test.ts b/tests/output/javascript/recommend.test.ts index fb62ab4e39..7d6f2fbc69 100644 --- a/tests/output/javascript/recommend.test.ts +++ b/tests/output/javascript/recommend.test.ts @@ -22,20 +22,22 @@ describe('getRecommendations', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName', - objectID: 'objectID', - model: 'related-products', - threshold: 42, - }, - ], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/*/recommendations', + method: 'POST', + data: { + requests: [ + { + indexName: 'indexName', + objectID: 'objectID', + model: 'related-products', + threshold: 42, + }, + ], + }, + }) + ); }); test('get recommendations with all parameters', async () => { @@ -57,25 +59,27 @@ describe('getRecommendations', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName', - objectID: 'objectID', - model: 'related-products', - threshold: 42, - queryParameters: { query: 'myQuery', facetFilters: ['query'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback'], + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/*/recommendations', + method: 'POST', + data: { + requests: [ + { + indexName: 'indexName', + objectID: 'objectID', + model: 'related-products', + threshold: 42, + queryParameters: { query: 'myQuery', facetFilters: ['query'] }, + fallbackParameters: { + query: 'myQuery', + facetFilters: ['fallback'], + }, }, - }, - ], - }, - }); + ], + }, + }) + ); }); test('get multiple recommendations with minimal parameters', async () => { @@ -98,26 +102,28 @@ describe('getRecommendations', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'related-products', - threshold: 21, - }, - { - indexName: 'indexName2', - objectID: 'objectID2', - model: 'related-products', - threshold: 21, - }, - ], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/*/recommendations', + method: 'POST', + data: { + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'related-products', + threshold: 21, + }, + { + indexName: 'indexName2', + objectID: 'objectID2', + model: 'related-products', + threshold: 21, + }, + ], + }, + }) + ); }); test('get multiple recommendations with all parameters', async () => { @@ -150,36 +156,38 @@ describe('getRecommendations', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'related-products', - threshold: 21, - queryParameters: { query: 'myQuery', facetFilters: ['query1'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback1'], + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/*/recommendations', + method: 'POST', + data: { + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'related-products', + threshold: 21, + queryParameters: { query: 'myQuery', facetFilters: ['query1'] }, + fallbackParameters: { + query: 'myQuery', + facetFilters: ['fallback1'], + }, }, - }, - { - indexName: 'indexName2', - objectID: 'objectID2', - model: 'related-products', - threshold: 21, - queryParameters: { query: 'myQuery', facetFilters: ['query2'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback2'], + { + indexName: 'indexName2', + objectID: 'objectID2', + model: 'related-products', + threshold: 21, + queryParameters: { query: 'myQuery', facetFilters: ['query2'] }, + fallbackParameters: { + query: 'myQuery', + facetFilters: ['fallback2'], + }, }, - }, - ], - }, - }); + ], + }, + }) + ); }); test('get frequently bought together recommendations', async () => { @@ -196,19 +204,21 @@ describe('getRecommendations', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'bought-together', - threshold: 42, - }, - ], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/*/recommendations', + method: 'POST', + data: { + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'bought-together', + threshold: 42, + }, + ], + }, + }) + ); }); }); diff --git a/tests/output/javascript/search.test.ts b/tests/output/javascript/search.test.ts index 32455a2f0a..6eb094c137 100644 --- a/tests/output/javascript/search.test.ts +++ b/tests/output/javascript/search.test.ts @@ -17,17 +17,19 @@ describe('addApiKey', () => { }, }); - expect(req).toMatchObject({ - path: '/1/keys', - method: 'POST', - data: { - acl: ['search', 'addObject'], - description: 'my new api key', - validity: 300, - maxQueriesPerIPPerHour: 100, - maxHitsPerQuery: 20, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys', + method: 'POST', + data: { + acl: ['search', 'addObject'], + description: 'my new api key', + validity: 300, + maxQueriesPerIPPerHour: 100, + maxHitsPerQuery: 20, + }, + }) + ); }); }); @@ -43,16 +45,18 @@ describe('batchDictionaryEntries', () => { }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/compounds/batch', - method: 'POST', - data: { - requests: [ - { action: 'addEntry', body: { objectID: '1', language: 'en' } }, - { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, - ], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/compounds/batch', + method: 'POST', + data: { + requests: [ + { action: 'addEntry', body: { objectID: '1', language: 'en' } }, + { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, + ], + }, + }) + ); }); test('get batchDictionaryEntries results with all parameters', async () => { @@ -87,37 +91,39 @@ describe('batchDictionaryEntries', () => { }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/compounds/batch', - method: 'POST', - data: { - clearExistingDictionaryEntries: false, - requests: [ - { - action: 'addEntry', - body: { - objectID: '1', - language: 'en', - word: 'yo', - words: ['yo', 'algolia'], - decomposition: ['yo', 'algolia'], - state: 'enabled', + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/compounds/batch', + method: 'POST', + data: { + clearExistingDictionaryEntries: false, + requests: [ + { + action: 'addEntry', + body: { + objectID: '1', + language: 'en', + word: 'yo', + words: ['yo', 'algolia'], + decomposition: ['yo', 'algolia'], + state: 'enabled', + }, }, - }, - { - action: 'deleteEntry', - body: { - objectID: '2', - language: 'fr', - word: 'salut', - words: ['salut', 'algolia'], - decomposition: ['salut', 'algolia'], - state: 'enabled', + { + action: 'deleteEntry', + body: { + objectID: '2', + language: 'fr', + word: 'salut', + words: ['salut', 'algolia'], + decomposition: ['salut', 'algolia'], + state: 'enabled', + }, }, - }, - ], - }, - }); + ], + }, + }) + ); }); }); @@ -141,22 +147,24 @@ describe('batchRules', () => { clearExistingRules: true, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/batch', - method: 'POST', - data: [ - { - objectID: 'a-rule-id', - conditions: [{ pattern: 'smartphone', anchoring: 'contains' }], - consequence: { params: { filters: 'category:smartphone' } }, - }, - { - objectID: 'a-second-rule-id', - conditions: [{ pattern: 'apple', anchoring: 'contains' }], - consequence: { params: { filters: 'brand:apple' } }, - }, - ], - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/batch', + method: 'POST', + data: [ + { + objectID: 'a-rule-id', + conditions: [{ pattern: 'smartphone', anchoring: 'contains' }], + consequence: { params: { filters: 'category:smartphone' } }, + }, + { + objectID: 'a-second-rule-id', + conditions: [{ pattern: 'apple', anchoring: 'contains' }], + consequence: { params: { filters: 'brand:apple' } }, + }, + ], + }) + ); }); }); @@ -166,10 +174,12 @@ describe('browse', () => { indexName: 'indexName', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/browse', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/browse', + method: 'POST', + }) + ); }); test('get browse results with all parameters', async () => { @@ -181,11 +191,13 @@ describe('browse', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/browse', - method: 'POST', - data: { params: "query=foo&facetFilters=['bar']", cursor: 'cts' }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/browse', + method: 'POST', + data: { params: "query=foo&facetFilters=['bar']", cursor: 'cts' }, + }) + ); }); }); @@ -195,10 +207,12 @@ describe('clearAllSynonyms', () => { indexName: 'indexName', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/clear', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/clear', + method: 'POST', + }) + ); }); }); @@ -208,10 +222,12 @@ describe('clearRules', () => { indexName: 'indexName', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/clear', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/clear', + method: 'POST', + }) + ); }); }); @@ -221,10 +237,12 @@ describe('deleteApiKey', () => { key: 'myTestApiKey', }); - expect(req).toMatchObject({ - path: '/1/keys/myTestApiKey', - method: 'DELETE', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys/myTestApiKey', + method: 'DELETE', + }) + ); }); }); @@ -235,10 +253,12 @@ describe('deleteRule', () => { objectID: 'id1', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/id1', - method: 'DELETE', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/id1', + method: 'DELETE', + }) + ); }); }); @@ -249,10 +269,12 @@ describe('deleteSynonym', () => { objectID: 'id1', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'DELETE', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/id1', + method: 'DELETE', + }) + ); }); }); @@ -262,10 +284,12 @@ describe('getApiKey', () => { key: 'myTestApiKey', }); - expect(req).toMatchObject({ - path: '/1/keys/myTestApiKey', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys/myTestApiKey', + method: 'GET', + }) + ); }); }); @@ -273,10 +297,12 @@ describe('getDictionaryLanguages', () => { test('get getDictionaryLanguages', async () => { const req = await client.getDictionaryLanguages(); - expect(req).toMatchObject({ - path: '/1/dictionaries/*/languages', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/*/languages', + method: 'GET', + }) + ); }); }); @@ -284,10 +310,12 @@ describe('getDictionarySettings', () => { test('get getDictionarySettings results', async () => { const req = await client.getDictionarySettings(); - expect(req).toMatchObject({ - path: '/1/dictionaries/*/settings', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/*/settings', + method: 'GET', + }) + ); }); }); @@ -298,10 +326,12 @@ describe('getRule', () => { objectID: 'id1', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/id1', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/id1', + method: 'GET', + }) + ); }); }); @@ -312,10 +342,12 @@ describe('getSynonym', () => { objectID: 'id1', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/id1', + method: 'GET', + }) + ); }); }); @@ -323,10 +355,12 @@ describe('listApiKeys', () => { test('listApiKeys', async () => { const req = await client.listApiKeys(); - expect(req).toMatchObject({ - path: '/1/keys', - method: 'GET', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys', + method: 'GET', + }) + ); }); }); @@ -336,10 +370,12 @@ describe('restoreApiKey', () => { key: 'myApiKey', }); - expect(req).toMatchObject({ - path: '/1/keys/myApiKey/restore', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys/myApiKey/restore', + method: 'POST', + }) + ); }); }); @@ -356,15 +392,17 @@ describe('saveRule', () => { forwardToReplicas: true, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/id1', - method: 'PUT', - data: { - objectID: 'id1', - conditions: [{ pattern: 'apple', anchoring: 'contains' }], - consequence: { params: { filters: 'brand:apple' } }, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/id1', + method: 'PUT', + data: { + objectID: 'id1', + conditions: [{ pattern: 'apple', anchoring: 'contains' }], + consequence: { params: { filters: 'brand:apple' } }, + }, + }) + ); }); }); @@ -381,15 +419,17 @@ describe('saveSynonym', () => { forwardToReplicas: true, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'PUT', - data: { - objectID: 'id1', - type: 'synonym', - synonyms: ['car', 'vehicule', 'auto'], - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/id1', + method: 'PUT', + data: { + objectID: 'id1', + type: 'synonym', + synonyms: ['car', 'vehicule', 'auto'], + }, + }) + ); }); }); @@ -414,23 +454,25 @@ describe('saveSynonyms', () => { replaceExistingSynonyms: false, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/batch', - method: 'POST', - data: [ - { - objectID: 'id1', - type: 'synonym', - synonyms: ['car', 'vehicule', 'auto'], - }, - { - objectID: 'id2', - type: 'onewaysynonym', - input: 'iphone', - synonyms: ['ephone', 'aphone', 'yphone'], - }, - ], - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/batch', + method: 'POST', + data: [ + { + objectID: 'id1', + type: 'synonym', + synonyms: ['car', 'vehicule', 'auto'], + }, + { + objectID: 'id2', + type: 'onewaysynonym', + input: 'iphone', + synonyms: ['ephone', 'aphone', 'yphone'], + }, + ], + }) + ); }); }); @@ -441,11 +483,13 @@ describe('search', () => { searchParams: { query: 'myQuery' }, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/query', - method: 'POST', - data: { query: 'myQuery' }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/query', + method: 'POST', + data: { query: 'myQuery' }, + }) + ); }); }); @@ -456,11 +500,13 @@ describe('searchDictionaryEntries', () => { searchDictionaryEntries: { query: 'foo' }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/compounds/search', - method: 'POST', - data: { query: 'foo' }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/compounds/search', + method: 'POST', + data: { query: 'foo' }, + }) + ); }); test('get searchDictionaryEntries results with all parameters', async () => { @@ -474,11 +520,13 @@ describe('searchDictionaryEntries', () => { }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/compounds/search', - method: 'POST', - data: { query: 'foo', page: 4, hitsPerPage: 2, language: 'fr' }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/compounds/search', + method: 'POST', + data: { query: 'foo', page: 4, hitsPerPage: 2, language: 'fr' }, + }) + ); }); }); @@ -489,10 +537,12 @@ describe('searchForFacetValues', () => { facetName: 'facetName', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/facets/facetName/query', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/facets/facetName/query', + method: 'POST', + }) + ); }); test('get searchForFacetValues results with all parameters', async () => { @@ -506,15 +556,17 @@ describe('searchForFacetValues', () => { }, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/facets/facetName/query', - method: 'POST', - data: { - params: "query=foo&facetFilters=['bar']", - facetQuery: 'foo', - maxFacetHits: 42, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/facets/facetName/query', + method: 'POST', + data: { + params: "query=foo&facetFilters=['bar']", + facetQuery: 'foo', + maxFacetHits: 42, + }, + }) + ); }); }); @@ -525,11 +577,13 @@ describe('searchRules', () => { searchRulesParams: { query: 'something' }, }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/rules/search', - method: 'POST', - data: { query: 'something' }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/rules/search', + method: 'POST', + data: { query: 'something' }, + }) + ); }); }); @@ -541,10 +595,12 @@ describe('searchSynonyms', () => { type: 'onewaysynonym', }); - expect(req).toMatchObject({ - path: '/1/indexes/indexName/synonyms/search', - method: 'POST', - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/indexes/indexName/synonyms/search', + method: 'POST', + }) + ); }); }); @@ -556,13 +612,17 @@ describe('setDictionarySettings', () => { }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/*/settings', - method: 'PUT', - data: { - disableStandardEntries: { plurals: { fr: false, en: false, ru: true } }, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/*/settings', + method: 'PUT', + data: { + disableStandardEntries: { + plurals: { fr: false, en: false, ru: true }, + }, + }, + }) + ); }); test('get setDictionarySettings results with all parameters', async () => { @@ -576,17 +636,19 @@ describe('setDictionarySettings', () => { }, }); - expect(req).toMatchObject({ - path: '/1/dictionaries/*/settings', - method: 'PUT', - data: { - disableStandardEntries: { - plurals: { fr: false, en: false, ru: true }, - stopwords: { fr: false }, - compounds: { ru: true }, + expect(req).toEqual( + expect.objectContaining({ + path: '/1/dictionaries/*/settings', + method: 'PUT', + data: { + disableStandardEntries: { + plurals: { fr: false, en: false, ru: true }, + stopwords: { fr: false }, + compounds: { ru: true }, + }, }, - }, - }); + }) + ); }); }); @@ -602,15 +664,17 @@ describe('updateApiKey', () => { }, }); - expect(req).toMatchObject({ - path: '/1/keys/myApiKey', - method: 'PUT', - data: { - acl: ['search', 'addObject'], - validity: 300, - maxQueriesPerIPPerHour: 100, - maxHitsPerQuery: 20, - }, - }); + expect(req).toEqual( + expect.objectContaining({ + path: '/1/keys/myApiKey', + method: 'PUT', + data: { + acl: ['search', 'addObject'], + validity: 300, + maxQueriesPerIPPerHour: 100, + maxHitsPerQuery: 20, + }, + }) + ); }); }); From aad0c093ff28bfd44faa8ef6d627c34c461a9843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 7 Jan 2022 14:21:39 +0100 Subject: [PATCH 4/9] tests: add `searchParams` values --- .../analytics/getAverageClickPosition.json | 3 +- .../clients/analytics/getClickPositions.json | 3 +- .../analytics/getClickThroughRate.json | 3 +- .../analytics/getConversationRate.json | 3 +- .../CTS/clients/analytics/getNoClickRate.json | 3 +- .../clients/analytics/getNoResultsRate.json | 3 +- .../clients/analytics/getSearchesCount.json | 3 +- .../analytics/getSearchesNoClicks.json | 3 +- .../analytics/getSearchesNoResults.json | 3 +- .../clients/analytics/getTopCountries.json | 3 +- .../analytics/getTopFilterAttributes.json | 3 +- .../getTopFilterAttributesForSearch.json | 3 +- .../analytics/getTopFilterForAttribute.json | 6 ++- .../getTopFiltersForAttributesSearch.json | 6 ++- .../analytics/getTopFiltersNoResults.json | 3 +- .../getTopFiltersNoResultsForSearch.json | 3 +- tests/CTS/clients/analytics/getTopHits.json | 3 +- .../analytics/getTopHitsForSearch.json | 3 +- .../CTS/clients/analytics/getTopSearches.json | 3 +- .../CTS/clients/analytics/getUsersCount.json | 3 +- tests/output/javascript/analytics.test.ts | 42 +++++++++++++++++++ 21 files changed, 86 insertions(+), 22 deletions(-) diff --git a/tests/CTS/clients/analytics/getAverageClickPosition.json b/tests/CTS/clients/analytics/getAverageClickPosition.json index 579f906124..914c02dea1 100644 --- a/tests/CTS/clients/analytics/getAverageClickPosition.json +++ b/tests/CTS/clients/analytics/getAverageClickPosition.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/clicks/averageClickPosition", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getClickPositions.json b/tests/CTS/clients/analytics/getClickPositions.json index 2f1827446f..a3b8f7abb3 100644 --- a/tests/CTS/clients/analytics/getClickPositions.json +++ b/tests/CTS/clients/analytics/getClickPositions.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/clicks/positions", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getClickThroughRate.json b/tests/CTS/clients/analytics/getClickThroughRate.json index c065097586..9cb9ba1606 100644 --- a/tests/CTS/clients/analytics/getClickThroughRate.json +++ b/tests/CTS/clients/analytics/getClickThroughRate.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/clicks/clickThroughRate", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getConversationRate.json b/tests/CTS/clients/analytics/getConversationRate.json index a829f033f1..bf4fde9586 100644 --- a/tests/CTS/clients/analytics/getConversationRate.json +++ b/tests/CTS/clients/analytics/getConversationRate.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/conversions/conversionRate", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getNoClickRate.json b/tests/CTS/clients/analytics/getNoClickRate.json index 6f7f63d80e..45e6d191e8 100644 --- a/tests/CTS/clients/analytics/getNoClickRate.json +++ b/tests/CTS/clients/analytics/getNoClickRate.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/searches/noClickRate", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getNoResultsRate.json b/tests/CTS/clients/analytics/getNoResultsRate.json index e53770cea3..2cd5bb3e8b 100644 --- a/tests/CTS/clients/analytics/getNoResultsRate.json +++ b/tests/CTS/clients/analytics/getNoResultsRate.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/searches/noResultRate", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getSearchesCount.json b/tests/CTS/clients/analytics/getSearchesCount.json index 4c6a1d0aad..6ce0ddab96 100644 --- a/tests/CTS/clients/analytics/getSearchesCount.json +++ b/tests/CTS/clients/analytics/getSearchesCount.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/searches/count", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getSearchesNoClicks.json b/tests/CTS/clients/analytics/getSearchesNoClicks.json index a46387382a..c144519b61 100644 --- a/tests/CTS/clients/analytics/getSearchesNoClicks.json +++ b/tests/CTS/clients/analytics/getSearchesNoClicks.json @@ -23,7 +23,8 @@ }, "request": { "path": "/2/searches/noClicks", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getSearchesNoResults.json b/tests/CTS/clients/analytics/getSearchesNoResults.json index 0fe953f33b..e244b61656 100644 --- a/tests/CTS/clients/analytics/getSearchesNoResults.json +++ b/tests/CTS/clients/analytics/getSearchesNoResults.json @@ -23,7 +23,8 @@ }, "request": { "path": "/2/searches/noResults", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopCountries.json b/tests/CTS/clients/analytics/getTopCountries.json index d92f70fe37..5c2a77705d 100644 --- a/tests/CTS/clients/analytics/getTopCountries.json +++ b/tests/CTS/clients/analytics/getTopCountries.json @@ -23,7 +23,8 @@ }, "request": { "path": "/2/countries", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterAttributes.json b/tests/CTS/clients/analytics/getTopFilterAttributes.json index 2ca6cd17aa..2652ade50f 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributes.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributes.json @@ -23,7 +23,8 @@ }, "request": { "path": "/2/filters", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json b/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json index 7f79452fdd..53e3ad7eb6 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json @@ -25,7 +25,8 @@ }, "request": { "path": "/2/filters?search=mySearch", - "method": "GET" + "method": "GET", + "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterForAttribute.json b/tests/CTS/clients/analytics/getTopFilterForAttribute.json index 2dddc6a1e9..1879ed4d4a 100644 --- a/tests/CTS/clients/analytics/getTopFilterForAttribute.json +++ b/tests/CTS/clients/analytics/getTopFilterForAttribute.json @@ -37,7 +37,8 @@ }, "request": { "path": "/2/filters/myAttribute", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } }, { @@ -54,7 +55,8 @@ }, "request": { "path": "/2/filters/myAttribute1%2CmyAttribute2", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json b/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json index bef1251316..8ce7a06fa1 100644 --- a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json +++ b/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json @@ -40,7 +40,8 @@ }, "request": { "path": "/2/filters/myAttribute?search=mySearch", - "method": "GET" + "method": "GET", + "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } }, { @@ -58,7 +59,8 @@ }, "request": { "path": "/2/filters/myAttribute1%2CmyAttribute2?search=mySearch", - "method": "GET" + "method": "GET", + "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResults.json b/tests/CTS/clients/analytics/getTopFiltersNoResults.json index 23c47ed2d9..41a3011188 100644 --- a/tests/CTS/clients/analytics/getTopFiltersNoResults.json +++ b/tests/CTS/clients/analytics/getTopFiltersNoResults.json @@ -23,7 +23,8 @@ }, "request": { "path": "/2/filters/noResults", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json b/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json index 09b3f0ec97..1f173d1ea8 100644 --- a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json +++ b/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json @@ -25,7 +25,8 @@ }, "request": { "path": "/2/filters/noResults?search=mySearch", - "method": "GET" + "method": "GET", + "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopHits.json b/tests/CTS/clients/analytics/getTopHits.json index 49511ac82c..c364ce7e54 100644 --- a/tests/CTS/clients/analytics/getTopHits.json +++ b/tests/CTS/clients/analytics/getTopHits.json @@ -24,7 +24,8 @@ }, "request": { "path": "/2/hits", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopHitsForSearch.json b/tests/CTS/clients/analytics/getTopHitsForSearch.json index 538ea778fa..7872820a2b 100644 --- a/tests/CTS/clients/analytics/getTopHitsForSearch.json +++ b/tests/CTS/clients/analytics/getTopHitsForSearch.json @@ -26,7 +26,8 @@ }, "request": { "path": "/2/hits?search=mySearch", - "method": "GET" + "method": "GET", + "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getTopSearches.json b/tests/CTS/clients/analytics/getTopSearches.json index 37f56e735c..ba8e3185d5 100644 --- a/tests/CTS/clients/analytics/getTopSearches.json +++ b/tests/CTS/clients/analytics/getTopSearches.json @@ -26,7 +26,8 @@ }, "request": { "path": "/2/searches", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&orderBy=searchCount&direction=asc&limit=21&offset=42&tags=tag" } } ] diff --git a/tests/CTS/clients/analytics/getUsersCount.json b/tests/CTS/clients/analytics/getUsersCount.json index 751edd81e5..626ec03609 100644 --- a/tests/CTS/clients/analytics/getUsersCount.json +++ b/tests/CTS/clients/analytics/getUsersCount.json @@ -21,7 +21,8 @@ }, "request": { "path": "/2/users/count", - "method": "GET" + "method": "GET", + "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" } } ] diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 83b1828011..1dc742a5d1 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -33,6 +33,8 @@ describe('getAverageClickPosition', () => { expect.objectContaining({ path: '/2/clicks/averageClickPosition', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -64,6 +66,8 @@ describe('getClickPositions', () => { expect.objectContaining({ path: '/2/clicks/positions', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -95,6 +99,8 @@ describe('getClickThroughRate', () => { expect.objectContaining({ path: '/2/clicks/clickThroughRate', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -126,6 +132,8 @@ describe('getConversationRate', () => { expect.objectContaining({ path: '/2/conversions/conversionRate', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -157,6 +165,8 @@ describe('getNoClickRate', () => { expect.objectContaining({ path: '/2/searches/noClickRate', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -188,6 +198,8 @@ describe('getNoResultsRate', () => { expect.objectContaining({ path: '/2/searches/noResultRate', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -219,6 +231,8 @@ describe('getSearchesCount', () => { expect.objectContaining({ path: '/2/searches/count', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', }) ); }); @@ -252,6 +266,8 @@ describe('getSearchesNoClicks', () => { expect.objectContaining({ path: '/2/searches/noClicks', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -285,6 +301,8 @@ describe('getSearchesNoResults', () => { expect.objectContaining({ path: '/2/searches/noResults', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -333,6 +351,8 @@ describe('getTopCountries', () => { expect.objectContaining({ path: '/2/countries', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -366,6 +386,8 @@ describe('getTopFilterAttributes', () => { expect.objectContaining({ path: '/2/filters', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -401,6 +423,8 @@ describe('getTopFilterAttributesForSearch', () => { expect.objectContaining({ path: '/2/filters?search=mySearch', method: 'GET', + searchParams: + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -450,6 +474,8 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -469,6 +495,8 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -521,6 +549,8 @@ describe('getTopFiltersForAttributesSearch', () => { expect.objectContaining({ path: '/2/filters/myAttribute?search=mySearch', method: 'GET', + searchParams: + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -541,6 +571,8 @@ describe('getTopFiltersForAttributesSearch', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', method: 'GET', + searchParams: + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -574,6 +606,8 @@ describe('getTopFiltersNoResults', () => { expect.objectContaining({ path: '/2/filters/noResults', method: 'GET', + searchParams: + '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -609,6 +643,8 @@ describe('getTopFiltersNoResultsForSearch', () => { expect.objectContaining({ path: '/2/filters/noResults?search=mySearch', method: 'GET', + searchParams: + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -643,6 +679,8 @@ describe('getTopHits', () => { expect.objectContaining({ path: '/2/hits', method: 'GET', + searchParams: + '?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -679,6 +717,8 @@ describe('getTopHitsForSearch', () => { expect.objectContaining({ path: '/2/hits?search=mySearch', method: 'GET', + searchParams: + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', }) ); }); @@ -715,6 +755,8 @@ describe('getTopSearches', () => { expect.objectContaining({ path: '/2/searches', method: 'GET', + searchParams: + '?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&orderBy=searchCount&direction=asc&limit=21&offset=42&tags=tag', }) ); }); From 6cc05ef4396dfde9c217c13a770a717f07f812a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 7 Jan 2022 15:57:29 +0100 Subject: [PATCH 5/9] use `searchParams` object --- .../utils/requester/EchoRequester.ts | 19 +- .../utils/requester/EchoRequester.ts | 19 +- .../utils/requester/EchoRequester.ts | 19 +- .../utils/requester/EchoRequester.ts | 19 +- .../utils/requester/EchoRequester.ts | 19 +- .../utils/requester/EchoRequester.ts | 19 +- specs/analytics/paths/common/parameters.yml | 18 +- .../getTopFilterAttributesForSearch.yml | 2 +- .../getTopFiltersForAttributesSearch.yml | 2 +- .../getTopFiltersNoResultsForSearch.yml | 2 +- .../paths/search/getTopHitsForSearch.yml | 2 +- .../analytics/getAverageClickPosition.json | 7 +- .../clients/analytics/getClickPositions.json | 7 +- .../analytics/getClickThroughRate.json | 7 +- .../analytics/getConversationRate.json | 7 +- .../CTS/clients/analytics/getNoClickRate.json | 7 +- .../clients/analytics/getNoResultsRate.json | 7 +- .../clients/analytics/getSearchesCount.json | 7 +- .../analytics/getSearchesNoClicks.json | 9 +- .../analytics/getSearchesNoResults.json | 9 +- .../clients/analytics/getTopCountries.json | 9 +- .../analytics/getTopFilterAttributes.json | 9 +- .../getTopFilterAttributesForSearch.json | 10 +- .../analytics/getTopFilterForAttribute.json | 20 +- .../getTopFiltersForAttributesSearch.json | 10 +- .../analytics/getTopFiltersNoResults.json | 9 +- .../getTopFiltersNoResultsForSearch.json | 10 +- tests/CTS/clients/analytics/getTopHits.json | 10 +- .../analytics/getTopHitsForSearch.json | 11 +- .../CTS/clients/analytics/getTopSearches.json | 12 +- .../CTS/clients/analytics/getUsersCount.json | 7 +- tests/CTS/templates/javascript.mustache | 4 +- tests/generateCTS.ts | 1 + tests/output/javascript/analytics.test.ts | 298 ++++++++++++------ 34 files changed, 437 insertions(+), 190 deletions(-) diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts index 1eec310f8c..fd48553d4a 100644 --- a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts @@ -4,28 +4,24 @@ import { Requester } from './Requester'; type AdditionalContent = { headers: Record; - searchParams: string | undefined; - userAgent: string | undefined; connectTimeout: number; responseTimeout: number; + userAgent: string | undefined; + searchParams: Record; }; -function searchParamsWithoutUA(params: URLSearchParams): string | undefined { - let searchParams = '?'; +function searchParamsWithoutUA(params: URLSearchParams): Record { + const searchParams = {}; for (const [k, v] of params) { if (k === 'x-algolia-agent') { continue; } - searchParams += encodeURI(`${k}=${v}&`); - } - - if (searchParams === '?') { - return undefined; + searchParams[k] = v; } - return searchParams.replace(/&$/, ''); + return searchParams; } export class EchoRequester extends Requester { @@ -39,12 +35,13 @@ export class EchoRequester extends Requester { ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; + const searchParams = searchParamsWithoutUA(urlSearchParams); const additionalContent: AdditionalContent = { headers, connectTimeout, responseTimeout, userAgent: userAgent ? encodeURI(userAgent) : undefined, - searchParams: searchParamsWithoutUA(urlSearchParams), + searchParams, }; return Promise.resolve({ diff --git a/specs/analytics/paths/common/parameters.yml b/specs/analytics/paths/common/parameters.yml index 6fb3d21cfd..12a471cf0b 100644 --- a/specs/analytics/paths/common/parameters.yml +++ b/specs/analytics/paths/common/parameters.yml @@ -7,6 +7,14 @@ Attribute: schema: type: string +Search: + in: path + name: search + description: The query term. Must match the exact user input. + required: true + schema: + type: string + # query OrderBy: in: query @@ -42,15 +50,7 @@ Limit: type: integer default: 10 -Search: - in: path - name: search - description: The query term. Must match the exact user input. - required: true - schema: - type: string - -SearchInPath: +SearchInQuery: in: path name: search description: The query term. Must match the exact user input. diff --git a/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml b/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml index 71073a7f27..05efbe595a 100644 --- a/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml +++ b/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml @@ -6,7 +6,7 @@ get: summary: Returns top filter attributes for a given search. parameters: - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInPath' + - $ref: '../common/parameters.yml#/SearchInQuery' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml b/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml index 26f7cc00f6..b0046dab81 100644 --- a/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml +++ b/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml @@ -12,7 +12,7 @@ get: schema: type: string - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInPath' + - $ref: '../common/parameters.yml#/SearchInQuery' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml b/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml index e6f7e768f5..af9d3274ad 100644 --- a/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml +++ b/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml @@ -6,7 +6,7 @@ get: summary: Returns top filters for the given no result search. parameters: - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInPath' + - $ref: '../common/parameters.yml#/SearchInQuery' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopHitsForSearch.yml b/specs/analytics/paths/search/getTopHitsForSearch.yml index a96d68a62e..527fcc20c5 100644 --- a/specs/analytics/paths/search/getTopHitsForSearch.yml +++ b/specs/analytics/paths/search/getTopHitsForSearch.yml @@ -6,7 +6,7 @@ get: summary: Returns top hits for the given search. parameters: - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInPath' + - $ref: '../common/parameters.yml#/SearchInQuery' - $ref: '../common/parameters.yml#/ClickAnalytics' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' diff --git a/tests/CTS/clients/analytics/getAverageClickPosition.json b/tests/CTS/clients/analytics/getAverageClickPosition.json index 914c02dea1..8fc2f6b953 100644 --- a/tests/CTS/clients/analytics/getAverageClickPosition.json +++ b/tests/CTS/clients/analytics/getAverageClickPosition.json @@ -22,7 +22,12 @@ "request": { "path": "/2/clicks/averageClickPosition", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getClickPositions.json b/tests/CTS/clients/analytics/getClickPositions.json index a3b8f7abb3..56ffeed4cf 100644 --- a/tests/CTS/clients/analytics/getClickPositions.json +++ b/tests/CTS/clients/analytics/getClickPositions.json @@ -22,7 +22,12 @@ "request": { "path": "/2/clicks/positions", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getClickThroughRate.json b/tests/CTS/clients/analytics/getClickThroughRate.json index 9cb9ba1606..9c576cf1ba 100644 --- a/tests/CTS/clients/analytics/getClickThroughRate.json +++ b/tests/CTS/clients/analytics/getClickThroughRate.json @@ -22,7 +22,12 @@ "request": { "path": "/2/clicks/clickThroughRate", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getConversationRate.json b/tests/CTS/clients/analytics/getConversationRate.json index bf4fde9586..eac532a3a1 100644 --- a/tests/CTS/clients/analytics/getConversationRate.json +++ b/tests/CTS/clients/analytics/getConversationRate.json @@ -22,7 +22,12 @@ "request": { "path": "/2/conversions/conversionRate", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getNoClickRate.json b/tests/CTS/clients/analytics/getNoClickRate.json index 45e6d191e8..44c5d94e81 100644 --- a/tests/CTS/clients/analytics/getNoClickRate.json +++ b/tests/CTS/clients/analytics/getNoClickRate.json @@ -22,7 +22,12 @@ "request": { "path": "/2/searches/noClickRate", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getNoResultsRate.json b/tests/CTS/clients/analytics/getNoResultsRate.json index 2cd5bb3e8b..c41149768e 100644 --- a/tests/CTS/clients/analytics/getNoResultsRate.json +++ b/tests/CTS/clients/analytics/getNoResultsRate.json @@ -22,7 +22,12 @@ "request": { "path": "/2/searches/noResultRate", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getSearchesCount.json b/tests/CTS/clients/analytics/getSearchesCount.json index 6ce0ddab96..e1f533562e 100644 --- a/tests/CTS/clients/analytics/getSearchesCount.json +++ b/tests/CTS/clients/analytics/getSearchesCount.json @@ -22,7 +22,12 @@ "request": { "path": "/2/searches/count", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getSearchesNoClicks.json b/tests/CTS/clients/analytics/getSearchesNoClicks.json index c144519b61..6177538ac5 100644 --- a/tests/CTS/clients/analytics/getSearchesNoClicks.json +++ b/tests/CTS/clients/analytics/getSearchesNoClicks.json @@ -24,7 +24,14 @@ "request": { "path": "/2/searches/noClicks", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getSearchesNoResults.json b/tests/CTS/clients/analytics/getSearchesNoResults.json index e244b61656..be66e74c2d 100644 --- a/tests/CTS/clients/analytics/getSearchesNoResults.json +++ b/tests/CTS/clients/analytics/getSearchesNoResults.json @@ -24,7 +24,14 @@ "request": { "path": "/2/searches/noResults", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopCountries.json b/tests/CTS/clients/analytics/getTopCountries.json index 5c2a77705d..bb2efa885e 100644 --- a/tests/CTS/clients/analytics/getTopCountries.json +++ b/tests/CTS/clients/analytics/getTopCountries.json @@ -24,7 +24,14 @@ "request": { "path": "/2/countries", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterAttributes.json b/tests/CTS/clients/analytics/getTopFilterAttributes.json index 2652ade50f..9a2e6f779a 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributes.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributes.json @@ -24,7 +24,14 @@ "request": { "path": "/2/filters", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json b/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json index 53e3ad7eb6..9c47175ef2 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json @@ -26,7 +26,15 @@ "request": { "path": "/2/filters?search=mySearch", "method": "GET", - "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "search": "mySearch", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFilterForAttribute.json b/tests/CTS/clients/analytics/getTopFilterForAttribute.json index 1879ed4d4a..2b2e2e7b0c 100644 --- a/tests/CTS/clients/analytics/getTopFilterForAttribute.json +++ b/tests/CTS/clients/analytics/getTopFilterForAttribute.json @@ -38,7 +38,15 @@ "request": { "path": "/2/filters/myAttribute", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "attribute": "myAttribute", + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } }, { @@ -56,7 +64,15 @@ "request": { "path": "/2/filters/myAttribute1%2CmyAttribute2", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "attribute": "myAttribute1,myAttribute2", + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json b/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json index 8ce7a06fa1..671a96844f 100644 --- a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json +++ b/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json @@ -60,7 +60,15 @@ "request": { "path": "/2/filters/myAttribute1%2CmyAttribute2?search=mySearch", "method": "GET", - "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "search": "mySearch", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResults.json b/tests/CTS/clients/analytics/getTopFiltersNoResults.json index 41a3011188..7b2e33d126 100644 --- a/tests/CTS/clients/analytics/getTopFiltersNoResults.json +++ b/tests/CTS/clients/analytics/getTopFiltersNoResults.json @@ -24,7 +24,14 @@ "request": { "path": "/2/filters/noResults", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json b/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json index 1f173d1ea8..a3d034a22d 100644 --- a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json +++ b/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json @@ -26,7 +26,15 @@ "request": { "path": "/2/filters/noResults?search=mySearch", "method": "GET", - "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "search": "mySearch", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopHits.json b/tests/CTS/clients/analytics/getTopHits.json index c364ce7e54..3aedd5de15 100644 --- a/tests/CTS/clients/analytics/getTopHits.json +++ b/tests/CTS/clients/analytics/getTopHits.json @@ -25,7 +25,15 @@ "request": { "path": "/2/hits", "method": "GET", - "searchParams": "?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "clickAnalytics": "true", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopHitsForSearch.json b/tests/CTS/clients/analytics/getTopHitsForSearch.json index 7872820a2b..75cd687d48 100644 --- a/tests/CTS/clients/analytics/getTopHitsForSearch.json +++ b/tests/CTS/clients/analytics/getTopHitsForSearch.json @@ -27,7 +27,16 @@ "request": { "path": "/2/hits?search=mySearch", "method": "GET", - "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "search": "mySearch", + "clickAnalytics": "true", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopSearches.json b/tests/CTS/clients/analytics/getTopSearches.json index ba8e3185d5..741c5981e9 100644 --- a/tests/CTS/clients/analytics/getTopSearches.json +++ b/tests/CTS/clients/analytics/getTopSearches.json @@ -27,7 +27,17 @@ "request": { "path": "/2/searches", "method": "GET", - "searchParams": "?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&orderBy=searchCount&direction=asc&limit=21&offset=42&tags=tag" + "searchParams": { + "index": "index", + "clickAnalytics": "true", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "orderBy": "searchCount", + "direction": "asc", + "limit": "21", + "offset": "42", + "tags": "tag" + } } } ] diff --git a/tests/CTS/clients/analytics/getUsersCount.json b/tests/CTS/clients/analytics/getUsersCount.json index 626ec03609..78f6b3799a 100644 --- a/tests/CTS/clients/analytics/getUsersCount.json +++ b/tests/CTS/clients/analytics/getUsersCount.json @@ -22,7 +22,12 @@ "request": { "path": "/2/users/count", "method": "GET", - "searchParams": "?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag" + "searchParams": { + "index": "index", + "startDate": "1999-09-19", + "endDate": "2001-01-01", + "tags": "tag" + } } } ] diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index 49afd3a14e..80b01ad5d2 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -12,7 +12,7 @@ describe('{{operationId}}', () => { const req = await client.{{method}}( {{#hasParameters}}{ {{#parametersWithDataType}} - {{#isDate}}{{{key}}}:new Date({{{value}}}),{{/isDate}}{{^isDate}}{{{key}}}:{{{value}}},{{/isDate}} + {{#isDate}}{{{key}}}:{{{value}}} as unknown as Date,{{/isDate}}{{^isDate}}{{{key}}}:{{{value}}},{{/isDate}} {{/parametersWithDataType}} }{{/hasParameters}} ); @@ -20,7 +20,7 @@ describe('{{operationId}}', () => { expect(req).toEqual(expect.objectContaining({ path: '{{{request.path}}}', method: '{{{request.method}}}', - {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: {{{.}}},{{/request.searchParams}} + {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: expect.objectContaining({{{.}}}),{{/request.searchParams}} })) }); diff --git a/tests/generateCTS.ts b/tests/generateCTS.ts index e829b6f5ae..9d4199651a 100644 --- a/tests/generateCTS.ts +++ b/tests/generateCTS.ts @@ -131,6 +131,7 @@ async function loadCTSForClient(client: string): Promise { if (test.testName === undefined) { test.testName = test.method; } + // stringify request.data too test.request.data = JSON.stringify(test.request.data); test.request.headers = JSON.stringify(test.request.headers); diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 1dc742a5d1..46738aba79 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -24,8 +24,8 @@ describe('getAverageClickPosition', () => { test('get getAverageClickPosition with all parameters', async () => { const req = await client.getAverageClickPosition({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -33,8 +33,12 @@ describe('getAverageClickPosition', () => { expect.objectContaining({ path: '/2/clicks/averageClickPosition', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -57,8 +61,8 @@ describe('getClickPositions', () => { test('get getClickPositions with all parameters', async () => { const req = await client.getClickPositions({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -66,8 +70,12 @@ describe('getClickPositions', () => { expect.objectContaining({ path: '/2/clicks/positions', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -90,8 +98,8 @@ describe('getClickThroughRate', () => { test('get getClickThroughRate with all parameters', async () => { const req = await client.getClickThroughRate({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -99,8 +107,12 @@ describe('getClickThroughRate', () => { expect.objectContaining({ path: '/2/clicks/clickThroughRate', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -123,8 +135,8 @@ describe('getConversationRate', () => { test('get getConversationRate with all parameters', async () => { const req = await client.getConversationRate({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -132,8 +144,12 @@ describe('getConversationRate', () => { expect.objectContaining({ path: '/2/conversions/conversionRate', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -156,8 +172,8 @@ describe('getNoClickRate', () => { test('get getNoClickRate with all parameters', async () => { const req = await client.getNoClickRate({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -165,8 +181,12 @@ describe('getNoClickRate', () => { expect.objectContaining({ path: '/2/searches/noClickRate', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -189,8 +209,8 @@ describe('getNoResultsRate', () => { test('get getNoResultsRate with all parameters', async () => { const req = await client.getNoResultsRate({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -198,8 +218,12 @@ describe('getNoResultsRate', () => { expect.objectContaining({ path: '/2/searches/noResultRate', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -222,8 +246,8 @@ describe('getSearchesCount', () => { test('get getSearchesCount with all parameters', async () => { const req = await client.getSearchesCount({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -231,8 +255,12 @@ describe('getSearchesCount', () => { expect.objectContaining({ path: '/2/searches/count', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); @@ -255,8 +283,8 @@ describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with all parameters', async () => { const req = await client.getSearchesNoClicks({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -266,8 +294,14 @@ describe('getSearchesNoClicks', () => { expect.objectContaining({ path: '/2/searches/noClicks', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -290,8 +324,8 @@ describe('getSearchesNoResults', () => { test('get getSearchesNoResults with all parameters', async () => { const req = await client.getSearchesNoResults({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -301,8 +335,14 @@ describe('getSearchesNoResults', () => { expect.objectContaining({ path: '/2/searches/noResults', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -340,8 +380,8 @@ describe('getTopCountries', () => { test('get getTopCountries with all parameters', async () => { const req = await client.getTopCountries({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -351,8 +391,14 @@ describe('getTopCountries', () => { expect.objectContaining({ path: '/2/countries', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -375,8 +421,8 @@ describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with all parameters', async () => { const req = await client.getTopFilterAttributes({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -386,8 +432,14 @@ describe('getTopFilterAttributes', () => { expect.objectContaining({ path: '/2/filters', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -412,8 +464,8 @@ describe('getTopFilterAttributesForSearch', () => { const req = await client.getTopFilterAttributesForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -423,8 +475,15 @@ describe('getTopFilterAttributesForSearch', () => { expect.objectContaining({ path: '/2/filters?search=mySearch', method: 'GET', - searchParams: - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -463,8 +522,8 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -474,8 +533,15 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + attribute: 'myAttribute', + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -484,8 +550,8 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -495,8 +561,15 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + attribute: 'myAttribute1,myAttribute2', + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -538,8 +611,8 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute', index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -549,8 +622,9 @@ describe('getTopFiltersForAttributesSearch', () => { expect.objectContaining({ path: '/2/filters/myAttribute?search=mySearch', method: 'GET', - searchParams: - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining( + '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag' + ), }) ); }); @@ -560,8 +634,8 @@ describe('getTopFiltersForAttributesSearch', () => { attributes: 'myAttribute1,myAttribute2', index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -571,8 +645,15 @@ describe('getTopFiltersForAttributesSearch', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', method: 'GET', - searchParams: - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -595,8 +676,8 @@ describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with all parameters', async () => { const req = await client.getTopFiltersNoResults({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -606,8 +687,14 @@ describe('getTopFiltersNoResults', () => { expect.objectContaining({ path: '/2/filters/noResults', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -632,8 +719,8 @@ describe('getTopFiltersNoResultsForSearch', () => { const req = await client.getTopFiltersNoResultsForSearch({ index: 'index', search: 'mySearch', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -643,8 +730,15 @@ describe('getTopFiltersNoResultsForSearch', () => { expect.objectContaining({ path: '/2/filters/noResults?search=mySearch', method: 'GET', - searchParams: - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -668,8 +762,8 @@ describe('getTopHits', () => { const req = await client.getTopHits({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -679,8 +773,15 @@ describe('getTopHits', () => { expect.objectContaining({ path: '/2/hits', method: 'GET', - searchParams: - '?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + clickAnalytics: 'true', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -706,8 +807,8 @@ describe('getTopHitsForSearch', () => { index: 'index', search: 'mySearch', clickAnalytics: true, - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, limit: 21, offset: 42, tags: 'tag', @@ -717,8 +818,16 @@ describe('getTopHitsForSearch', () => { expect.objectContaining({ path: '/2/hits?search=mySearch', method: 'GET', - searchParams: - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + search: 'mySearch', + clickAnalytics: 'true', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -742,8 +851,8 @@ describe('getTopSearches', () => { const req = await client.getTopSearches({ index: 'index', clickAnalytics: true, - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, orderBy: 'searchCount', direction: 'asc', limit: 21, @@ -755,8 +864,17 @@ describe('getTopSearches', () => { expect.objectContaining({ path: '/2/searches', method: 'GET', - searchParams: - '?index=index&clickAnalytics=true&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&orderBy=searchCount&direction=asc&limit=21&offset=42&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + clickAnalytics: 'true', + startDate: '1999-09-19', + endDate: '2001-01-01', + orderBy: 'searchCount', + direction: 'asc', + limit: '21', + offset: '42', + tags: 'tag', + }), }) ); }); @@ -779,8 +897,8 @@ describe('getUsersCount', () => { test('get getUsersCount with all parameters', async () => { const req = await client.getUsersCount({ index: 'index', - startDate: new Date('1999-09-19'), - endDate: new Date('2001-01-01'), + startDate: '1999-09-19' as unknown as Date, + endDate: '2001-01-01' as unknown as Date, tags: 'tag', }); @@ -788,8 +906,12 @@ describe('getUsersCount', () => { expect.objectContaining({ path: '/2/users/count', method: 'GET', - searchParams: - '?index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&tags=tag', + searchParams: expect.objectContaining({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }), }) ); }); From db35de7b2153674a94cde408613048bf028ce8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= <20689156+shortcuts@users.noreply.github.com> Date: Mon, 10 Jan 2022 11:01:20 +0100 Subject: [PATCH 6/9] fix(specs): analytics paths and params (#73) --- .../client-analytics/src/analyticsApi.ts | 527 ++---------------- specs/analytics/paths/common/parameters.yml | 15 +- .../search/getSearchAttributesTopFilters.yml | 63 --- .../paths/search/getTopFilterAttributes.yml | 1 + .../getTopFilterAttributesForSearch.yml | 29 - .../paths/search/getTopFilterForAttribute.yml | 1 + .../getTopFiltersForAttributesSearch.yml | 35 -- .../paths/search/getTopFiltersNoResults.yml | 1 + .../getTopFiltersNoResultsForSearch.yml | 29 - specs/analytics/paths/search/getTopHits.yml | 1 + .../paths/search/getTopHitsForSearch.yml | 32 -- specs/analytics/spec.yml | 8 - specs/common/parameters.yml | 6 +- .../analytics/getTopFilterAttributes.json | 2 + .../getTopFilterAttributesForSearch.json | 40 -- .../analytics/getTopFilterForAttribute.json | 16 +- .../getTopFiltersForAttributesSearch.json | 74 --- .../analytics/getTopFiltersNoResults.json | 7 +- .../getTopFiltersNoResultsForSearch.json | 40 -- tests/CTS/clients/analytics/getTopHits.json | 2 + .../analytics/getTopHitsForSearch.json | 42 -- tests/CTS/templates/javascript.mustache | 6 +- tests/output/javascript/analytics.test.ts | 357 ++---------- .../output/javascript/personalization.test.ts | 8 +- tests/output/javascript/search.test.ts | 24 +- 25 files changed, 157 insertions(+), 1209 deletions(-) delete mode 100644 specs/analytics/paths/search/getSearchAttributesTopFilters.yml delete mode 100644 specs/analytics/paths/search/getTopFilterAttributesForSearch.yml delete mode 100644 specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml delete mode 100644 specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml delete mode 100644 specs/analytics/paths/search/getTopHitsForSearch.yml delete mode 100644 tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json delete mode 100644 tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json delete mode 100644 tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json delete mode 100644 tests/CTS/clients/analytics/getTopHitsForSearch.json diff --git a/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts b/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts index f41e3db1d4..3e1d144b6a 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts @@ -712,6 +712,7 @@ export class AnalyticsApi { * @summary Returns top filter attributes. * @param getTopFilterAttributes - The getTopFilterAttributes parameters. * @param getTopFilterAttributes.index - The index name to target. + * @param getTopFilterAttributes.search - The query term to search for. Must match the exact user input. * @param getTopFilterAttributes.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFilterAttributes.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFilterAttributes.limit - How many items to fetch. @@ -720,6 +721,7 @@ export class AnalyticsApi { */ getTopFilterAttributes({ index, + search, startDate, endDate, limit, @@ -740,81 +742,8 @@ export class AnalyticsApi { queryParameters.index = index.toString(); } - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path, - }; - - const requestOptions: RequestOptions = { - headers, - queryParameters, - }; - - return this.sendRequest(request, requestOptions); - } - /** - * Returns top filter attributes for a given search. Limited to the 1000 most used filters. - * - * @summary Returns top filter attributes for a given search. - * @param getTopFilterAttributesForSearch - The getTopFilterAttributesForSearch parameters. - * @param getTopFilterAttributesForSearch.index - The index name to target. - * @param getTopFilterAttributesForSearch.search - The query term. Must match the exact user input. - * @param getTopFilterAttributesForSearch.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterAttributesForSearch.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFilterAttributesForSearch.limit - How many items to fetch. - * @param getTopFilterAttributesForSearch.offset - From which position to start retrieving results. - * @param getTopFilterAttributesForSearch.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFilterAttributesForSearch({ - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFilterAttributesForSearchProps): Promise { - const path = '/2/filters?search={search}'.replace( - '{search}', - encodeURIComponent(String(search)) - ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; - - if (index === null || index === undefined) { - throw new Error( - 'Required parameter index was null or undefined when calling getTopFilterAttributesForSearch.' - ); - } - - if (search === null || search === undefined) { - throw new Error( - 'Required parameter search was null or undefined when calling getTopFilterAttributesForSearch.' - ); - } - - if (index !== undefined) { - queryParameters.index = index.toString(); + if (search !== undefined) { + queryParameters.search = search.toString(); } if (startDate !== undefined) { @@ -856,6 +785,7 @@ export class AnalyticsApi { * @param getTopFilterForAttribute - The getTopFilterForAttribute parameters. * @param getTopFilterForAttribute.attribute - The exact name of the attribute. * @param getTopFilterForAttribute.index - The index name to target. + * @param getTopFilterForAttribute.search - The query term to search for. Must match the exact user input. * @param getTopFilterForAttribute.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFilterForAttribute.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFilterForAttribute.limit - How many items to fetch. @@ -865,6 +795,7 @@ export class AnalyticsApi { getTopFilterForAttribute({ attribute, index, + search, startDate, endDate, limit, @@ -894,88 +825,8 @@ export class AnalyticsApi { queryParameters.index = index.toString(); } - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path, - }; - - const requestOptions: RequestOptions = { - headers, - queryParameters, - }; - - return this.sendRequest(request, requestOptions); - } - /** - * Returns top filters for the given attributes and search. Several attributes can be given by separating them with a comma. Several attributes can be given by separating them with a comma. - * - * @summary Returns top filters for the given attributes and search. - * @param getTopFiltersForAttributesSearch - The getTopFiltersForAttributesSearch parameters. - * @param getTopFiltersForAttributesSearch.attributes - The exact names of the attributes, separated by commas. - * @param getTopFiltersForAttributesSearch.index - The index name to target. - * @param getTopFiltersForAttributesSearch.search - The query term. Must match the exact user input. - * @param getTopFiltersForAttributesSearch.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersForAttributesSearch.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersForAttributesSearch.limit - How many items to fetch. - * @param getTopFiltersForAttributesSearch.offset - From which position to start retrieving results. - * @param getTopFiltersForAttributesSearch.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFiltersForAttributesSearch({ - attributes, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFiltersForAttributesSearchProps): Promise { - const path = '/2/filters/{attributes}?search={search}' - .replace('{attributes}', encodeURIComponent(String(attributes))) - .replace('{search}', encodeURIComponent(String(search))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; - - if (attributes === null || attributes === undefined) { - throw new Error( - 'Required parameter attributes was null or undefined when calling getTopFiltersForAttributesSearch.' - ); - } - - if (index === null || index === undefined) { - throw new Error( - 'Required parameter index was null or undefined when calling getTopFiltersForAttributesSearch.' - ); - } - - if (search === null || search === undefined) { - throw new Error( - 'Required parameter search was null or undefined when calling getTopFiltersForAttributesSearch.' - ); - } - - if (index !== undefined) { - queryParameters.index = index.toString(); + if (search !== undefined) { + queryParameters.search = search.toString(); } if (startDate !== undefined) { @@ -1016,6 +867,7 @@ export class AnalyticsApi { * @summary Returns top filters with no results. * @param getTopFiltersNoResults - The getTopFiltersNoResults parameters. * @param getTopFiltersNoResults.index - The index name to target. + * @param getTopFiltersNoResults.search - The query term to search for. Must match the exact user input. * @param getTopFiltersNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFiltersNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopFiltersNoResults.limit - How many items to fetch. @@ -1024,6 +876,7 @@ export class AnalyticsApi { */ getTopFiltersNoResults({ index, + search, startDate, endDate, limit, @@ -1044,81 +897,8 @@ export class AnalyticsApi { queryParameters.index = index.toString(); } - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path, - }; - - const requestOptions: RequestOptions = { - headers, - queryParameters, - }; - - return this.sendRequest(request, requestOptions); - } - /** - * Returns top filters for the given no result search. Limited to the 1000 most used filters. - * - * @summary Returns top filters for the given no result search. - * @param getTopFiltersNoResultsForSearch - The getTopFiltersNoResultsForSearch parameters. - * @param getTopFiltersNoResultsForSearch.index - The index name to target. - * @param getTopFiltersNoResultsForSearch.search - The query term. Must match the exact user input. - * @param getTopFiltersNoResultsForSearch.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersNoResultsForSearch.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopFiltersNoResultsForSearch.limit - How many items to fetch. - * @param getTopFiltersNoResultsForSearch.offset - From which position to start retrieving results. - * @param getTopFiltersNoResultsForSearch.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopFiltersNoResultsForSearch({ - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFiltersNoResultsForSearchProps): Promise { - const path = '/2/filters/noResults?search={search}'.replace( - '{search}', - encodeURIComponent(String(search)) - ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; - - if (index === null || index === undefined) { - throw new Error( - 'Required parameter index was null or undefined when calling getTopFiltersNoResultsForSearch.' - ); - } - - if (search === null || search === undefined) { - throw new Error( - 'Required parameter search was null or undefined when calling getTopFiltersNoResultsForSearch.' - ); - } - - if (index !== undefined) { - queryParameters.index = index.toString(); + if (search !== undefined) { + queryParameters.search = search.toString(); } if (startDate !== undefined) { @@ -1159,6 +939,7 @@ export class AnalyticsApi { * @summary Returns top hits. * @param getTopHits - The getTopHits parameters. * @param getTopHits.index - The index name to target. + * @param getTopHits.search - The query term to search for. Must match the exact user input. * @param getTopHits.clickAnalytics - Whether to include the click-through and conversion rates for a search. * @param getTopHits.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getTopHits.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. @@ -1168,6 +949,7 @@ export class AnalyticsApi { */ getTopHits({ index, + search, clickAnalytics, startDate, endDate, @@ -1191,89 +973,8 @@ export class AnalyticsApi { queryParameters.index = index.toString(); } - if (clickAnalytics !== undefined) { - queryParameters.clickAnalytics = clickAnalytics.toString(); - } - - if (startDate !== undefined) { - queryParameters.startDate = startDate.toString(); - } - - if (endDate !== undefined) { - queryParameters.endDate = endDate.toString(); - } - - if (limit !== undefined) { - queryParameters.limit = limit.toString(); - } - - if (offset !== undefined) { - queryParameters.offset = offset.toString(); - } - - if (tags !== undefined) { - queryParameters.tags = tags.toString(); - } - - const request: Request = { - method: 'GET', - path, - }; - - const requestOptions: RequestOptions = { - headers, - queryParameters, - }; - - return this.sendRequest(request, requestOptions); - } - /** - * Returns top hits for the given search. Limited to the 1000 most frequent ones. - * - * @summary Returns top hits for the given search. - * @param getTopHitsForSearch - The getTopHitsForSearch parameters. - * @param getTopHitsForSearch.index - The index name to target. - * @param getTopHitsForSearch.search - The query term. Must match the exact user input. - * @param getTopHitsForSearch.clickAnalytics - Whether to include the click-through and conversion rates for a search. - * @param getTopHitsForSearch.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopHitsForSearch.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - * @param getTopHitsForSearch.limit - How many items to fetch. - * @param getTopHitsForSearch.offset - From which position to start retrieving results. - * @param getTopHitsForSearch.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - getTopHitsForSearch({ - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopHitsForSearchProps): Promise< - GetTopHitsResponse | GetTopHitsResponseWithAnalytics - > { - const path = '/2/hits?search={search}'.replace( - '{search}', - encodeURIComponent(String(search)) - ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; - - if (index === null || index === undefined) { - throw new Error( - 'Required parameter index was null or undefined when calling getTopHitsForSearch.' - ); - } - - if (search === null || search === undefined) { - throw new Error( - 'Required parameter search was null or undefined when calling getTopHitsForSearch.' - ); - } - - if (index !== undefined) { - queryParameters.index = index.toString(); + if (search !== undefined) { + queryParameters.search = search.toString(); } if (clickAnalytics !== undefined) { @@ -1462,11 +1163,11 @@ export type GetAverageClickPositionProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1481,11 +1182,11 @@ export type GetClickPositionsProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1500,11 +1201,11 @@ export type GetClickThroughRateProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1519,11 +1220,11 @@ export type GetConversationRateProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1538,11 +1239,11 @@ export type GetNoClickRateProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1557,11 +1258,11 @@ export type GetNoResultsRateProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1576,11 +1277,11 @@ export type GetSearchesCountProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ @@ -1595,11 +1296,11 @@ export type GetSearchesNoClicksProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1622,11 +1323,11 @@ export type GetSearchesNoResultsProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1656,11 +1357,11 @@ export type GetTopCountriesProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1681,44 +1382,17 @@ export type GetTopFilterAttributesProps = { */ index: string; /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: Date; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: Date; - /** - * How many items to fetch. - */ - limit?: number; - /** - * From which position to start retrieving results. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFilterAttributesForSearchProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term. Must match the exact user input. + * The query term to search for. Must match the exact user input. */ - search: string; + search?: string; /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1743,48 +1417,17 @@ export type GetTopFilterForAttributeProps = { */ index: string; /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: Date; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: Date; - /** - * How many items to fetch. + * The query term to search for. Must match the exact user input. */ - limit?: number; - /** - * From which position to start retrieving results. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFiltersForAttributesSearchProps = { - /** - * The exact names of the attributes, separated by commas. - */ - attributes: string; - /** - * The index name to target. - */ - index: string; - /** - * The query term. Must match the exact user input. - */ - search: string; + search?: string; /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1805,44 +1448,17 @@ export type GetTopFiltersNoResultsProps = { */ index: string; /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: Date; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: Date; - /** - * How many items to fetch. + * The query term to search for. Must match the exact user input. */ - limit?: number; - /** - * From which position to start retrieving results. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopFiltersNoResultsForSearchProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term. Must match the exact user input. - */ - search: string; + search?: string; /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1863,40 +1479,9 @@ export type GetTopHitsProps = { */ index: string; /** - * Whether to include the click-through and conversion rates for a search. - */ - clickAnalytics?: boolean; - /** - * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - startDate?: Date; - /** - * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. - */ - endDate?: Date; - /** - * How many items to fetch. - */ - limit?: number; - /** - * From which position to start retrieving results. - */ - offset?: number; - /** - * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. - */ - tags?: string; -}; - -export type GetTopHitsForSearchProps = { - /** - * The index name to target. - */ - index: string; - /** - * The query term. Must match the exact user input. + * The query term to search for. Must match the exact user input. */ - search: string; + search?: string; /** * Whether to include the click-through and conversion rates for a search. */ @@ -1904,11 +1489,11 @@ export type GetTopHitsForSearchProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * How many items to fetch. */ @@ -1935,11 +1520,11 @@ export type GetTopSearchesProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Reorder the results. */ @@ -1974,11 +1559,11 @@ export type GetUsersCountProps = { /** * The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - startDate?: Date; + startDate?: string; /** * The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. */ - endDate?: Date; + endDate?: string; /** * Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ diff --git a/specs/analytics/paths/common/parameters.yml b/specs/analytics/paths/common/parameters.yml index 12a471cf0b..a92d33ea2d 100644 --- a/specs/analytics/paths/common/parameters.yml +++ b/specs/analytics/paths/common/parameters.yml @@ -7,14 +7,6 @@ Attribute: schema: type: string -Search: - in: path - name: search - description: The query term. Must match the exact user input. - required: true - schema: - type: string - # query OrderBy: in: query @@ -50,11 +42,10 @@ Limit: type: integer default: 10 -SearchInQuery: - in: path +Search: + in: query name: search - description: The query term. Must match the exact user input. - required: true + description: The query term to search for. Must match the exact user input. schema: type: string diff --git a/specs/analytics/paths/search/getSearchAttributesTopFilters.yml b/specs/analytics/paths/search/getSearchAttributesTopFilters.yml deleted file mode 100644 index 2dbe813d59..0000000000 --- a/specs/analytics/paths/search/getSearchAttributesTopFilters.yml +++ /dev/null @@ -1,63 +0,0 @@ -get: - tags: - - analytics - operationId: getSearchAttributesTopFilters - description: Returns top filters for the given no result search. Limited to the 1000 most used filters. - summary: Returns top filters for the given no result search. - parameters: - - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/Search' - - $ref: '../../../common/parameters.yml#/StartDate' - - $ref: '../../../common/parameters.yml#/EndDate' - - $ref: '../common/parameters.yml#/Limit' - - $ref: '../common/parameters.yml#/Offset' - - $ref: '../common/parameters.yml#/Tags' - responses: - '200': - description: OK - content: - application/json: - schema: - title: getSearchAttributesTopFiltersResponse - type: object - additionalProperties: false - required: - - values - properties: - values: - type: array - description: A list of filters without results. - items: - type: object - additionalProperties: false - required: - - values - - count - properties: - count: - description: The number of occurrences. - type: integer - values: - type: array - items: - type: object - additionalProperties: false - required: - - attribute - - operator - - value - properties: - attribute: - $ref: '../common/parameters.yml#/attribute' - operator: - $ref: '../common/parameters.yml#/operator' - value: - $ref: '../common/parameters.yml#/value' - '400': - $ref: ../../../common/responses/BadRequest.yml - '402': - $ref: ../../../common/responses/FeatureNotEnabled.yml - '403': - $ref: ../../../common/responses/MethodNotAllowed.yml - '404': - $ref: ../../../common/responses/IndexNotFound.yml diff --git a/specs/analytics/paths/search/getTopFilterAttributes.yml b/specs/analytics/paths/search/getTopFilterAttributes.yml index 226d54638d..bdb7cc1ffa 100644 --- a/specs/analytics/paths/search/getTopFilterAttributes.yml +++ b/specs/analytics/paths/search/getTopFilterAttributes.yml @@ -6,6 +6,7 @@ get: summary: Returns top filter attributes. parameters: - $ref: '../../../common/parameters.yml#/Index' + - $ref: '../common/parameters.yml#/Search' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml b/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml deleted file mode 100644 index 05efbe595a..0000000000 --- a/specs/analytics/paths/search/getTopFilterAttributesForSearch.yml +++ /dev/null @@ -1,29 +0,0 @@ -get: - tags: - - analytics - operationId: getTopFilterAttributesForSearch - description: Returns top filter attributes for a given search. Limited to the 1000 most used filters. - summary: Returns top filter attributes for a given search. - parameters: - - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInQuery' - - $ref: '../../../common/parameters.yml#/StartDate' - - $ref: '../../../common/parameters.yml#/EndDate' - - $ref: '../common/parameters.yml#/Limit' - - $ref: '../common/parameters.yml#/Offset' - - $ref: '../common/parameters.yml#/Tags' - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '../common/schemas/getTopFilterAttributes.yml#/getTopFilterAttributesResponse' - '400': - $ref: ../../../common/responses/BadRequest.yml - '402': - $ref: ../../../common/responses/FeatureNotEnabled.yml - '403': - $ref: ../../../common/responses/MethodNotAllowed.yml - '404': - $ref: ../../../common/responses/IndexNotFound.yml diff --git a/specs/analytics/paths/search/getTopFilterForAttribute.yml b/specs/analytics/paths/search/getTopFilterForAttribute.yml index dce6dd8306..4d7d6e89d2 100644 --- a/specs/analytics/paths/search/getTopFilterForAttribute.yml +++ b/specs/analytics/paths/search/getTopFilterForAttribute.yml @@ -7,6 +7,7 @@ get: parameters: - $ref: '../common/parameters.yml#/Attribute' - $ref: '../../../common/parameters.yml#/Index' + - $ref: '../common/parameters.yml#/Search' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml b/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml deleted file mode 100644 index b0046dab81..0000000000 --- a/specs/analytics/paths/search/getTopFiltersForAttributesSearch.yml +++ /dev/null @@ -1,35 +0,0 @@ -get: - tags: - - analytics - operationId: getTopFiltersForAttributesSearch - description: Returns top filters for the given attributes and search. Several attributes can be given by separating them with a comma. Several attributes can be given by separating them with a comma. - summary: Returns top filters for the given attributes and search. - parameters: - - in: path - name: attributes - required: true - description: The exact names of the attributes, separated by commas. - schema: - type: string - - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInQuery' - - $ref: '../../../common/parameters.yml#/StartDate' - - $ref: '../../../common/parameters.yml#/EndDate' - - $ref: '../common/parameters.yml#/Limit' - - $ref: '../common/parameters.yml#/Offset' - - $ref: '../common/parameters.yml#/Tags' - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '../common/schemas/getTopFilterForAttribute.yml#/getTopFilterForAttributeResponse' - '400': - $ref: ../../../common/responses/BadRequest.yml - '402': - $ref: ../../../common/responses/FeatureNotEnabled.yml - '403': - $ref: ../../../common/responses/MethodNotAllowed.yml - '404': - $ref: ../../../common/responses/IndexNotFound.yml diff --git a/specs/analytics/paths/search/getTopFiltersNoResults.yml b/specs/analytics/paths/search/getTopFiltersNoResults.yml index 232c984035..da2a552b87 100644 --- a/specs/analytics/paths/search/getTopFiltersNoResults.yml +++ b/specs/analytics/paths/search/getTopFiltersNoResults.yml @@ -6,6 +6,7 @@ get: summary: Returns top filters with no results. parameters: - $ref: '../../../common/parameters.yml#/Index' + - $ref: '../common/parameters.yml#/Search' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' - $ref: '../common/parameters.yml#/Limit' diff --git a/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml b/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml deleted file mode 100644 index af9d3274ad..0000000000 --- a/specs/analytics/paths/search/getTopFiltersNoResultsForSearch.yml +++ /dev/null @@ -1,29 +0,0 @@ -get: - tags: - - analytics - operationId: getTopFiltersNoResultsForSearch - description: Returns top filters for the given no result search. Limited to the 1000 most used filters. - summary: Returns top filters for the given no result search. - parameters: - - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInQuery' - - $ref: '../../../common/parameters.yml#/StartDate' - - $ref: '../../../common/parameters.yml#/EndDate' - - $ref: '../common/parameters.yml#/Limit' - - $ref: '../common/parameters.yml#/Offset' - - $ref: '../common/parameters.yml#/Tags' - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '../common/schemas/getTopFiltersNoResults.yml#/getTopFiltersNoResultsResponse' - '400': - $ref: ../../../common/responses/BadRequest.yml - '402': - $ref: ../../../common/responses/FeatureNotEnabled.yml - '403': - $ref: ../../../common/responses/MethodNotAllowed.yml - '404': - $ref: ../../../common/responses/IndexNotFound.yml diff --git a/specs/analytics/paths/search/getTopHits.yml b/specs/analytics/paths/search/getTopHits.yml index ce6b8af451..ce5c0ae790 100644 --- a/specs/analytics/paths/search/getTopHits.yml +++ b/specs/analytics/paths/search/getTopHits.yml @@ -6,6 +6,7 @@ get: summary: Returns top hits. parameters: - $ref: '../../../common/parameters.yml#/Index' + - $ref: '../common/parameters.yml#/Search' - $ref: '../common/parameters.yml#/ClickAnalytics' - $ref: '../../../common/parameters.yml#/StartDate' - $ref: '../../../common/parameters.yml#/EndDate' diff --git a/specs/analytics/paths/search/getTopHitsForSearch.yml b/specs/analytics/paths/search/getTopHitsForSearch.yml deleted file mode 100644 index 527fcc20c5..0000000000 --- a/specs/analytics/paths/search/getTopHitsForSearch.yml +++ /dev/null @@ -1,32 +0,0 @@ -get: - tags: - - analytics - operationId: getTopHitsForSearch - description: Returns top hits for the given search. Limited to the 1000 most frequent ones. - summary: Returns top hits for the given search. - parameters: - - $ref: '../../../common/parameters.yml#/Index' - - $ref: '../common/parameters.yml#/SearchInQuery' - - $ref: '../common/parameters.yml#/ClickAnalytics' - - $ref: '../../../common/parameters.yml#/StartDate' - - $ref: '../../../common/parameters.yml#/EndDate' - - $ref: '../common/parameters.yml#/Limit' - - $ref: '../common/parameters.yml#/Offset' - - $ref: '../common/parameters.yml#/Tags' - responses: - '200': - description: OK - content: - application/json: - schema: - oneOf: - - $ref: '../common/schemas/getTopHits.yml#/getTopHitsResponse' - - $ref: '../common/schemas/getTopHits.yml#/getTopHitsResponseWithAnalytics' - '400': - $ref: ../../../common/responses/BadRequest.yml - '402': - $ref: ../../../common/responses/FeatureNotEnabled.yml - '403': - $ref: ../../../common/responses/MethodNotAllowed.yml - '404': - $ref: ../../../common/responses/IndexNotFound.yml diff --git a/specs/analytics/spec.yml b/specs/analytics/spec.yml index 08bf1f40b0..00594254e4 100644 --- a/specs/analytics/spec.yml +++ b/specs/analytics/spec.yml @@ -30,22 +30,14 @@ paths: $ref: paths/search/getNoClickRate.yml /2/hits: $ref: paths/search/getTopHits.yml - /2/hits?search={search}: - $ref: paths/search/getTopHitsForSearch.yml /2/users/count: $ref: paths/search/getUsersCount.yml /2/filters: $ref: paths/search/getTopFilterAttributes.yml /2/filters/{attribute}: $ref: paths/search/getTopFilterForAttribute.yml - /2/filters?search={search}: - $ref: paths/search/getTopFilterAttributesForSearch.yml /2/filters/noResults: $ref: paths/search/getTopFiltersNoResults.yml - /2/filters/noResults?search={search}: - $ref: paths/search/getTopFiltersNoResultsForSearch.yml - /2/filters/{attributes}?search={search}: - $ref: paths/search/getTopFiltersForAttributesSearch.yml /2/countries: $ref: paths/search/getTopCountries.yml diff --git a/specs/common/parameters.yml b/specs/common/parameters.yml index 4b4fc9721c..9209370516 100644 --- a/specs/common/parameters.yml +++ b/specs/common/parameters.yml @@ -32,7 +32,8 @@ StartDate: description: The lower bound timestamp (a date, a string like "2006-01-02") of the period to analyze. schema: type: string - format: date-time + example: 1999-09-19 + pattern: ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ EndDate: in: query @@ -40,7 +41,8 @@ EndDate: description: The upper bound timestamp (a date, a string like "2006-01-02") of the period to analyze. schema: type: string - format: date-time + example: 2000-01-21 + pattern: ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ ForwardToReplicas: in: query diff --git a/tests/CTS/clients/analytics/getTopFilterAttributes.json b/tests/CTS/clients/analytics/getTopFilterAttributes.json index 9a2e6f779a..d3a0a4d667 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributes.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributes.json @@ -15,6 +15,7 @@ "testName": "get getTopFilterAttributes with all parameters", "parameters": { "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": 21, @@ -26,6 +27,7 @@ "method": "GET", "searchParams": { "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": "21", diff --git a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json b/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json deleted file mode 100644 index 9c47175ef2..0000000000 --- a/tests/CTS/clients/analytics/getTopFilterAttributesForSearch.json +++ /dev/null @@ -1,40 +0,0 @@ -[ - { - "method": "getTopFilterAttributesForSearch", - "testName": "get getTopFilterAttributesForSearch with minimal parameters", - "parameters": { - "index": "index", - "search": "mySearch" - }, - "request": { - "path": "/2/filters?search=mySearch", - "method": "GET" - } - }, - { - "method": "getTopFilterAttributesForSearch", - "testName": "get getTopFilterAttributesForSearch with all parameters", - "parameters": { - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": 21, - "offset": 42, - "tags": "tag" - }, - "request": { - "path": "/2/filters?search=mySearch", - "method": "GET", - "searchParams": { - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": "21", - "offset": "42", - "tags": "tag" - } - } - } -] diff --git a/tests/CTS/clients/analytics/getTopFilterForAttribute.json b/tests/CTS/clients/analytics/getTopFilterForAttribute.json index 2b2e2e7b0c..3cbad8c0d9 100644 --- a/tests/CTS/clients/analytics/getTopFilterForAttribute.json +++ b/tests/CTS/clients/analytics/getTopFilterForAttribute.json @@ -8,7 +8,10 @@ }, "request": { "path": "/2/filters/myAttribute", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { @@ -20,7 +23,10 @@ }, "request": { "path": "/2/filters/myAttribute1%2CmyAttribute2", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { @@ -29,6 +35,7 @@ "parameters": { "attribute": "myAttribute", "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": 21, @@ -39,8 +46,8 @@ "path": "/2/filters/myAttribute", "method": "GET", "searchParams": { - "attribute": "myAttribute", "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": "21", @@ -55,6 +62,7 @@ "parameters": { "attribute": "myAttribute1,myAttribute2", "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": 21, @@ -65,8 +73,8 @@ "path": "/2/filters/myAttribute1%2CmyAttribute2", "method": "GET", "searchParams": { - "attribute": "myAttribute1,myAttribute2", "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": "21", diff --git a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json b/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json deleted file mode 100644 index 671a96844f..0000000000 --- a/tests/CTS/clients/analytics/getTopFiltersForAttributesSearch.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "method": "getTopFiltersForAttributesSearch", - "testName": "get getTopFiltersForAttributesSearch with minimal parameters", - "parameters": { - "attributes": "myAttribute", - "index": "index", - "search": "mySearch" - }, - "request": { - "path": "/2/filters/myAttribute?search=mySearch", - "method": "GET" - } - }, - { - "method": "getTopFiltersForAttributesSearch", - "testName": "get getTopFiltersForAttributesSearch with minimal parameters and multiple attributes", - "parameters": { - "attributes": "myAttribute1,myAttribute2", - "index": "index", - "search": "mySearch" - }, - "request": { - "path": "/2/filters/myAttribute1%2CmyAttribute2?search=mySearch", - "method": "GET" - } - }, - { - "method": "getTopFiltersForAttributesSearch", - "testName": "get getTopFiltersForAttributesSearch with all parameters", - "parameters": { - "attributes": "myAttribute", - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": 21, - "offset": 42, - "tags": "tag" - }, - "request": { - "path": "/2/filters/myAttribute?search=mySearch", - "method": "GET", - "searchParams": "?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag" - } - }, - { - "method": "getTopFiltersForAttributesSearch", - "testName": "get getTopFiltersForAttributesSearch with all parameters and multiple attributes", - "parameters": { - "attributes": "myAttribute1,myAttribute2", - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": 21, - "offset": 42, - "tags": "tag" - }, - "request": { - "path": "/2/filters/myAttribute1%2CmyAttribute2?search=mySearch", - "method": "GET", - "searchParams": { - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": "21", - "offset": "42", - "tags": "tag" - } - } - } -] diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResults.json b/tests/CTS/clients/analytics/getTopFiltersNoResults.json index 7b2e33d126..47c3b5b288 100644 --- a/tests/CTS/clients/analytics/getTopFiltersNoResults.json +++ b/tests/CTS/clients/analytics/getTopFiltersNoResults.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/filters/noResults", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { @@ -15,6 +18,7 @@ "testName": "get getTopFiltersNoResults with all parameters", "parameters": { "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": 21, @@ -26,6 +30,7 @@ "method": "GET", "searchParams": { "index": "index", + "search": "mySearch", "startDate": "1999-09-19", "endDate": "2001-01-01", "limit": "21", diff --git a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json b/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json deleted file mode 100644 index a3d034a22d..0000000000 --- a/tests/CTS/clients/analytics/getTopFiltersNoResultsForSearch.json +++ /dev/null @@ -1,40 +0,0 @@ -[ - { - "method": "getTopFiltersNoResultsForSearch", - "testName": "get getTopFiltersNoResultsForSearch with minimal parameters", - "parameters": { - "index": "index", - "search": "mySearch" - }, - "request": { - "path": "/2/filters/noResults?search=mySearch", - "method": "GET" - } - }, - { - "method": "getTopFiltersNoResultsForSearch", - "testName": "get getTopFiltersNoResultsForSearch with all parameters", - "parameters": { - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": 21, - "offset": 42, - "tags": "tag" - }, - "request": { - "path": "/2/filters/noResults?search=mySearch", - "method": "GET", - "searchParams": { - "index": "index", - "search": "mySearch", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": "21", - "offset": "42", - "tags": "tag" - } - } - } -] diff --git a/tests/CTS/clients/analytics/getTopHits.json b/tests/CTS/clients/analytics/getTopHits.json index 3aedd5de15..5eb78cd2ff 100644 --- a/tests/CTS/clients/analytics/getTopHits.json +++ b/tests/CTS/clients/analytics/getTopHits.json @@ -15,6 +15,7 @@ "testName": "get getTopHits with all parameters", "parameters": { "index": "index", + "search": "mySearch", "clickAnalytics": true, "startDate": "1999-09-19", "endDate": "2001-01-01", @@ -27,6 +28,7 @@ "method": "GET", "searchParams": { "index": "index", + "search": "mySearch", "clickAnalytics": "true", "startDate": "1999-09-19", "endDate": "2001-01-01", diff --git a/tests/CTS/clients/analytics/getTopHitsForSearch.json b/tests/CTS/clients/analytics/getTopHitsForSearch.json deleted file mode 100644 index 75cd687d48..0000000000 --- a/tests/CTS/clients/analytics/getTopHitsForSearch.json +++ /dev/null @@ -1,42 +0,0 @@ -[ - { - "method": "getTopHitsForSearch", - "testName": "get getTopHitsForSearch with minimal parameters", - "parameters": { - "index": "index", - "search": "mySearch" - }, - "request": { - "path": "/2/hits?search=mySearch", - "method": "GET" - } - }, - { - "method": "getTopHitsForSearch", - "testName": "get getTopHitsForSearch with all parameters", - "parameters": { - "index": "index", - "search": "mySearch", - "clickAnalytics": true, - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": 21, - "offset": 42, - "tags": "tag" - }, - "request": { - "path": "/2/hits?search=mySearch", - "method": "GET", - "searchParams": { - "index": "index", - "search": "mySearch", - "clickAnalytics": "true", - "startDate": "1999-09-19", - "endDate": "2001-01-01", - "limit": "21", - "offset": "42", - "tags": "tag" - } - } - } -] diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index 80b01ad5d2..d8128aed8b 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -10,11 +10,7 @@ describe('{{operationId}}', () => { {{#tests}} test('{{testName}}', async () => { const req = await client.{{method}}( - {{#hasParameters}}{ - {{#parametersWithDataType}} - {{#isDate}}{{{key}}}:{{{value}}} as unknown as Date,{{/isDate}}{{^isDate}}{{{key}}}:{{{value}}},{{/isDate}} - {{/parametersWithDataType}} - }{{/hasParameters}} + {{#hasParameters}}{{{parameters}}}{{/hasParameters}} ); expect(req).toEqual(expect.objectContaining({ diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 46738aba79..671fe20033 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -9,9 +9,7 @@ const client = new AnalyticsApi(appId, apiKey, 'de', { describe('getAverageClickPosition', () => { test('get getAverageClickPosition with minimal parameters', async () => { - const req = await client.getAverageClickPosition({ - index: 'index', - }); + const req = await client.getAverageClickPosition({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -24,8 +22,8 @@ describe('getAverageClickPosition', () => { test('get getAverageClickPosition with all parameters', async () => { const req = await client.getAverageClickPosition({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -46,9 +44,7 @@ describe('getAverageClickPosition', () => { describe('getClickPositions', () => { test('get getClickPositions with minimal parameters', async () => { - const req = await client.getClickPositions({ - index: 'index', - }); + const req = await client.getClickPositions({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -61,8 +57,8 @@ describe('getClickPositions', () => { test('get getClickPositions with all parameters', async () => { const req = await client.getClickPositions({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -83,9 +79,7 @@ describe('getClickPositions', () => { describe('getClickThroughRate', () => { test('get getClickThroughRate with minimal parameters', async () => { - const req = await client.getClickThroughRate({ - index: 'index', - }); + const req = await client.getClickThroughRate({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -98,8 +92,8 @@ describe('getClickThroughRate', () => { test('get getClickThroughRate with all parameters', async () => { const req = await client.getClickThroughRate({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -120,9 +114,7 @@ describe('getClickThroughRate', () => { describe('getConversationRate', () => { test('get getConversationRate with minimal parameters', async () => { - const req = await client.getConversationRate({ - index: 'index', - }); + const req = await client.getConversationRate({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -135,8 +127,8 @@ describe('getConversationRate', () => { test('get getConversationRate with all parameters', async () => { const req = await client.getConversationRate({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -157,9 +149,7 @@ describe('getConversationRate', () => { describe('getNoClickRate', () => { test('get getNoClickRate with minimal parameters', async () => { - const req = await client.getNoClickRate({ - index: 'index', - }); + const req = await client.getNoClickRate({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -172,8 +162,8 @@ describe('getNoClickRate', () => { test('get getNoClickRate with all parameters', async () => { const req = await client.getNoClickRate({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -194,9 +184,7 @@ describe('getNoClickRate', () => { describe('getNoResultsRate', () => { test('get getNoResultsRate with minimal parameters', async () => { - const req = await client.getNoResultsRate({ - index: 'index', - }); + const req = await client.getNoResultsRate({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -209,8 +197,8 @@ describe('getNoResultsRate', () => { test('get getNoResultsRate with all parameters', async () => { const req = await client.getNoResultsRate({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -231,9 +219,7 @@ describe('getNoResultsRate', () => { describe('getSearchesCount', () => { test('get getSearchesCount with minimal parameters', async () => { - const req = await client.getSearchesCount({ - index: 'index', - }); + const req = await client.getSearchesCount({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -246,8 +232,8 @@ describe('getSearchesCount', () => { test('get getSearchesCount with all parameters', async () => { const req = await client.getSearchesCount({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); @@ -268,9 +254,7 @@ describe('getSearchesCount', () => { describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with minimal parameters', async () => { - const req = await client.getSearchesNoClicks({ - index: 'index', - }); + const req = await client.getSearchesNoClicks({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -283,8 +267,8 @@ describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with all parameters', async () => { const req = await client.getSearchesNoClicks({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -309,9 +293,7 @@ describe('getSearchesNoClicks', () => { describe('getSearchesNoResults', () => { test('get getSearchesNoResults with minimal parameters', async () => { - const req = await client.getSearchesNoResults({ - index: 'index', - }); + const req = await client.getSearchesNoResults({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -324,8 +306,8 @@ describe('getSearchesNoResults', () => { test('get getSearchesNoResults with all parameters', async () => { const req = await client.getSearchesNoResults({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -350,9 +332,7 @@ describe('getSearchesNoResults', () => { describe('getStatus', () => { test('get getStatus with minimal parameters', async () => { - const req = await client.getStatus({ - index: 'index', - }); + const req = await client.getStatus({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -365,9 +345,7 @@ describe('getStatus', () => { describe('getTopCountries', () => { test('get getTopCountries with minimal parameters', async () => { - const req = await client.getTopCountries({ - index: 'index', - }); + const req = await client.getTopCountries({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -380,8 +358,8 @@ describe('getTopCountries', () => { test('get getTopCountries with all parameters', async () => { const req = await client.getTopCountries({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -406,9 +384,7 @@ describe('getTopCountries', () => { describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with minimal parameters', async () => { - const req = await client.getTopFilterAttributes({ - index: 'index', - }); + const req = await client.getTopFilterAttributes({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -420,52 +396,10 @@ describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with all parameters', async () => { const req = await client.getTopFilterAttributes({ - index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, - limit: 21, - offset: 42, - tags: 'tag', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters', - method: 'GET', - searchParams: expect.objectContaining({ - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }), - }) - ); - }); -}); - -describe('getTopFilterAttributesForSearch', () => { - test('get getTopFilterAttributesForSearch with minimal parameters', async () => { - const req = await client.getTopFilterAttributesForSearch({ index: 'index', search: 'mySearch', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters?search=mySearch', - method: 'GET', - }) - ); - }); - - test('get getTopFilterAttributesForSearch with all parameters', async () => { - const req = await client.getTopFilterAttributesForSearch({ - index: 'index', - search: 'mySearch', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -473,7 +407,7 @@ describe('getTopFilterAttributesForSearch', () => { expect(req).toEqual( expect.objectContaining({ - path: '/2/filters?search=mySearch', + path: '/2/filters', method: 'GET', searchParams: expect.objectContaining({ index: 'index', @@ -500,6 +434,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute', method: 'GET', + searchParams: expect.objectContaining({ index: 'index' }), }) ); }); @@ -514,6 +449,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', + searchParams: expect.objectContaining({ index: 'index' }), }) ); }); @@ -522,8 +458,9 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute', index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -534,8 +471,8 @@ describe('getTopFilterForAttribute', () => { path: '/2/filters/myAttribute', method: 'GET', searchParams: expect.objectContaining({ - attribute: 'myAttribute', index: 'index', + search: 'mySearch', startDate: '1999-09-19', endDate: '2001-01-01', limit: '21', @@ -550,69 +487,9 @@ describe('getTopFilterForAttribute', () => { const req = await client.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, - limit: 21, - offset: 42, - tags: 'tag', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute1%2CmyAttribute2', - method: 'GET', - searchParams: expect.objectContaining({ - attribute: 'myAttribute1,myAttribute2', - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }), - }) - ); - }); -}); - -describe('getTopFiltersForAttributesSearch', () => { - test('get getTopFiltersForAttributesSearch with minimal parameters', async () => { - const req = await client.getTopFiltersForAttributesSearch({ - attributes: 'myAttribute', - index: 'index', - search: 'mySearch', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute?search=mySearch', - method: 'GET', - }) - ); - }); - - test('get getTopFiltersForAttributesSearch with minimal parameters and multiple attributes', async () => { - const req = await client.getTopFiltersForAttributesSearch({ - attributes: 'myAttribute1,myAttribute2', - index: 'index', - search: 'mySearch', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', - method: 'GET', - }) - ); - }); - - test('get getTopFiltersForAttributesSearch with all parameters', async () => { - const req = await client.getTopFiltersForAttributesSearch({ - attributes: 'myAttribute', - index: 'index', search: 'mySearch', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -620,30 +497,7 @@ describe('getTopFiltersForAttributesSearch', () => { expect(req).toEqual( expect.objectContaining({ - path: '/2/filters/myAttribute?search=mySearch', - method: 'GET', - searchParams: expect.objectContaining( - '?search=mySearch?x-algolia-agent=Algolia%20for%20Javascript&index=index&startDate=Sun%20Sep%2019%201999%2002:00:00%20GMT%200200%20(Central%20European%20Summer%20Time)&endDate=Mon%20Jan%2001%202001%2001:00:00%20GMT%200100%20(Central%20European%20Standard%20Time)&limit=21&offset=42&tags=tag' - ), - }) - ); - }); - - test('get getTopFiltersForAttributesSearch with all parameters and multiple attributes', async () => { - const req = await client.getTopFiltersForAttributesSearch({ - attributes: 'myAttribute1,myAttribute2', - index: 'index', - search: 'mySearch', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, - limit: 21, - offset: 42, - tags: 'tag', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute1%2CmyAttribute2?search=mySearch', + path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', searchParams: expect.objectContaining({ index: 'index', @@ -661,66 +515,23 @@ describe('getTopFiltersForAttributesSearch', () => { describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with minimal parameters', async () => { - const req = await client.getTopFiltersNoResults({ - index: 'index', - }); + const req = await client.getTopFiltersNoResults({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ path: '/2/filters/noResults', method: 'GET', + searchParams: expect.objectContaining({ index: 'index' }), }) ); }); test('get getTopFiltersNoResults with all parameters', async () => { const req = await client.getTopFiltersNoResults({ - index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, - limit: 21, - offset: 42, - tags: 'tag', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/noResults', - method: 'GET', - searchParams: expect.objectContaining({ - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }), - }) - ); - }); -}); - -describe('getTopFiltersNoResultsForSearch', () => { - test('get getTopFiltersNoResultsForSearch with minimal parameters', async () => { - const req = await client.getTopFiltersNoResultsForSearch({ - index: 'index', - search: 'mySearch', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/noResults?search=mySearch', - method: 'GET', - }) - ); - }); - - test('get getTopFiltersNoResultsForSearch with all parameters', async () => { - const req = await client.getTopFiltersNoResultsForSearch({ index: 'index', search: 'mySearch', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -728,7 +539,7 @@ describe('getTopFiltersNoResultsForSearch', () => { expect(req).toEqual( expect.objectContaining({ - path: '/2/filters/noResults?search=mySearch', + path: '/2/filters/noResults', method: 'GET', searchParams: expect.objectContaining({ index: 'index', @@ -746,9 +557,7 @@ describe('getTopFiltersNoResultsForSearch', () => { describe('getTopHits', () => { test('get getTopHits with minimal parameters', async () => { - const req = await client.getTopHits({ - index: 'index', - }); + const req = await client.getTopHits({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -760,55 +569,11 @@ describe('getTopHits', () => { test('get getTopHits with all parameters', async () => { const req = await client.getTopHits({ - index: 'index', - clickAnalytics: true, - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, - limit: 21, - offset: 42, - tags: 'tag', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/hits', - method: 'GET', - searchParams: expect.objectContaining({ - index: 'index', - clickAnalytics: 'true', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }), - }) - ); - }); -}); - -describe('getTopHitsForSearch', () => { - test('get getTopHitsForSearch with minimal parameters', async () => { - const req = await client.getTopHitsForSearch({ - index: 'index', - search: 'mySearch', - }); - - expect(req).toEqual( - expect.objectContaining({ - path: '/2/hits?search=mySearch', - method: 'GET', - }) - ); - }); - - test('get getTopHitsForSearch with all parameters', async () => { - const req = await client.getTopHitsForSearch({ index: 'index', search: 'mySearch', clickAnalytics: true, - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', limit: 21, offset: 42, tags: 'tag', @@ -816,7 +581,7 @@ describe('getTopHitsForSearch', () => { expect(req).toEqual( expect.objectContaining({ - path: '/2/hits?search=mySearch', + path: '/2/hits', method: 'GET', searchParams: expect.objectContaining({ index: 'index', @@ -835,9 +600,7 @@ describe('getTopHitsForSearch', () => { describe('getTopSearches', () => { test('get getTopSearches with minimal parameters', async () => { - const req = await client.getTopSearches({ - index: 'index', - }); + const req = await client.getTopSearches({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -851,8 +614,8 @@ describe('getTopSearches', () => { const req = await client.getTopSearches({ index: 'index', clickAnalytics: true, - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', orderBy: 'searchCount', direction: 'asc', limit: 21, @@ -882,9 +645,7 @@ describe('getTopSearches', () => { describe('getUsersCount', () => { test('get getUsersCount with minimal parameters', async () => { - const req = await client.getUsersCount({ - index: 'index', - }); + const req = await client.getUsersCount({ index: 'index' }); expect(req).toEqual( expect.objectContaining({ @@ -897,8 +658,8 @@ describe('getUsersCount', () => { test('get getUsersCount with all parameters', async () => { const req = await client.getUsersCount({ index: 'index', - startDate: '1999-09-19' as unknown as Date, - endDate: '2001-01-01' as unknown as Date, + startDate: '1999-09-19', + endDate: '2001-01-01', tags: 'tag', }); diff --git a/tests/output/javascript/personalization.test.ts b/tests/output/javascript/personalization.test.ts index b4005be18e..935ef2e5f1 100644 --- a/tests/output/javascript/personalization.test.ts +++ b/tests/output/javascript/personalization.test.ts @@ -12,9 +12,7 @@ const client = new PersonalizationApi(appId, apiKey, 'de', { describe('deleteUserProfile', () => { test('delete deleteUserProfile', async () => { - const req = await client.deleteUserProfile({ - userToken: 'UserToken', - }); + const req = await client.deleteUserProfile({ userToken: 'UserToken' }); expect(req).toEqual( expect.objectContaining({ @@ -40,9 +38,7 @@ describe('getPersonalizationStrategy', () => { describe('getUserTokenProfile', () => { test('get getUserTokenProfile', async () => { - const req = await client.getUserTokenProfile({ - userToken: 'UserToken', - }); + const req = await client.getUserTokenProfile({ userToken: 'UserToken' }); expect(req).toEqual( expect.objectContaining({ diff --git a/tests/output/javascript/search.test.ts b/tests/output/javascript/search.test.ts index 6eb094c137..6a975f51c8 100644 --- a/tests/output/javascript/search.test.ts +++ b/tests/output/javascript/search.test.ts @@ -170,9 +170,7 @@ describe('batchRules', () => { describe('browse', () => { test('get browse results with minimal parameters', async () => { - const req = await client.browse({ - indexName: 'indexName', - }); + const req = await client.browse({ indexName: 'indexName' }); expect(req).toEqual( expect.objectContaining({ @@ -203,9 +201,7 @@ describe('browse', () => { describe('clearAllSynonyms', () => { test('clearAllSynonyms', async () => { - const req = await client.clearAllSynonyms({ - indexName: 'indexName', - }); + const req = await client.clearAllSynonyms({ indexName: 'indexName' }); expect(req).toEqual( expect.objectContaining({ @@ -218,9 +214,7 @@ describe('clearAllSynonyms', () => { describe('clearRules', () => { test('clearRules', async () => { - const req = await client.clearRules({ - indexName: 'indexName', - }); + const req = await client.clearRules({ indexName: 'indexName' }); expect(req).toEqual( expect.objectContaining({ @@ -233,9 +227,7 @@ describe('clearRules', () => { describe('deleteApiKey', () => { test('deleteApiKey', async () => { - const req = await client.deleteApiKey({ - key: 'myTestApiKey', - }); + const req = await client.deleteApiKey({ key: 'myTestApiKey' }); expect(req).toEqual( expect.objectContaining({ @@ -280,9 +272,7 @@ describe('deleteSynonym', () => { describe('getApiKey', () => { test('getApiKey', async () => { - const req = await client.getApiKey({ - key: 'myTestApiKey', - }); + const req = await client.getApiKey({ key: 'myTestApiKey' }); expect(req).toEqual( expect.objectContaining({ @@ -366,9 +356,7 @@ describe('listApiKeys', () => { describe('restoreApiKey', () => { test('restoreApiKey', async () => { - const req = await client.restoreApiKey({ - key: 'myApiKey', - }); + const req = await client.restoreApiKey({ key: 'myApiKey' }); expect(req).toEqual( expect.objectContaining({ From 61eae55ce962e1a3da48b0a9daa046e7db7e4ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 10 Jan 2022 11:39:15 +0100 Subject: [PATCH 7/9] remove `objectContaining` on `searchParams` --- tests/CTS/templates/javascript.mustache | 2 +- tests/generateCTS.ts | 4 -- tests/output/javascript/analytics.test.ts | 74 +++++++++++------------ 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index d8128aed8b..c558de57f6 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -16,7 +16,7 @@ describe('{{operationId}}', () => { expect(req).toEqual(expect.objectContaining({ path: '{{{request.path}}}', method: '{{{request.method}}}', - {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: expect.objectContaining({{{.}}}),{{/request.searchParams}} + {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: {{{.}}},{{/request.searchParams}} })) }); diff --git a/tests/generateCTS.ts b/tests/generateCTS.ts index 9d4199651a..0af2103492 100644 --- a/tests/generateCTS.ts +++ b/tests/generateCTS.ts @@ -30,8 +30,6 @@ type Tests = { request: { path: string; method: string; - headers: string; - userAgent: string; data?: string; searchParams?: string; }; @@ -134,9 +132,7 @@ async function loadCTSForClient(client: string): Promise { // stringify request.data too test.request.data = JSON.stringify(test.request.data); - test.request.headers = JSON.stringify(test.request.headers); test.request.searchParams = JSON.stringify(test.request.searchParams); - test.request.userAgent = JSON.stringify(test.request.userAgent); if (Object.keys(test.parameters).length === 0) { test.parameters = undefined; diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index 671fe20033..f9d570eb38 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -31,12 +31,12 @@ describe('getAverageClickPosition', () => { expect.objectContaining({ path: '/2/clicks/averageClickPosition', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -66,12 +66,12 @@ describe('getClickPositions', () => { expect.objectContaining({ path: '/2/clicks/positions', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -101,12 +101,12 @@ describe('getClickThroughRate', () => { expect.objectContaining({ path: '/2/clicks/clickThroughRate', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -136,12 +136,12 @@ describe('getConversationRate', () => { expect.objectContaining({ path: '/2/conversions/conversionRate', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -171,12 +171,12 @@ describe('getNoClickRate', () => { expect.objectContaining({ path: '/2/searches/noClickRate', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -206,12 +206,12 @@ describe('getNoResultsRate', () => { expect.objectContaining({ path: '/2/searches/noResultRate', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -241,12 +241,12 @@ describe('getSearchesCount', () => { expect.objectContaining({ path: '/2/searches/count', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); @@ -278,14 +278,14 @@ describe('getSearchesNoClicks', () => { expect.objectContaining({ path: '/2/searches/noClicks', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -317,14 +317,14 @@ describe('getSearchesNoResults', () => { expect.objectContaining({ path: '/2/searches/noResults', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -369,14 +369,14 @@ describe('getTopCountries', () => { expect.objectContaining({ path: '/2/countries', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -409,7 +409,7 @@ describe('getTopFilterAttributes', () => { expect.objectContaining({ path: '/2/filters', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -417,7 +417,7 @@ describe('getTopFilterAttributes', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -434,7 +434,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute', method: 'GET', - searchParams: expect.objectContaining({ index: 'index' }), + searchParams: { index: 'index' }, }) ); }); @@ -449,7 +449,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', - searchParams: expect.objectContaining({ index: 'index' }), + searchParams: { index: 'index' }, }) ); }); @@ -470,7 +470,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -478,7 +478,7 @@ describe('getTopFilterForAttribute', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -499,7 +499,7 @@ describe('getTopFilterForAttribute', () => { expect.objectContaining({ path: '/2/filters/myAttribute1%2CmyAttribute2', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -507,7 +507,7 @@ describe('getTopFilterForAttribute', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -521,7 +521,7 @@ describe('getTopFiltersNoResults', () => { expect.objectContaining({ path: '/2/filters/noResults', method: 'GET', - searchParams: expect.objectContaining({ index: 'index' }), + searchParams: { index: 'index' }, }) ); }); @@ -541,7 +541,7 @@ describe('getTopFiltersNoResults', () => { expect.objectContaining({ path: '/2/filters/noResults', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', search: 'mySearch', startDate: '1999-09-19', @@ -549,7 +549,7 @@ describe('getTopFiltersNoResults', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -583,7 +583,7 @@ describe('getTopHits', () => { expect.objectContaining({ path: '/2/hits', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', search: 'mySearch', clickAnalytics: 'true', @@ -592,7 +592,7 @@ describe('getTopHits', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -627,7 +627,7 @@ describe('getTopSearches', () => { expect.objectContaining({ path: '/2/searches', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', clickAnalytics: 'true', startDate: '1999-09-19', @@ -637,7 +637,7 @@ describe('getTopSearches', () => { limit: '21', offset: '42', tags: 'tag', - }), + }, }) ); }); @@ -667,12 +667,12 @@ describe('getUsersCount', () => { expect.objectContaining({ path: '/2/users/count', method: 'GET', - searchParams: expect.objectContaining({ + searchParams: { index: 'index', startDate: '1999-09-19', endDate: '2001-01-01', tags: 'tag', - }), + }, }) ); }); From f9c18d23b49f647871661f8164fa1556d3a1cfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 10 Jan 2022 13:20:54 +0100 Subject: [PATCH 8/9] split assertions, make `EchoRequester` return undefined --- .../utils/requester/EchoRequester.ts | 18 +- .../utils/requester/EchoRequester.ts | 18 +- .../utils/requester/EchoRequester.ts | 18 +- .../utils/requester/EchoRequester.ts | 18 +- .../utils/requester/EchoRequester.ts | 18 +- .../utils/requester/EchoRequester.ts | 18 +- .../analytics/getAverageClickPosition.json | 5 +- .../clients/analytics/getClickPositions.json | 5 +- .../analytics/getClickThroughRate.json | 5 +- .../analytics/getConversationRate.json | 5 +- .../CTS/clients/analytics/getNoClickRate.json | 5 +- .../clients/analytics/getNoResultsRate.json | 5 +- .../clients/analytics/getSearchesCount.json | 5 +- .../analytics/getSearchesNoClicks.json | 5 +- .../analytics/getSearchesNoResults.json | 5 +- tests/CTS/clients/analytics/getStatus.json | 5 +- .../clients/analytics/getTopCountries.json | 5 +- .../analytics/getTopFilterAttributes.json | 5 +- tests/CTS/clients/analytics/getTopHits.json | 5 +- .../CTS/clients/analytics/getTopSearches.json | 5 +- .../CTS/clients/analytics/getUsersCount.json | 5 +- tests/CTS/clients/insights/pushEvents.json | 40 +- tests/CTS/clients/search/addApiKey.json | 10 +- tests/CTS/clients/search/batchRules.json | 6 +- tests/CTS/clients/search/saveRule.json | 3 + tests/CTS/clients/search/saveSynonym.json | 15 +- tests/CTS/clients/search/saveSynonyms.json | 30 +- tests/CTS/clients/search/searchSynonyms.json | 6 +- tests/CTS/clients/search/updateApiKey.json | 10 +- tests/CTS/templates/javascript.mustache | 9 +- tests/output/javascript/analytics.test.ts | 594 ++++++++---------- tests/output/javascript/insights.test.ts | 69 +- .../output/javascript/personalization.test.ts | 51 +- tests/output/javascript/recommend.test.ts | 180 +++--- tests/output/javascript/search.test.ts | 513 +++++++-------- 35 files changed, 791 insertions(+), 928 deletions(-) diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts index fd48553d4a..6f69e0ea26 100644 --- a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts @@ -7,10 +7,12 @@ type AdditionalContent = { connectTimeout: number; responseTimeout: number; userAgent: string | undefined; - searchParams: Record; + searchParams: Record | undefined; }; -function searchParamsWithoutUA(params: URLSearchParams): Record { +function searchParamsWithoutUA( + params: URLSearchParams +): Record | undefined { const searchParams = {}; for (const [k, v] of params) { @@ -21,7 +23,7 @@ function searchParamsWithoutUA(params: URLSearchParams): Record { searchParams[k] = v; } - return searchParams; + return Object.entries(searchParams).length === 0 ? undefined : searchParams; } export class EchoRequester extends Requester { @@ -31,7 +33,7 @@ export class EchoRequester extends Requester { send( { headers, url, connectTimeout, responseTimeout }: EndRequest, - originalRequest: Request + { data, ...originalRequest }: Request ): Promise { const urlSearchParams = new URL(url).searchParams; const userAgent = urlSearchParams.get('x-algolia-agent') || undefined; @@ -43,9 +45,15 @@ export class EchoRequester extends Requester { userAgent: userAgent ? encodeURI(userAgent) : undefined, searchParams, }; + const originalData = + data && Object.entries(data).length > 0 ? data : undefined; return Promise.resolve({ - content: JSON.stringify({ ...originalRequest, ...additionalContent }), + content: JSON.stringify({ + ...originalRequest, + ...additionalContent, + data: originalData, + }), isTimedOut: false, status: this.status, }); diff --git a/tests/CTS/clients/analytics/getAverageClickPosition.json b/tests/CTS/clients/analytics/getAverageClickPosition.json index 8fc2f6b953..2a5ca62405 100644 --- a/tests/CTS/clients/analytics/getAverageClickPosition.json +++ b/tests/CTS/clients/analytics/getAverageClickPosition.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/clicks/averageClickPosition", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getClickPositions.json b/tests/CTS/clients/analytics/getClickPositions.json index 56ffeed4cf..173abd2798 100644 --- a/tests/CTS/clients/analytics/getClickPositions.json +++ b/tests/CTS/clients/analytics/getClickPositions.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/clicks/positions", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getClickThroughRate.json b/tests/CTS/clients/analytics/getClickThroughRate.json index 9c576cf1ba..9fd79fa8bc 100644 --- a/tests/CTS/clients/analytics/getClickThroughRate.json +++ b/tests/CTS/clients/analytics/getClickThroughRate.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/clicks/clickThroughRate", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getConversationRate.json b/tests/CTS/clients/analytics/getConversationRate.json index eac532a3a1..10a3be49c2 100644 --- a/tests/CTS/clients/analytics/getConversationRate.json +++ b/tests/CTS/clients/analytics/getConversationRate.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/conversions/conversionRate", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getNoClickRate.json b/tests/CTS/clients/analytics/getNoClickRate.json index 44c5d94e81..ad9cbb0ef4 100644 --- a/tests/CTS/clients/analytics/getNoClickRate.json +++ b/tests/CTS/clients/analytics/getNoClickRate.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches/noClickRate", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getNoResultsRate.json b/tests/CTS/clients/analytics/getNoResultsRate.json index c41149768e..0033428e77 100644 --- a/tests/CTS/clients/analytics/getNoResultsRate.json +++ b/tests/CTS/clients/analytics/getNoResultsRate.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches/noResultRate", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getSearchesCount.json b/tests/CTS/clients/analytics/getSearchesCount.json index e1f533562e..3aa0651899 100644 --- a/tests/CTS/clients/analytics/getSearchesCount.json +++ b/tests/CTS/clients/analytics/getSearchesCount.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches/count", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getSearchesNoClicks.json b/tests/CTS/clients/analytics/getSearchesNoClicks.json index 6177538ac5..e55f488a51 100644 --- a/tests/CTS/clients/analytics/getSearchesNoClicks.json +++ b/tests/CTS/clients/analytics/getSearchesNoClicks.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches/noClicks", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getSearchesNoResults.json b/tests/CTS/clients/analytics/getSearchesNoResults.json index be66e74c2d..f568f1ffad 100644 --- a/tests/CTS/clients/analytics/getSearchesNoResults.json +++ b/tests/CTS/clients/analytics/getSearchesNoResults.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches/noResults", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getStatus.json b/tests/CTS/clients/analytics/getStatus.json index 4a468d88c3..48b33963c1 100644 --- a/tests/CTS/clients/analytics/getStatus.json +++ b/tests/CTS/clients/analytics/getStatus.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/status", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } } ] diff --git a/tests/CTS/clients/analytics/getTopCountries.json b/tests/CTS/clients/analytics/getTopCountries.json index bb2efa885e..679126e334 100644 --- a/tests/CTS/clients/analytics/getTopCountries.json +++ b/tests/CTS/clients/analytics/getTopCountries.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/countries", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getTopFilterAttributes.json b/tests/CTS/clients/analytics/getTopFilterAttributes.json index d3a0a4d667..f99e9386f7 100644 --- a/tests/CTS/clients/analytics/getTopFilterAttributes.json +++ b/tests/CTS/clients/analytics/getTopFilterAttributes.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/filters", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getTopHits.json b/tests/CTS/clients/analytics/getTopHits.json index 5eb78cd2ff..9fcb31162d 100644 --- a/tests/CTS/clients/analytics/getTopHits.json +++ b/tests/CTS/clients/analytics/getTopHits.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/hits", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getTopSearches.json b/tests/CTS/clients/analytics/getTopSearches.json index 741c5981e9..d0a271c5d8 100644 --- a/tests/CTS/clients/analytics/getTopSearches.json +++ b/tests/CTS/clients/analytics/getTopSearches.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/searches", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/analytics/getUsersCount.json b/tests/CTS/clients/analytics/getUsersCount.json index 78f6b3799a..113c78b30d 100644 --- a/tests/CTS/clients/analytics/getUsersCount.json +++ b/tests/CTS/clients/analytics/getUsersCount.json @@ -7,7 +7,10 @@ }, "request": { "path": "/2/users/count", - "method": "GET" + "method": "GET", + "searchParams": { + "index": "index" + } } }, { diff --git a/tests/CTS/clients/insights/pushEvents.json b/tests/CTS/clients/insights/pushEvents.json index 3de1e39ef2..c6f184f022 100644 --- a/tests/CTS/clients/insights/pushEvents.json +++ b/tests/CTS/clients/insights/pushEvents.json @@ -10,15 +10,9 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ], + "objectIDs": ["9780545139700", "9780439784542"], "queryID": "43b15df305339e827f0ac0bdc5ebcaa7", - "positions": [ - 7, - 6 - ] + "positions": [7, 6] }, { "eventType": "view", @@ -26,10 +20,7 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ] + "objectIDs": ["9780545139700", "9780439784542"] }, { "eventType": "conversion", @@ -37,10 +28,7 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ], + "objectIDs": ["9780545139700", "9780439784542"], "queryID": "43b15df305339e827f0ac0bdc5ebcaa7" } ] @@ -57,15 +45,9 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ], + "objectIDs": ["9780545139700", "9780439784542"], "queryID": "43b15df305339e827f0ac0bdc5ebcaa7", - "positions": [ - 7, - 6 - ] + "positions": [7, 6] }, { "eventType": "view", @@ -73,10 +55,7 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ] + "objectIDs": ["9780545139700", "9780439784542"] }, { "eventType": "conversion", @@ -84,10 +63,7 @@ "index": "products", "userToken": "user-123456", "timestamp": 1641290601962, - "objectIDs": [ - "9780545139700", - "9780439784542" - ], + "objectIDs": ["9780545139700", "9780439784542"], "queryID": "43b15df305339e827f0ac0bdc5ebcaa7" } ] diff --git a/tests/CTS/clients/search/addApiKey.json b/tests/CTS/clients/search/addApiKey.json index 8477c1d65e..2d5e30d7cb 100644 --- a/tests/CTS/clients/search/addApiKey.json +++ b/tests/CTS/clients/search/addApiKey.json @@ -3,10 +3,7 @@ "method": "addApiKey", "parameters": { "apiKey": { - "acl": [ - "search", - "addObject" - ], + "acl": ["search", "addObject"], "description": "my new api key", "validity": 300, "maxQueriesPerIPPerHour": 100, @@ -17,10 +14,7 @@ "path": "/1/keys", "method": "POST", "data": { - "acl": [ - "search", - "addObject" - ], + "acl": ["search", "addObject"], "description": "my new api key", "validity": 300, "maxQueriesPerIPPerHour": 100, diff --git a/tests/CTS/clients/search/batchRules.json b/tests/CTS/clients/search/batchRules.json index c0e1656bf6..6d7653e0cd 100644 --- a/tests/CTS/clients/search/batchRules.json +++ b/tests/CTS/clients/search/batchRules.json @@ -68,7 +68,11 @@ } } } - ] + ], + "searchParams": { + "forwardToReplicas": "true", + "clearExistingRules": "true" + } } } ] diff --git a/tests/CTS/clients/search/saveRule.json b/tests/CTS/clients/search/saveRule.json index 066c64a739..5dbb735fb9 100644 --- a/tests/CTS/clients/search/saveRule.json +++ b/tests/CTS/clients/search/saveRule.json @@ -36,6 +36,9 @@ "filters": "brand:apple" } } + }, + "searchParams": { + "forwardToReplicas": "true" } } } diff --git a/tests/CTS/clients/search/saveSynonym.json b/tests/CTS/clients/search/saveSynonym.json index d5eb3acb52..266e6e86fb 100644 --- a/tests/CTS/clients/search/saveSynonym.json +++ b/tests/CTS/clients/search/saveSynonym.json @@ -7,11 +7,7 @@ "synonymHit": { "objectID": "id1", "type": "synonym", - "synonyms": [ - "car", - "vehicule", - "auto" - ] + "synonyms": ["car", "vehicule", "auto"] }, "forwardToReplicas": true }, @@ -21,11 +17,10 @@ "data": { "objectID": "id1", "type": "synonym", - "synonyms": [ - "car", - "vehicule", - "auto" - ] + "synonyms": ["car", "vehicule", "auto"] + }, + "searchParams": { + "forwardToReplicas": "true" } } } diff --git a/tests/CTS/clients/search/saveSynonyms.json b/tests/CTS/clients/search/saveSynonyms.json index 006a0c3f1b..9ea6047bc3 100644 --- a/tests/CTS/clients/search/saveSynonyms.json +++ b/tests/CTS/clients/search/saveSynonyms.json @@ -7,21 +7,13 @@ { "objectID": "id1", "type": "synonym", - "synonyms": [ - "car", - "vehicule", - "auto" - ] + "synonyms": ["car", "vehicule", "auto"] }, { "objectID": "id2", "type": "onewaysynonym", "input": "iphone", - "synonyms": [ - "ephone", - "aphone", - "yphone" - ] + "synonyms": ["ephone", "aphone", "yphone"] } ], "forwardToReplicas": true, @@ -34,23 +26,19 @@ { "objectID": "id1", "type": "synonym", - "synonyms": [ - "car", - "vehicule", - "auto" - ] + "synonyms": ["car", "vehicule", "auto"] }, { "objectID": "id2", "type": "onewaysynonym", "input": "iphone", - "synonyms": [ - "ephone", - "aphone", - "yphone" - ] + "synonyms": ["ephone", "aphone", "yphone"] } - ] + ], + "searchParams": { + "forwardToReplicas": "true", + "replaceExistingSynonyms": "false" + } } } ] diff --git a/tests/CTS/clients/search/searchSynonyms.json b/tests/CTS/clients/search/searchSynonyms.json index 7784de2dc5..8357c117e0 100644 --- a/tests/CTS/clients/search/searchSynonyms.json +++ b/tests/CTS/clients/search/searchSynonyms.json @@ -8,7 +8,11 @@ }, "request": { "path": "/1/indexes/indexName/synonyms/search", - "method": "POST" + "method": "POST", + "searchParams": { + "query": "queryString", + "type": "onewaysynonym" + } } } ] diff --git a/tests/CTS/clients/search/updateApiKey.json b/tests/CTS/clients/search/updateApiKey.json index f4d1a65486..9591f4c856 100644 --- a/tests/CTS/clients/search/updateApiKey.json +++ b/tests/CTS/clients/search/updateApiKey.json @@ -4,10 +4,7 @@ "parameters": { "key": "myApiKey", "apiKey": { - "acl": [ - "search", - "addObject" - ], + "acl": ["search", "addObject"], "validity": 300, "maxQueriesPerIPPerHour": 100, "maxHitsPerQuery": 20 @@ -17,10 +14,7 @@ "path": "/1/keys/myApiKey", "method": "PUT", "data": { - "acl": [ - "search", - "addObject" - ], + "acl": ["search", "addObject"], "validity": 300, "maxQueriesPerIPPerHour": 100, "maxHitsPerQuery": 20 diff --git a/tests/CTS/templates/javascript.mustache b/tests/CTS/templates/javascript.mustache index c558de57f6..5b2541fb66 100644 --- a/tests/CTS/templates/javascript.mustache +++ b/tests/CTS/templates/javascript.mustache @@ -13,11 +13,10 @@ describe('{{operationId}}', () => { {{#hasParameters}}{{{parameters}}}{{/hasParameters}} ); - expect(req).toEqual(expect.objectContaining({ - path: '{{{request.path}}}', - method: '{{{request.method}}}', - {{#request.data}}data: {{{.}}},{{/request.data}}{{#request.searchParams}}searchParams: {{{.}}},{{/request.searchParams}} - })) + expect((req as any).path).toEqual('{{{request.path}}}'); + expect((req as any).method).toEqual('{{{request.method}}}'); + expect((req as any).data).toEqual({{#request.data}}{{{request.data}}}{{/request.data}}{{^request.data}}undefined{{/request.data}}); + expect((req as any).searchParams).toEqual({{#request.searchParams}}{{{request.searchParams}}}{{/request.searchParams}}{{^request.searchParams}}undefined{{/request.searchParams}}); }); {{/tests}} diff --git a/tests/output/javascript/analytics.test.ts b/tests/output/javascript/analytics.test.ts index f9d570eb38..699732c9ff 100644 --- a/tests/output/javascript/analytics.test.ts +++ b/tests/output/javascript/analytics.test.ts @@ -11,12 +11,10 @@ describe('getAverageClickPosition', () => { test('get getAverageClickPosition with minimal parameters', async () => { const req = await client.getAverageClickPosition({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/averageClickPosition', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/clicks/averageClickPosition'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getAverageClickPosition with all parameters', async () => { @@ -27,18 +25,15 @@ describe('getAverageClickPosition', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/averageClickPosition', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/clicks/averageClickPosition'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -46,12 +41,10 @@ describe('getClickPositions', () => { test('get getClickPositions with minimal parameters', async () => { const req = await client.getClickPositions({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/positions', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/clicks/positions'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getClickPositions with all parameters', async () => { @@ -62,18 +55,15 @@ describe('getClickPositions', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/positions', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/clicks/positions'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -81,12 +71,10 @@ describe('getClickThroughRate', () => { test('get getClickThroughRate with minimal parameters', async () => { const req = await client.getClickThroughRate({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/clickThroughRate', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/clicks/clickThroughRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getClickThroughRate with all parameters', async () => { @@ -97,18 +85,15 @@ describe('getClickThroughRate', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/clicks/clickThroughRate', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/clicks/clickThroughRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -116,12 +101,10 @@ describe('getConversationRate', () => { test('get getConversationRate with minimal parameters', async () => { const req = await client.getConversationRate({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/conversions/conversionRate', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/conversions/conversionRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getConversationRate with all parameters', async () => { @@ -132,18 +115,15 @@ describe('getConversationRate', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/conversions/conversionRate', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/conversions/conversionRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -151,12 +131,10 @@ describe('getNoClickRate', () => { test('get getNoClickRate with minimal parameters', async () => { const req = await client.getNoClickRate({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noClickRate', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches/noClickRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getNoClickRate with all parameters', async () => { @@ -167,18 +145,15 @@ describe('getNoClickRate', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noClickRate', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches/noClickRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -186,12 +161,10 @@ describe('getNoResultsRate', () => { test('get getNoResultsRate with minimal parameters', async () => { const req = await client.getNoResultsRate({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noResultRate', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches/noResultRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getNoResultsRate with all parameters', async () => { @@ -202,18 +175,15 @@ describe('getNoResultsRate', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noResultRate', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches/noResultRate'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -221,12 +191,10 @@ describe('getSearchesCount', () => { test('get getSearchesCount with minimal parameters', async () => { const req = await client.getSearchesCount({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/count', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches/count'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getSearchesCount with all parameters', async () => { @@ -237,18 +205,15 @@ describe('getSearchesCount', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/count', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches/count'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); @@ -256,12 +221,10 @@ describe('getSearchesNoClicks', () => { test('get getSearchesNoClicks with minimal parameters', async () => { const req = await client.getSearchesNoClicks({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noClicks', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches/noClicks'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getSearchesNoClicks with all parameters', async () => { @@ -274,20 +237,17 @@ describe('getSearchesNoClicks', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noClicks', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches/noClicks'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -295,12 +255,10 @@ describe('getSearchesNoResults', () => { test('get getSearchesNoResults with minimal parameters', async () => { const req = await client.getSearchesNoResults({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noResults', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches/noResults'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getSearchesNoResults with all parameters', async () => { @@ -313,20 +271,17 @@ describe('getSearchesNoResults', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches/noResults', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches/noResults'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -334,12 +289,10 @@ describe('getStatus', () => { test('get getStatus with minimal parameters', async () => { const req = await client.getStatus({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/status', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/status'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); }); @@ -347,12 +300,10 @@ describe('getTopCountries', () => { test('get getTopCountries with minimal parameters', async () => { const req = await client.getTopCountries({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/countries', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/countries'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopCountries with all parameters', async () => { @@ -365,20 +316,17 @@ describe('getTopCountries', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/countries', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/countries'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -386,12 +334,10 @@ describe('getTopFilterAttributes', () => { test('get getTopFilterAttributes with minimal parameters', async () => { const req = await client.getTopFilterAttributes({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/filters'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterAttributes with all parameters', async () => { @@ -405,21 +351,18 @@ describe('getTopFilterAttributes', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters', - method: 'GET', - searchParams: { - index: 'index', - search: 'mySearch', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/filters'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -430,13 +373,10 @@ describe('getTopFilterForAttribute', () => { index: 'index', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute', - method: 'GET', - searchParams: { index: 'index' }, - }) - ); + expect((req as any).path).toEqual('/2/filters/myAttribute'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterForAttribute with minimal parameters and multiple attributes', async () => { @@ -445,13 +385,10 @@ describe('getTopFilterForAttribute', () => { index: 'index', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute1%2CmyAttribute2', - method: 'GET', - searchParams: { index: 'index' }, - }) - ); + expect((req as any).path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopFilterForAttribute with all parameters', async () => { @@ -466,21 +403,18 @@ describe('getTopFilterForAttribute', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute', - method: 'GET', - searchParams: { - index: 'index', - search: 'mySearch', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/filters/myAttribute'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); test('get getTopFilterForAttribute with all parameters and multiple attributes', async () => { @@ -495,21 +429,18 @@ describe('getTopFilterForAttribute', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/myAttribute1%2CmyAttribute2', - method: 'GET', - searchParams: { - index: 'index', - search: 'mySearch', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/filters/myAttribute1%2CmyAttribute2'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -517,13 +448,10 @@ describe('getTopFiltersNoResults', () => { test('get getTopFiltersNoResults with minimal parameters', async () => { const req = await client.getTopFiltersNoResults({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/noResults', - method: 'GET', - searchParams: { index: 'index' }, - }) - ); + expect((req as any).path).toEqual('/2/filters/noResults'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopFiltersNoResults with all parameters', async () => { @@ -537,21 +465,18 @@ describe('getTopFiltersNoResults', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/filters/noResults', - method: 'GET', - searchParams: { - index: 'index', - search: 'mySearch', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/filters/noResults'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + search: 'mySearch', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -559,12 +484,10 @@ describe('getTopHits', () => { test('get getTopHits with minimal parameters', async () => { const req = await client.getTopHits({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/hits', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/hits'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopHits with all parameters', async () => { @@ -579,22 +502,19 @@ describe('getTopHits', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/hits', - method: 'GET', - searchParams: { - index: 'index', - search: 'mySearch', - clickAnalytics: 'true', - startDate: '1999-09-19', - endDate: '2001-01-01', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/hits'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + search: 'mySearch', + clickAnalytics: 'true', + startDate: '1999-09-19', + endDate: '2001-01-01', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -602,12 +522,10 @@ describe('getTopSearches', () => { test('get getTopSearches with minimal parameters', async () => { const req = await client.getTopSearches({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/searches'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getTopSearches with all parameters', async () => { @@ -623,23 +541,20 @@ describe('getTopSearches', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/searches', - method: 'GET', - searchParams: { - index: 'index', - clickAnalytics: 'true', - startDate: '1999-09-19', - endDate: '2001-01-01', - orderBy: 'searchCount', - direction: 'asc', - limit: '21', - offset: '42', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/searches'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + clickAnalytics: 'true', + startDate: '1999-09-19', + endDate: '2001-01-01', + orderBy: 'searchCount', + direction: 'asc', + limit: '21', + offset: '42', + tags: 'tag', + }); }); }); @@ -647,12 +562,10 @@ describe('getUsersCount', () => { test('get getUsersCount with minimal parameters', async () => { const req = await client.getUsersCount({ index: 'index' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/users/count', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/2/users/count'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ index: 'index' }); }); test('get getUsersCount with all parameters', async () => { @@ -663,17 +576,14 @@ describe('getUsersCount', () => { tags: 'tag', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/2/users/count', - method: 'GET', - searchParams: { - index: 'index', - startDate: '1999-09-19', - endDate: '2001-01-01', - tags: 'tag', - }, - }) - ); + expect((req as any).path).toEqual('/2/users/count'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + index: 'index', + startDate: '1999-09-19', + endDate: '2001-01-01', + tags: 'tag', + }); }); }); diff --git a/tests/output/javascript/insights.test.ts b/tests/output/javascript/insights.test.ts index 399adea745..ffd4004e59 100644 --- a/tests/output/javascript/insights.test.ts +++ b/tests/output/javascript/insights.test.ts @@ -43,42 +43,39 @@ describe('pushEvents', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/events', - method: 'POST', - data: { - events: [ - { - eventType: 'click', - eventName: 'Product Clicked', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - queryID: '43b15df305339e827f0ac0bdc5ebcaa7', - positions: [7, 6], - }, - { - eventType: 'view', - eventName: 'Product Detail Page Viewed', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - }, - { - eventType: 'conversion', - eventName: 'Product Purchased', - index: 'products', - userToken: 'user-123456', - timestamp: 1641290601962, - objectIDs: ['9780545139700', '9780439784542'], - queryID: '43b15df305339e827f0ac0bdc5ebcaa7', - }, - ], + expect((req as any).path).toEqual('/1/events'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + events: [ + { + eventType: 'click', + eventName: 'Product Clicked', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + queryID: '43b15df305339e827f0ac0bdc5ebcaa7', + positions: [7, 6], }, - }) - ); + { + eventType: 'view', + eventName: 'Product Detail Page Viewed', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + }, + { + eventType: 'conversion', + eventName: 'Product Purchased', + index: 'products', + userToken: 'user-123456', + timestamp: 1641290601962, + objectIDs: ['9780545139700', '9780439784542'], + queryID: '43b15df305339e827f0ac0bdc5ebcaa7', + }, + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/personalization.test.ts b/tests/output/javascript/personalization.test.ts index 935ef2e5f1..5f0c629665 100644 --- a/tests/output/javascript/personalization.test.ts +++ b/tests/output/javascript/personalization.test.ts @@ -14,12 +14,10 @@ describe('deleteUserProfile', () => { test('delete deleteUserProfile', async () => { const req = await client.deleteUserProfile({ userToken: 'UserToken' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/profiles/UserToken', - method: 'DELETE', - }) - ); + expect((req as any).path).toEqual('/1/profiles/UserToken'); + expect((req as any).method).toEqual('DELETE'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -27,12 +25,10 @@ describe('getPersonalizationStrategy', () => { test('get getPersonalizationStrategy', async () => { const req = await client.getPersonalizationStrategy(); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/strategies/personalization', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/strategies/personalization'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -40,12 +36,10 @@ describe('getUserTokenProfile', () => { test('get getUserTokenProfile', async () => { const req = await client.getUserTokenProfile({ userToken: 'UserToken' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/profiles/personalization/UserToken', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/profiles/personalization/UserToken'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -59,18 +53,13 @@ describe('setPersonalizationStrategy', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/strategies/personalization', - method: 'POST', - data: { - eventScoring: [ - { score: 42, eventName: 'Algolia', eventType: 'Event' }, - ], - facetScoring: [{ score: 42, facetName: 'Event' }], - personalizationImpact: 42, - }, - }) - ); + expect((req as any).path).toEqual('/1/strategies/personalization'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + eventScoring: [{ score: 42, eventName: 'Algolia', eventType: 'Event' }], + facetScoring: [{ score: 42, facetName: 'Event' }], + personalizationImpact: 42, + }); + expect((req as any).searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/recommend.test.ts b/tests/output/javascript/recommend.test.ts index 7d6f2fbc69..e9fda02598 100644 --- a/tests/output/javascript/recommend.test.ts +++ b/tests/output/javascript/recommend.test.ts @@ -22,22 +22,19 @@ describe('getRecommendations', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName', - objectID: 'objectID', - model: 'related-products', - threshold: 42, - }, - ], + expect((req as any).path).toEqual('/1/indexes/*/recommendations'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { + indexName: 'indexName', + objectID: 'objectID', + model: 'related-products', + threshold: 42, }, - }) - ); + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get recommendations with all parameters', async () => { @@ -59,27 +56,21 @@ describe('getRecommendations', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName', - objectID: 'objectID', - model: 'related-products', - threshold: 42, - queryParameters: { query: 'myQuery', facetFilters: ['query'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback'], - }, - }, - ], + expect((req as any).path).toEqual('/1/indexes/*/recommendations'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { + indexName: 'indexName', + objectID: 'objectID', + model: 'related-products', + threshold: 42, + queryParameters: { query: 'myQuery', facetFilters: ['query'] }, + fallbackParameters: { query: 'myQuery', facetFilters: ['fallback'] }, }, - }) - ); + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get multiple recommendations with minimal parameters', async () => { @@ -102,28 +93,25 @@ describe('getRecommendations', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'related-products', - threshold: 21, - }, - { - indexName: 'indexName2', - objectID: 'objectID2', - model: 'related-products', - threshold: 21, - }, - ], + expect((req as any).path).toEqual('/1/indexes/*/recommendations'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'related-products', + threshold: 21, + }, + { + indexName: 'indexName2', + objectID: 'objectID2', + model: 'related-products', + threshold: 21, }, - }) - ); + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get multiple recommendations with all parameters', async () => { @@ -156,38 +144,29 @@ describe('getRecommendations', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'related-products', - threshold: 21, - queryParameters: { query: 'myQuery', facetFilters: ['query1'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback1'], - }, - }, - { - indexName: 'indexName2', - objectID: 'objectID2', - model: 'related-products', - threshold: 21, - queryParameters: { query: 'myQuery', facetFilters: ['query2'] }, - fallbackParameters: { - query: 'myQuery', - facetFilters: ['fallback2'], - }, - }, - ], + expect((req as any).path).toEqual('/1/indexes/*/recommendations'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'related-products', + threshold: 21, + queryParameters: { query: 'myQuery', facetFilters: ['query1'] }, + fallbackParameters: { query: 'myQuery', facetFilters: ['fallback1'] }, + }, + { + indexName: 'indexName2', + objectID: 'objectID2', + model: 'related-products', + threshold: 21, + queryParameters: { query: 'myQuery', facetFilters: ['query2'] }, + fallbackParameters: { query: 'myQuery', facetFilters: ['fallback2'] }, }, - }) - ); + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get frequently bought together recommendations', async () => { @@ -204,21 +183,18 @@ describe('getRecommendations', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/*/recommendations', - method: 'POST', - data: { - requests: [ - { - indexName: 'indexName1', - objectID: 'objectID1', - model: 'bought-together', - threshold: 42, - }, - ], + expect((req as any).path).toEqual('/1/indexes/*/recommendations'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { + indexName: 'indexName1', + objectID: 'objectID1', + model: 'bought-together', + threshold: 42, }, - }) - ); + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); }); diff --git a/tests/output/javascript/search.test.ts b/tests/output/javascript/search.test.ts index 6a975f51c8..c51ed002ac 100644 --- a/tests/output/javascript/search.test.ts +++ b/tests/output/javascript/search.test.ts @@ -17,19 +17,16 @@ describe('addApiKey', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys', - method: 'POST', - data: { - acl: ['search', 'addObject'], - description: 'my new api key', - validity: 300, - maxQueriesPerIPPerHour: 100, - maxHitsPerQuery: 20, - }, - }) - ); + expect((req as any).path).toEqual('/1/keys'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + acl: ['search', 'addObject'], + description: 'my new api key', + validity: 300, + maxQueriesPerIPPerHour: 100, + maxHitsPerQuery: 20, + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -45,18 +42,15 @@ describe('batchDictionaryEntries', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/compounds/batch', - method: 'POST', - data: { - requests: [ - { action: 'addEntry', body: { objectID: '1', language: 'en' } }, - { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, - ], - }, - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/compounds/batch'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + requests: [ + { action: 'addEntry', body: { objectID: '1', language: 'en' } }, + { action: 'deleteEntry', body: { objectID: '2', language: 'fr' } }, + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get batchDictionaryEntries results with all parameters', async () => { @@ -91,39 +85,36 @@ describe('batchDictionaryEntries', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/compounds/batch', - method: 'POST', - data: { - clearExistingDictionaryEntries: false, - requests: [ - { - action: 'addEntry', - body: { - objectID: '1', - language: 'en', - word: 'yo', - words: ['yo', 'algolia'], - decomposition: ['yo', 'algolia'], - state: 'enabled', - }, - }, - { - action: 'deleteEntry', - body: { - objectID: '2', - language: 'fr', - word: 'salut', - words: ['salut', 'algolia'], - decomposition: ['salut', 'algolia'], - state: 'enabled', - }, - }, - ], + expect((req as any).path).toEqual('/1/dictionaries/compounds/batch'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + clearExistingDictionaryEntries: false, + requests: [ + { + action: 'addEntry', + body: { + objectID: '1', + language: 'en', + word: 'yo', + words: ['yo', 'algolia'], + decomposition: ['yo', 'algolia'], + state: 'enabled', + }, }, - }) - ); + { + action: 'deleteEntry', + body: { + objectID: '2', + language: 'fr', + word: 'salut', + words: ['salut', 'algolia'], + decomposition: ['salut', 'algolia'], + state: 'enabled', + }, + }, + ], + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -147,24 +138,24 @@ describe('batchRules', () => { clearExistingRules: true, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/batch', - method: 'POST', - data: [ - { - objectID: 'a-rule-id', - conditions: [{ pattern: 'smartphone', anchoring: 'contains' }], - consequence: { params: { filters: 'category:smartphone' } }, - }, - { - objectID: 'a-second-rule-id', - conditions: [{ pattern: 'apple', anchoring: 'contains' }], - consequence: { params: { filters: 'brand:apple' } }, - }, - ], - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/batch'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual([ + { + objectID: 'a-rule-id', + conditions: [{ pattern: 'smartphone', anchoring: 'contains' }], + consequence: { params: { filters: 'category:smartphone' } }, + }, + { + objectID: 'a-second-rule-id', + conditions: [{ pattern: 'apple', anchoring: 'contains' }], + consequence: { params: { filters: 'brand:apple' } }, + }, + ]); + expect((req as any).searchParams).toEqual({ + forwardToReplicas: 'true', + clearExistingRules: 'true', + }); }); }); @@ -172,12 +163,10 @@ describe('browse', () => { test('get browse results with minimal parameters', async () => { const req = await client.browse({ indexName: 'indexName' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/browse', - method: 'POST', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/browse'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); test('get browse results with all parameters', async () => { @@ -189,13 +178,13 @@ describe('browse', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/browse', - method: 'POST', - data: { params: "query=foo&facetFilters=['bar']", cursor: 'cts' }, - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/browse'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + params: "query=foo&facetFilters=['bar']", + cursor: 'cts', + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -203,12 +192,10 @@ describe('clearAllSynonyms', () => { test('clearAllSynonyms', async () => { const req = await client.clearAllSynonyms({ indexName: 'indexName' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/clear', - method: 'POST', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/clear'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -216,12 +203,10 @@ describe('clearRules', () => { test('clearRules', async () => { const req = await client.clearRules({ indexName: 'indexName' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/clear', - method: 'POST', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/clear'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -229,12 +214,10 @@ describe('deleteApiKey', () => { test('deleteApiKey', async () => { const req = await client.deleteApiKey({ key: 'myTestApiKey' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys/myTestApiKey', - method: 'DELETE', - }) - ); + expect((req as any).path).toEqual('/1/keys/myTestApiKey'); + expect((req as any).method).toEqual('DELETE'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -245,12 +228,10 @@ describe('deleteRule', () => { objectID: 'id1', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/id1', - method: 'DELETE', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); + expect((req as any).method).toEqual('DELETE'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -261,12 +242,10 @@ describe('deleteSynonym', () => { objectID: 'id1', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'DELETE', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect((req as any).method).toEqual('DELETE'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -274,12 +253,10 @@ describe('getApiKey', () => { test('getApiKey', async () => { const req = await client.getApiKey({ key: 'myTestApiKey' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys/myTestApiKey', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/keys/myTestApiKey'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -287,12 +264,10 @@ describe('getDictionaryLanguages', () => { test('get getDictionaryLanguages', async () => { const req = await client.getDictionaryLanguages(); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/*/languages', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/*/languages'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -300,12 +275,10 @@ describe('getDictionarySettings', () => { test('get getDictionarySettings results', async () => { const req = await client.getDictionarySettings(); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/*/settings', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/*/settings'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -316,12 +289,10 @@ describe('getRule', () => { objectID: 'id1', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/id1', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -332,12 +303,10 @@ describe('getSynonym', () => { objectID: 'id1', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -345,12 +314,10 @@ describe('listApiKeys', () => { test('listApiKeys', async () => { const req = await client.listApiKeys(); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys', - method: 'GET', - }) - ); + expect((req as any).path).toEqual('/1/keys'); + expect((req as any).method).toEqual('GET'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -358,12 +325,10 @@ describe('restoreApiKey', () => { test('restoreApiKey', async () => { const req = await client.restoreApiKey({ key: 'myApiKey' }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys/myApiKey/restore', - method: 'POST', - }) - ); + expect((req as any).path).toEqual('/1/keys/myApiKey/restore'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -380,17 +345,14 @@ describe('saveRule', () => { forwardToReplicas: true, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/id1', - method: 'PUT', - data: { - objectID: 'id1', - conditions: [{ pattern: 'apple', anchoring: 'contains' }], - consequence: { params: { filters: 'brand:apple' } }, - }, - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/id1'); + expect((req as any).method).toEqual('PUT'); + expect((req as any).data).toEqual({ + objectID: 'id1', + conditions: [{ pattern: 'apple', anchoring: 'contains' }], + consequence: { params: { filters: 'brand:apple' } }, + }); + expect((req as any).searchParams).toEqual({ forwardToReplicas: 'true' }); }); }); @@ -407,17 +369,14 @@ describe('saveSynonym', () => { forwardToReplicas: true, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/id1', - method: 'PUT', - data: { - objectID: 'id1', - type: 'synonym', - synonyms: ['car', 'vehicule', 'auto'], - }, - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/id1'); + expect((req as any).method).toEqual('PUT'); + expect((req as any).data).toEqual({ + objectID: 'id1', + type: 'synonym', + synonyms: ['car', 'vehicule', 'auto'], + }); + expect((req as any).searchParams).toEqual({ forwardToReplicas: 'true' }); }); }); @@ -442,25 +401,25 @@ describe('saveSynonyms', () => { replaceExistingSynonyms: false, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/batch', - method: 'POST', - data: [ - { - objectID: 'id1', - type: 'synonym', - synonyms: ['car', 'vehicule', 'auto'], - }, - { - objectID: 'id2', - type: 'onewaysynonym', - input: 'iphone', - synonyms: ['ephone', 'aphone', 'yphone'], - }, - ], - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/batch'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual([ + { + objectID: 'id1', + type: 'synonym', + synonyms: ['car', 'vehicule', 'auto'], + }, + { + objectID: 'id2', + type: 'onewaysynonym', + input: 'iphone', + synonyms: ['ephone', 'aphone', 'yphone'], + }, + ]); + expect((req as any).searchParams).toEqual({ + forwardToReplicas: 'true', + replaceExistingSynonyms: 'false', + }); }); }); @@ -471,13 +430,10 @@ describe('search', () => { searchParams: { query: 'myQuery' }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/query', - method: 'POST', - data: { query: 'myQuery' }, - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/query'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ query: 'myQuery' }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -488,13 +444,10 @@ describe('searchDictionaryEntries', () => { searchDictionaryEntries: { query: 'foo' }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/compounds/search', - method: 'POST', - data: { query: 'foo' }, - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/compounds/search'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ query: 'foo' }); + expect((req as any).searchParams).toEqual(undefined); }); test('get searchDictionaryEntries results with all parameters', async () => { @@ -508,13 +461,15 @@ describe('searchDictionaryEntries', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/compounds/search', - method: 'POST', - data: { query: 'foo', page: 4, hitsPerPage: 2, language: 'fr' }, - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/compounds/search'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + query: 'foo', + page: 4, + hitsPerPage: 2, + language: 'fr', + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -525,12 +480,12 @@ describe('searchForFacetValues', () => { facetName: 'facetName', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/facets/facetName/query', - method: 'POST', - }) + expect((req as any).path).toEqual( + '/1/indexes/indexName/facets/facetName/query' ); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual(undefined); }); test('get searchForFacetValues results with all parameters', async () => { @@ -544,17 +499,16 @@ describe('searchForFacetValues', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/facets/facetName/query', - method: 'POST', - data: { - params: "query=foo&facetFilters=['bar']", - facetQuery: 'foo', - maxFacetHits: 42, - }, - }) + expect((req as any).path).toEqual( + '/1/indexes/indexName/facets/facetName/query' ); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ + params: "query=foo&facetFilters=['bar']", + facetQuery: 'foo', + maxFacetHits: 42, + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -565,13 +519,10 @@ describe('searchRules', () => { searchRulesParams: { query: 'something' }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/rules/search', - method: 'POST', - data: { query: 'something' }, - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/rules/search'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual({ query: 'something' }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -583,12 +534,13 @@ describe('searchSynonyms', () => { type: 'onewaysynonym', }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/indexes/indexName/synonyms/search', - method: 'POST', - }) - ); + expect((req as any).path).toEqual('/1/indexes/indexName/synonyms/search'); + expect((req as any).method).toEqual('POST'); + expect((req as any).data).toEqual(undefined); + expect((req as any).searchParams).toEqual({ + query: 'queryString', + type: 'onewaysynonym', + }); }); }); @@ -600,17 +552,12 @@ describe('setDictionarySettings', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/*/settings', - method: 'PUT', - data: { - disableStandardEntries: { - plurals: { fr: false, en: false, ru: true }, - }, - }, - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/*/settings'); + expect((req as any).method).toEqual('PUT'); + expect((req as any).data).toEqual({ + disableStandardEntries: { plurals: { fr: false, en: false, ru: true } }, + }); + expect((req as any).searchParams).toEqual(undefined); }); test('get setDictionarySettings results with all parameters', async () => { @@ -624,19 +571,16 @@ describe('setDictionarySettings', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/dictionaries/*/settings', - method: 'PUT', - data: { - disableStandardEntries: { - plurals: { fr: false, en: false, ru: true }, - stopwords: { fr: false }, - compounds: { ru: true }, - }, - }, - }) - ); + expect((req as any).path).toEqual('/1/dictionaries/*/settings'); + expect((req as any).method).toEqual('PUT'); + expect((req as any).data).toEqual({ + disableStandardEntries: { + plurals: { fr: false, en: false, ru: true }, + stopwords: { fr: false }, + compounds: { ru: true }, + }, + }); + expect((req as any).searchParams).toEqual(undefined); }); }); @@ -652,17 +596,14 @@ describe('updateApiKey', () => { }, }); - expect(req).toEqual( - expect.objectContaining({ - path: '/1/keys/myApiKey', - method: 'PUT', - data: { - acl: ['search', 'addObject'], - validity: 300, - maxQueriesPerIPPerHour: 100, - maxHitsPerQuery: 20, - }, - }) - ); + expect((req as any).path).toEqual('/1/keys/myApiKey'); + expect((req as any).method).toEqual('PUT'); + expect((req as any).data).toEqual({ + acl: ['search', 'addObject'], + validity: 300, + maxQueriesPerIPPerHour: 100, + maxHitsPerQuery: 20, + }); + expect((req as any).searchParams).toEqual(undefined); }); }); From 78fa21d923b63ca551877980840d5757b2394115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 10 Jan 2022 14:39:59 +0100 Subject: [PATCH 9/9] fix typescript syntax --- .../client-analytics/utils/requester/EchoRequester.ts | 6 +++--- .../client-insights/utils/requester/EchoRequester.ts | 6 +++--- .../client-personalization/utils/requester/EchoRequester.ts | 6 +++--- .../client-search/utils/requester/EchoRequester.ts | 6 +++--- .../recommend/utils/requester/EchoRequester.ts | 6 +++--- .../utils/requester/EchoRequester.ts | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-analytics/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) { diff --git a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-insights/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) { diff --git a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-personalization/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) { diff --git a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/client-search/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) { diff --git a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/recommend/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) { diff --git a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts index 6f69e0ea26..ec75b37a41 100644 --- a/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts +++ b/clients/algoliasearch-client-javascript/utils/requester/EchoRequester.ts @@ -6,13 +6,13 @@ type AdditionalContent = { headers: Record; connectTimeout: number; responseTimeout: number; - userAgent: string | undefined; - searchParams: Record | undefined; + userAgent?: string; + searchParams?: Record; }; function searchParamsWithoutUA( params: URLSearchParams -): Record | undefined { +): AdditionalContent['searchParams'] { const searchParams = {}; for (const [k, v] of params) {