diff --git a/src/sources/hits.js b/src/sources/hits.js index 23586a3fd..553c5b07a 100644 --- a/src/sources/hits.js +++ b/src/sources/hits.js @@ -6,7 +6,7 @@ var parseAlgoliaClientVersion = require('../common/parseAlgoliaClientVersion.js' module.exports = function search(index, params) { var algoliaVersion = parseAlgoliaClientVersion(index.as._ua); - if (algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { + if (algoliaVersion && algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { params.additionalUA = 'autocomplete.js ' + version; } return sourceFn; diff --git a/src/sources/popularIn.js b/src/sources/popularIn.js index 239d88d53..e720ca669 100644 --- a/src/sources/popularIn.js +++ b/src/sources/popularIn.js @@ -6,7 +6,7 @@ var parseAlgoliaClientVersion = require('../common/parseAlgoliaClientVersion.js' module.exports = function popularIn(index, params, details, options) { var algoliaVersion = parseAlgoliaClientVersion(index.as._ua); - if (algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { + if (algoliaVersion && algoliaVersion[0] >= 3 && algoliaVersion[1] > 20) { params.additionalUA = 'autocomplete.js ' + version; } if (!details.source) { @@ -37,6 +37,11 @@ module.exports = function popularIn(index, params, details, options) { delete detailsParams.source; // not a query parameter delete detailsParams.index; // not a query parameter + var detailsAlgoliaVersion = parseAlgoliaClientVersion(detailsIndex.as._ua); + if (detailsAlgoliaVersion && detailsAlgoliaVersion[0] >= 3 && detailsAlgoliaVersion[1] > 20) { + params.additionalUA = 'autocomplete.js ' + version; + } + detailsIndex.search(source(first), detailsParams, function(error2, content2) { if (error2) { _.error(error2.message); diff --git a/test/unit/popularIn_spec.js b/test/unit/popularIn_spec.js index c003d89dc..e3e972527 100644 --- a/test/unit/popularIn_spec.js +++ b/test/unit/popularIn_spec.js @@ -13,6 +13,9 @@ describe('popularIn', function() { function build(options) { var queries = { + as: { + _ua: 'javascript wrong agent', + }, search: function(q, params, cb) { cb(false, { hits: [ @@ -24,6 +27,9 @@ describe('popularIn', function() { } }; var products = { + as: { + _ua: 'javascript wrong agent', + }, search: function(q, params, cb) { cb(false, { facets: { @@ -92,6 +98,9 @@ describe('popularIn', function() { it('should not include the all department entry when no results', function() { var queries = { + as: { + _ua: 'Algolia for vanilla JavaScript 4.3.6' + }, search: function(q, params, cb) { cb(false, { hits: [] @@ -99,6 +108,9 @@ describe('popularIn', function() { } }; var products = { + as: { + _ua: 'javascript wrong agent', + }, search: function(q, params, cb) { throw new Error('Never reached'); }