Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
refactor(searchForFacetValues): use object vs list of arguments (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored May 6, 2019
1 parent 5acc939 commit 6ec07fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,12 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxF
this._currentNbQueries++;
var self = this;

this.emit('searchForFacetValues', state, facet, query);
this.emit('searchForFacetValues', {
state: state,
facet: facet,
query: query
});

var searchForFacetValuesPromise = clientHasSFFV
? this.client.searchForFacetValues([{indexName: state.index, params: algoliaQuery}])
: this.client.initIndex(state.index).searchForFacetValues(algoliaQuery);
Expand Down
18 changes: 10 additions & 8 deletions test/spec/algoliasearch.helper/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,24 @@ test('searchOnce event should be emitted once when the search is triggered using

test('searchForFacetValues event should be emitted once when the search is triggered using' +
' searchForFacetValues and before the request is sent', function() {
var searchedForFacetValues = jest.fn();
var fakeClient = makeFakeClient();
var helper = algoliaSearchHelper(fakeClient, 'Index', {
disjunctiveFacets: ['city'],
facets: ['tower']
});

var count = 0;
helper.on('searchForFacetValues', searchedForFacetValues);

helper.on('searchForFacetValues', function() {
count++;
});

expect(count).toBe(0);
expect(searchedForFacetValues).toHaveBeenCalledTimes(0);
expect(fakeClient.searchForFacetValues).toHaveBeenCalledTimes(0);

helper.searchForFacetValues();
expect(count).toBe(1);
helper.searchForFacetValues('city', 'NYC');
expect(searchedForFacetValues).toHaveBeenCalledTimes(1);
expect(searchedForFacetValues).toHaveBeenLastCalledWith({
state: helper.state,
facet: 'city',
query: 'NYC'
});
expect(fakeClient.searchForFacetValues).toHaveBeenCalledTimes(1);
});

0 comments on commit 6ec07fe

Please sign in to comment.