From 5344806e5e4e3061693a52cfc49b04195d59f95d Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Fri, 22 Mar 2019 10:34:12 +0100 Subject: [PATCH 1/4] fix(ua): Update the User-Agent to use the new format --- src/lib/InstantSearch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/InstantSearch.js b/src/lib/InstantSearch.js index 49c2025ed0..39d2ce212e 100644 --- a/src/lib/InstantSearch.js +++ b/src/lib/InstantSearch.js @@ -77,7 +77,7 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend } if (typeof searchClient.addAlgoliaAgent === 'function') { - searchClient.addAlgoliaAgent(`instantsearch.js ${version}`); + searchClient.addAlgoliaAgent(`instantsearch.js (${version})`); } this.client = searchClient; From b7f2d12f69390ca5665b8a2f72c1d25a94b737ac Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Fri, 22 Mar 2019 11:26:37 +0100 Subject: [PATCH 2/4] fix(ua): Add testing for the UA --- src/lib/__tests__/InstantSearch-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/__tests__/InstantSearch-test.js b/src/lib/__tests__/InstantSearch-test.js index 0a5ad0074e..34c061a321 100644 --- a/src/lib/__tests__/InstantSearch-test.js +++ b/src/lib/__tests__/InstantSearch-test.js @@ -2,6 +2,7 @@ import range from 'lodash/range'; import times from 'lodash/times'; import algoliaSearchHelper from 'algoliasearch-helper'; import InstantSearch from '../InstantSearch'; +import version from '../version' jest.mock('algoliasearch-helper', () => { const module = require.requireActual('algoliasearch-helper'); @@ -151,6 +152,7 @@ describe('InstantSearch lifecycle', () => { results: requests.map(() => ({})), }); }, + addAlgoliaAgent: jest.fn() }; algoliasearch = jest.fn().mockReturnValue(client); @@ -174,6 +176,7 @@ describe('InstantSearch lifecycle', () => { }); afterEach(() => { + client.addAlgoliaAgent.mockClear(); algoliaSearchHelper.mockClear(); }); @@ -182,6 +185,11 @@ describe('InstantSearch lifecycle', () => { expect(algoliasearch).toHaveBeenCalledWith(appId, apiKey); }); + it('calls addAlgoliaAgent', () => { + expect(client.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(client.addAlgoliaAgent).toHaveBeenCalledWith(`instantsearch.js (${version})`); + }); + it('does not call algoliasearchHelper', () => { expect(algoliaSearchHelper).not.toHaveBeenCalled(); }); From 6bb68fb920d0e43d099106d2b5e0e5f1e636e89b Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Fri, 22 Mar 2019 11:37:11 +0100 Subject: [PATCH 3/4] fix(ua): Addressed Francois's comments --- src/lib/__tests__/InstantSearch-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/__tests__/InstantSearch-test.js b/src/lib/__tests__/InstantSearch-test.js index 34c061a321..c170ca456a 100644 --- a/src/lib/__tests__/InstantSearch-test.js +++ b/src/lib/__tests__/InstantSearch-test.js @@ -2,7 +2,7 @@ import range from 'lodash/range'; import times from 'lodash/times'; import algoliaSearchHelper from 'algoliasearch-helper'; import InstantSearch from '../InstantSearch'; -import version from '../version' +import version from '../version'; jest.mock('algoliasearch-helper', () => { const module = require.requireActual('algoliasearch-helper'); @@ -152,7 +152,7 @@ describe('InstantSearch lifecycle', () => { results: requests.map(() => ({})), }); }, - addAlgoliaAgent: jest.fn() + addAlgoliaAgent: jest.fn(), }; algoliasearch = jest.fn().mockReturnValue(client); From 9f2ce92da8bbebd5b7bd42b83cb08e39b91b366c Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Fri, 22 Mar 2019 13:04:15 +0100 Subject: [PATCH 4/4] fix(ua): Run lint:fix --- src/lib/__tests__/InstantSearch-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/__tests__/InstantSearch-test.js b/src/lib/__tests__/InstantSearch-test.js index c170ca456a..11f7695d2c 100644 --- a/src/lib/__tests__/InstantSearch-test.js +++ b/src/lib/__tests__/InstantSearch-test.js @@ -187,7 +187,9 @@ describe('InstantSearch lifecycle', () => { it('calls addAlgoliaAgent', () => { expect(client.addAlgoliaAgent).toHaveBeenCalledTimes(1); - expect(client.addAlgoliaAgent).toHaveBeenCalledWith(`instantsearch.js (${version})`); + expect(client.addAlgoliaAgent).toHaveBeenCalledWith( + `instantsearch.js (${version})` + ); }); it('does not call algoliasearchHelper', () => {