Skip to content

Commit

Permalink
fix(test): bad handling of no actual inner mechanics of client
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stanislawski committed Feb 7, 2017
1 parent 9838105 commit 622aec5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sources/hits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/sources/popularIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/popularIn_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -24,6 +27,9 @@ describe('popularIn', function() {
}
};
var products = {
as: {
_ua: 'javascript wrong agent',
},
search: function(q, params, cb) {
cb(false, {
facets: {
Expand Down Expand Up @@ -92,13 +98,19 @@ 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: []
});
}
};
var products = {
as: {
_ua: 'javascript wrong agent',
},
search: function(q, params, cb) {
throw new Error('Never reached');
}
Expand Down

0 comments on commit 622aec5

Please sign in to comment.