From d0e2c1473846b34f66c8cd96472ca95895f57cae Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 7 Dec 2015 12:33:33 -0500 Subject: [PATCH 1/2] Check that hit.address exists Fixes #379 --- middleware/confidenceScore.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index b100b973..0eae0f8d 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -100,7 +100,8 @@ function checkForDealBreakers(req, hit) { 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 + ')'); return true; } From 5a84afa539c9ea77d3cf713f3d63e12763d475ca Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 7 Dec 2015 17:13:44 -0500 Subject: [PATCH 2/2] Add test of parsing hit with no address object In #369 I said I wouldn't bother testing for the case of the address object on hit being absent, but it turns out that does sometimes happen. --- test/unit/middleware/confidenceScore.js | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index c32a37d4..69821293 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/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) { var req = {