Browse Source

Merge pull request #380 from pelias/fix_confidence_score_testing

Check that hit.address exists
pull/383/head
Julian Simioni 9 years ago
parent
commit
ff4562edb6
  1. 3
      middleware/confidenceScore.js
  2. 33
      test/unit/middleware/confidenceScore.js

3
middleware/confidenceScore.js

@ -100,7 +100,8 @@ function checkForDealBreakers(req, hit) {
return true; return true;
} }
if (check.assigned(req.clean.parsed_text.postalcode) && req.clean.parsed_text.postalcode !== hit.address.zip) { if (check.assigned(req.clean.parsed_text.postalcode) && check.assigned(hit.address) &&
req.clean.parsed_text.postalcode !== hit.address.zip) {
logger.debug('[confidence][deal-breaker]: postalcode !== zip (' + req.clean.parsed_text.postalcode + ' !== ' + hit.address.zip + ')'); logger.debug('[confidence][deal-breaker]: postalcode !== zip (' + req.clean.parsed_text.postalcode + ' !== ' + hit.address.zip + ')');
return true; return true;
} }

33
test/unit/middleware/confidenceScore.js

@ -41,6 +41,39 @@ module.exports.tests.confidenceScore = function(test, common) {
}); });
test('hit without address should not error', function(t) {
var req = {
clean: {
text: 'test name3',
parsed_text: {
postalcode: 12345
}
}
};
var res = {
data: [{
name: {
default: 'foo'
}
}],
meta: {
scores: [10]
}
};
try {
confidenceScore(req, res, function() {});
t.pass('no exception');
}
catch (e) {
t.fail('an exception should not have been thrown with no address');
console.log(e.stack);
}
finally {
t.end();
}
});
test('res.results without parsed_text should not throw exception', function(t) { test('res.results without parsed_text should not throw exception', function(t) {
var req = { var req = {

Loading…
Cancel
Save