From cb90f9a4f863e8413b0040366d5debd42c10667e Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Thu, 21 Mar 2019 13:31:05 +0100 Subject: [PATCH 1/3] fix(ua): change the User-Agent to use the new specs lib (version) --- .../src/core/__tests__/createInstantSearch.js | 2 +- .../react-instantsearch-core/src/core/createInstantSearch.js | 4 ++-- .../src/core/__tests__/createInstantSearchServer.js | 2 +- .../src/core/createInstantSearchServer.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js b/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js index 3126c9e4c0..e1e1302eb7 100644 --- a/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js +++ b/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js @@ -46,7 +46,7 @@ describe('createInstantSearch', () => { expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith( - `react-instantsearch ${version}` + `react-instantsearch (${version})` ); }); diff --git a/packages/react-instantsearch-core/src/core/createInstantSearch.js b/packages/react-instantsearch-core/src/core/createInstantSearch.js index 00fcc85315..fa27291caa 100644 --- a/packages/react-instantsearch-core/src/core/createInstantSearch.js +++ b/packages/react-instantsearch-core/src/core/createInstantSearch.js @@ -69,7 +69,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) { }); if (typeof this.client.addAlgoliaAgent === 'function') { - this.client.addAlgoliaAgent(`react-instantsearch ${version}`); + this.client.addAlgoliaAgent(`react-instantsearch (${version})`); } } @@ -88,7 +88,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) { } if (typeof this.client.addAlgoliaAgent === 'function') { - this.client.addAlgoliaAgent(`react-instantsearch ${version}`); + this.client.addAlgoliaAgent(`react-instantsearch (${version})`); } } diff --git a/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js b/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js index 5432cbcee9..4acf9adb8c 100644 --- a/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js +++ b/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js @@ -80,7 +80,7 @@ describe('createInstantSearchServer', () => { expect(createSearchClientMock).toHaveBeenCalledWith('appId', 'apiKey'); expect(searchClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith( - `react-instantsearch ${version}` + `react-instantsearch (${version})` ); }); diff --git a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js index 9d2fd20300..ced1eccda9 100644 --- a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js +++ b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js @@ -165,7 +165,7 @@ const createInstantSearchServer = algoliasearch => { algoliasearch(this.props.appId, this.props.apiKey); if (typeof client.addAlgoliaAgent === 'function') { - client.addAlgoliaAgent(`react-instantsearch ${version}`); + client.addAlgoliaAgent(`react-instantsearch (${version})`); } indexName = this.props.indexName; From 40c8aef91470bdbd30d242cadf077b2d02661b86 Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Thu, 21 Mar 2019 13:48:33 +0100 Subject: [PATCH 2/3] fix(ua): Add the react framework version to UA --- .../src/core/__tests__/createInstantSearch.js | 17 ++++++++++------- .../src/core/createInstantSearch.js | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js b/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js index e1e1302eb7..ba3ad28923 100644 --- a/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js +++ b/packages/react-instantsearch-core/src/core/__tests__/createInstantSearch.js @@ -44,10 +44,13 @@ describe('createInstantSearch', () => { _useRequestCache: true, }); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith( `react-instantsearch (${version})` ); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith( + `react (${React.version})` + ); }); it('throws if algoliaClient is given with searchClient', () => { @@ -108,7 +111,7 @@ describe('createInstantSearch', () => { ); expect(algoliaClientFactory).toHaveBeenCalledTimes(0); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); expect(wrapper.props().searchClient).toBe(algoliaClient); }); @@ -118,7 +121,7 @@ describe('createInstantSearch', () => { ); expect(algoliaClientFactory).toHaveBeenCalledTimes(0); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); expect(wrapper.props().algoliaClient).toBe(algoliaClient); }); @@ -147,14 +150,14 @@ describe('createInstantSearch', () => { ); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); wrapper.setProps({ algoliaClient: newAlgoliaClient, }); expect(wrapper.props().algoliaClient).toBe(newAlgoliaClient); - expect(newAlgoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(newAlgoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); }); it('updates the searchClient when provided searchClient is passed down', () => { @@ -166,14 +169,14 @@ describe('createInstantSearch', () => { ); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); wrapper.setProps({ searchClient: newAlgoliaClient, }); expect(wrapper.props().searchClient).toBe(newAlgoliaClient); - expect(newAlgoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(newAlgoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); }); it('does not throw when algoliaClient gets updated and does not have a `addAlgoliaAgent()` method', () => { diff --git a/packages/react-instantsearch-core/src/core/createInstantSearch.js b/packages/react-instantsearch-core/src/core/createInstantSearch.js index fa27291caa..b0769c0056 100644 --- a/packages/react-instantsearch-core/src/core/createInstantSearch.js +++ b/packages/react-instantsearch-core/src/core/createInstantSearch.js @@ -69,6 +69,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) { }); if (typeof this.client.addAlgoliaAgent === 'function') { + this.client.addAlgoliaAgent(`react (${React.version})`); this.client.addAlgoliaAgent(`react-instantsearch (${version})`); } } @@ -88,6 +89,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) { } if (typeof this.client.addAlgoliaAgent === 'function') { + this.client.addAlgoliaAgent(`react (${React.version})`); this.client.addAlgoliaAgent(`react-instantsearch (${version})`); } } From 19afb62bc57b26accba1c0dea8b5a43b6cde47e2 Mon Sep 17 00:00:00 2001 From: Robert Mogos Date: Thu, 21 Mar 2019 14:30:03 +0100 Subject: [PATCH 3/3] fix(ua): Add the react framework version to UA and update the UT --- .../src/core/__tests__/createInstantSearchServer.js | 13 +++++++++++-- .../src/core/createInstantSearchServer.js | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js b/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js index 4acf9adb8c..9271962f56 100644 --- a/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js +++ b/packages/react-instantsearch-dom/src/core/__tests__/createInstantSearchServer.js @@ -78,7 +78,10 @@ describe('createInstantSearchServer', () => { expect(createSearchClientMock).toHaveBeenCalledTimes(1); expect(createSearchClientMock).toHaveBeenCalledWith('appId', 'apiKey'); - expect(searchClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(searchClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); + expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith( + `react (${React.version})` + ); expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith( `react-instantsearch (${version})` ); @@ -114,7 +117,13 @@ describe('createInstantSearchServer', () => { const wrapper = shallow(); - expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith( + `react (${React.version})` + ); + expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith( + `react-instantsearch (${version})` + ); expect(wrapper.props().algoliaClient).toBe(algoliaClient); }); diff --git a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js index ced1eccda9..47fb81a573 100644 --- a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js +++ b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js @@ -165,6 +165,7 @@ const createInstantSearchServer = algoliasearch => { algoliasearch(this.props.appId, this.props.apiKey); if (typeof client.addAlgoliaAgent === 'function') { + client.addAlgoliaAgent(`react (${React.version})`); client.addAlgoliaAgent(`react-instantsearch (${version})`); }