Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(ua): change the User-Agent to use the new specs lib (version) (#2209
Browse files Browse the repository at this point in the history
)

* fix(ua): change the User-Agent to use the new specs lib (version)

* fix(ua): Add the react framework version to UA and update the UT
  • Loading branch information
robertmogos authored and samouss committed Mar 22, 2019
1 parent e5f848f commit 642ba0b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ describe('createInstantSearch', () => {
_useRequestCache: true,
});

expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(1);
expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledTimes(2);
expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith(
`react-instantsearch ${version}`
`react-instantsearch (${version})`
);
expect(algoliaClient.addAlgoliaAgent).toHaveBeenCalledWith(
`react (${React.version})`
);
});

Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand Down Expand Up @@ -147,14 +150,14 @@ describe('createInstantSearch', () => {
<CustomInstantSearch algoliaClient={algoliaClient} indexName="name" />
);

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', () => {
Expand All @@ -166,14 +169,14 @@ describe('createInstantSearch', () => {
<CustomInstantSearch searchClient={algoliaClient} indexName="name" />
);

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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export default function createInstantSearch(defaultAlgoliaClient, root) {
});

if (typeof this.client.addAlgoliaAgent === 'function') {
this.client.addAlgoliaAgent(`react-instantsearch ${version}`);
this.client.addAlgoliaAgent(`react (${React.version})`);
this.client.addAlgoliaAgent(`react-instantsearch (${version})`);
}
}

Expand All @@ -88,7 +89,8 @@ export default function createInstantSearch(defaultAlgoliaClient, root) {
}

if (typeof this.client.addAlgoliaAgent === 'function') {
this.client.addAlgoliaAgent(`react-instantsearch ${version}`);
this.client.addAlgoliaAgent(`react (${React.version})`);
this.client.addAlgoliaAgent(`react-instantsearch (${version})`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ 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-instantsearch ${version}`
`react (${React.version})`
);
expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith(
`react-instantsearch (${version})`
);
});

Expand Down Expand Up @@ -114,7 +117,13 @@ describe('createInstantSearchServer', () => {

const wrapper = shallow(<InstantSearch {...props} />);

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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ const createInstantSearchServer = algoliasearch => {
algoliasearch(this.props.appId, this.props.apiKey);

if (typeof client.addAlgoliaAgent === 'function') {
client.addAlgoliaAgent(`react-instantsearch ${version}`);
client.addAlgoliaAgent(`react (${React.version})`);
client.addAlgoliaAgent(`react-instantsearch (${version})`);
}

indexName = this.props.indexName;
Expand Down

0 comments on commit 642ba0b

Please sign in to comment.