Skip to content

Commit

Permalink
fix(ua): Update the User-Agent to use the new format (#3616)
Browse files Browse the repository at this point in the history
* fix(ua): Update the User-Agent to use the new format
  • Loading branch information
robertmogos authored Mar 22, 2019
1 parent 5f41fc6 commit ab84c57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -151,6 +152,7 @@ describe('InstantSearch lifecycle', () => {
results: requests.map(() => ({})),
});
},
addAlgoliaAgent: jest.fn(),
};

algoliasearch = jest.fn().mockReturnValue(client);
Expand All @@ -174,6 +176,7 @@ describe('InstantSearch lifecycle', () => {
});

afterEach(() => {
client.addAlgoliaAgent.mockClear();
algoliaSearchHelper.mockClear();
});

Expand All @@ -182,6 +185,13 @@ 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();
});
Expand Down

0 comments on commit ab84c57

Please sign in to comment.