This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
feat(answers): add findAnswers
#804
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
08b0ecd
feat(answers): add searchForAnswers WIP
eunjae-lee c835ae1
update parameters
eunjae-lee 54509fe
add a FIXME comment
eunjae-lee e1c783f
accept options as an object
eunjae-lee de96b4a
add jsdoc and typings
eunjae-lee 4f3f07f
add test cases
eunjae-lee ca88e3b
fix lint error
eunjae-lee da8af13
better types
eunjae-lee 2433fb1
clean up error message
eunjae-lee 7bec235
Update src/algoliasearch.helper.js
5aa1206
remove jsdoc
eunjae-lee 761e2fd
fix type
Haroenv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
var algoliasearchHelper = require('../../../index'); | ||
|
||
function makeFakeFindAnswersResponse() { | ||
return { | ||
exhaustiveFacetsCount: true, | ||
facetHits: [], | ||
processingTimeMS: 3 | ||
}; | ||
} | ||
|
||
function setupTestEnvironment(helperOptions) { | ||
var findAnswers = jest.fn(function() { | ||
return Promise.resolve([makeFakeFindAnswersResponse()]); | ||
}); | ||
|
||
var fakeClient = { | ||
initIndex: function() { | ||
return { | ||
findAnswers: findAnswers | ||
}; | ||
} | ||
}; | ||
|
||
var helper = algoliasearchHelper(fakeClient, 'index', helperOptions); | ||
|
||
return { | ||
findAnswers: findAnswers, | ||
helper: helper | ||
}; | ||
} | ||
|
||
test('returns an empty array with no derived helper', function() { | ||
var env = setupTestEnvironment(); | ||
var helper = env.helper; | ||
var findAnswers = env.findAnswers; | ||
|
||
return helper | ||
.findAnswers({ | ||
attributesForPrediction: ['description'], | ||
queryLanguages: ['en'], | ||
nbHits: 1 | ||
}) | ||
.then(function(result) { | ||
expect(findAnswers).toHaveBeenCalledTimes(0); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
|
||
test('returns a correct result with one derivation', function() { | ||
var env = setupTestEnvironment(); | ||
var helper = env.helper; | ||
var findAnswers = env.findAnswers; | ||
|
||
helper.derive(function(state) { | ||
return state; | ||
}); | ||
|
||
return helper | ||
.findAnswers({ | ||
attributesForPrediction: ['description'], | ||
queryLanguages: ['en'], | ||
nbHits: 1 | ||
}) | ||
.then(function(result) { | ||
expect(findAnswers).toHaveBeenCalledTimes(1); | ||
expect(result).toEqual([makeFakeFindAnswersResponse()]); | ||
}); | ||
}); | ||
|
||
test('runs findAnswers with facets', function() { | ||
var env = setupTestEnvironment({facets: ['facet1']}); | ||
var helper = env.helper; | ||
var findAnswers = env.findAnswers; | ||
helper.addFacetRefinement('facet1', 'facetValue'); | ||
|
||
helper.derive(function(state) { | ||
return state; | ||
}); | ||
|
||
helper.setQuery('hello'); | ||
|
||
return helper | ||
.findAnswers({ | ||
attributesForPrediction: ['description'], | ||
queryLanguages: ['en'], | ||
nbHits: 1 | ||
}) | ||
.then(function() { | ||
expect(findAnswers).toHaveBeenCalledTimes(1); | ||
expect(findAnswers).toHaveBeenCalledWith('hello', ['en'], { | ||
attributesForPrediction: ['description'], | ||
nbHits: 1, | ||
params: { | ||
facetFilters: ['facet1:facetValue'], | ||
facets: ['facet1'], | ||
query: 'hello', | ||
tagFilters: '' | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the doc,
snippetEllipsisText
is throwing an error. I've reported it to the team, but for now let's have it here.