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

Commit

Permalink
test(sffv): no longer test impossible responses (#686)
Browse files Browse the repository at this point in the history
* test(sffv): no longer test impossible responses

Since the engine will always respond with `facetHits` on searchForFacetValues, we can assume this will always be defined.

follow-up to @samouss' comments on #674

* chore: turn into factory 🏭

* feedback
  • Loading branch information
Haroenv committed May 7, 2019
1 parent c689299 commit b59e278
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
7 changes: 1 addition & 6 deletions src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,10 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function(facet, query, maxF

content = Array.isArray(content) ? content[0] : content;

content.facetHits = Array.isArray(content.facetHits)
? content.facetHits
: [];

content.facetHits = content.facetHits.map(function(f) {
content.facetHits.forEach(function(f) {
f.isRefined = isDisjunctive
? state.isDisjunctiveFacetRefined(facet, f.value)
: state.isFacetRefined(facet, f.value);
return f;
});

return content;
Expand Down
9 changes: 7 additions & 2 deletions test/spec/algoliasearch.helper/pendingSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ test('When searchOnce with promises, hasPendingRequests is true', function(done)
});

test('When searchForFacetValues, hasPendingRequests is true', function(done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var client = algoliaSearch('dsf', 'dsfdf');

var triggerCb;
client.searchForFacetValues = function() {
return new Promise(function(resolve) {
triggerCb = function() { resolve([testData.response]); };
triggerCb = function() {
resolve([{
exhaustiveFacetsCount: true,
facetHits: [],
processingTimeMS: 3
}]);
};
});
};

Expand Down
34 changes: 17 additions & 17 deletions test/spec/algoliasearch.helper/searchForFacetValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

var algoliasearchHelper = require('../../../index');

function makeFakeSearchForFacetValuesResponse() {
return {
exhaustiveFacetsCount: true,
facetHits: [],
processingTimeMS: 3
};
}

test('searchForFacetValues calls the client method over the index method', function() {
var clientSearchForFacetValues = jest.fn(function() {
return Promise.resolve([{}]);
return Promise.resolve([makeFakeSearchForFacetValuesResponse()]);
});

var indexSearchForFacetValues = jest.fn(function() {
return Promise.resolve({});
return Promise.resolve(makeFakeSearchForFacetValuesResponse());
});

var fakeClient = {
Expand All @@ -30,7 +38,7 @@ test('searchForFacetValues calls the client method over the index method', funct

test('searchForFacetValues calls the index method if no client method', function() {
var indexSearchForFacetValues = jest.fn(function() {
return Promise.resolve({});
return Promise.resolve(makeFakeSearchForFacetValuesResponse());
});

var fakeClient = {
Expand All @@ -53,11 +61,7 @@ test('searchForFacetValues resolve with the correct response from client', funct
addAlgoliaAgent: function() {},
searchForFacetValues: function() {
return Promise.resolve([
{
exhaustiveFacetsCount: true,
facetHits: [],
processingTimeMS: 3
}
makeFakeSearchForFacetValuesResponse()
]);
}
};
Expand All @@ -77,11 +81,7 @@ test('searchForFacetValues resolve with the correct response from initIndex', fu
initIndex: function() {
return {
searchForFacetValues: function() {
return Promise.resolve({
exhaustiveFacetsCount: true,
facetHits: [],
processingTimeMS: 3
});
return Promise.resolve(makeFakeSearchForFacetValuesResponse());
}
};
}
Expand All @@ -98,7 +98,7 @@ test('searchForFacetValues resolve with the correct response from initIndex', fu

test('index.searchForFacetValues should search for facetValues with the current state', function() {
var indexSearchForFacetValues = jest.fn(function() {
return Promise.resolve({});
return Promise.resolve(makeFakeSearchForFacetValuesResponse());
});

var fakeClient = {
Expand Down Expand Up @@ -128,7 +128,7 @@ test('index.searchForFacetValues should search for facetValues with the current

test('index.searchForFacetValues can override the current search state', function() {
var indexSearchForFacetValues = jest.fn(function() {
return Promise.resolve({});
return Promise.resolve(makeFakeSearchForFacetValuesResponse());
});

var fakeClient = {
Expand Down Expand Up @@ -161,7 +161,7 @@ test('index.searchForFacetValues can override the current search state', functio

test('client.searchForFacetValues should search for facetValues with the current state', function() {
var clientSearchForFacetValues = jest.fn(function() {
return Promise.resolve([{}]);
return Promise.resolve([makeFakeSearchForFacetValuesResponse()]);
});

var fakeClient = {
Expand All @@ -188,7 +188,7 @@ test('client.searchForFacetValues should search for facetValues with the current

test('client.searchForFacetValues can override the current search state', function() {
var clientSearchForFacetValues = jest.fn(function() {
return Promise.resolve([{}]);
return Promise.resolve([makeFakeSearchForFacetValuesResponse()]);
});

var fakeClient = {
Expand Down

0 comments on commit b59e278

Please sign in to comment.