Skip to content

Commit

Permalink
fix(algoliasearch): v5 does not default threshold to 0 (#6251)
Browse files Browse the repository at this point in the history
* fix(algoliasearch): v5 does not default threshold to 0

* update snapshots and bump bundlesize
  • Loading branch information
aymeric-giraudet authored Jun 26, 2024
1 parent 4b7875a commit 762e633
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"path": "packages/vue-instantsearch/vue3/umd/index.js",
"maxSize": "67.75 kB"
"maxSize": "68 kB"
},
{
"path": "packages/vue-instantsearch/vue2/cjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ RecommendParameters.prototype = {
return cache[params.$$id] === undefined;
})
.map(function (params) {
var query = Object.assign({}, params, { indexName: indexName });
var query = Object.assign({}, params, {
indexName: indexName,
// @TODO: remove this if it ever gets handled by the API
threshold: params.threshold || 0,
});
delete query.$$id;

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,32 @@ describe('_buildQueries', () => {
"indexName": "indexName",
"model": "bought-together",
"objectID": "objectID1",
"threshold": 0,
},
Object {
"facetName": "brand",
"indexName": "indexName",
"model": "trending-facets",
"threshold": 0,
},
]
`);
});

test('does not override threshold', () => {
var recommendParameters = new RecommendParameters({
params: [{ ...params1, threshold: 10 }],
});

var queries = recommendParameters._buildQueries('indexName', {});
expect(queries).toHaveLength(1);
expect(queries).toMatchInlineSnapshot(`
Array [
Object {
"indexName": "indexName",
"model": "bought-together",
"objectID": "objectID1",
"threshold": 10,
},
]
`);
Expand Down
11 changes: 10 additions & 1 deletion packages/algoliasearch-helper/test/spec/recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ describe('recommend()', () => {
indexName: 'indexName',
model: 'bought-together',
objectID: 'A0E20000000279B',
threshold: 0,
},
{
indexName: 'indexName',
model: 'bought-together',
objectID: 'A0E20000000279C',
threshold: 0,
},
{
indexName: 'indexName',
model: 'trending-facets',
facetName: 'brand',
threshold: 0,
},
{ indexName: 'indexName', model: 'trending-facets', facetName: 'brand' },
]);
});

Expand Down Expand Up @@ -158,6 +165,7 @@ describe('recommend()', () => {
indexName: 'indexName',
model: 'bought-together',
objectID: 'A0E20000000279B',
threshold: 0,
},
]);

Expand All @@ -175,6 +183,7 @@ describe('recommend()', () => {
indexName: 'indexName',
model: 'bought-together',
objectID: 'A0E20000000279C',
threshold: 0,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -433,7 +433,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -580,7 +580,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('network requests', () => {
"highlightPostTag": "__/ais-highlight__",
"highlightPreTag": "__ais-highlight__",
},
"threshold": undefined,
"threshold": 0,
},
]
`);
Expand Down

0 comments on commit 762e633

Please sign in to comment.