From 8cae743c80a5e638d53abd0146d44eb2efc40358 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 25 Jul 2016 15:24:14 -0400 Subject: [PATCH] Handle empty country_a values as well --- middleware/confidenceScore.js | 4 ++-- test/unit/middleware/confidenceScore.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index 71a39bad..2e9eb1c6 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -219,8 +219,8 @@ function checkAddress(text, hit) { res += propMatch(text.number, (hit.address_parts ? hit.address_parts.number : null), false); res += propMatch(text.street, (hit.address_parts ? hit.address_parts.street : null), false); res += propMatch(text.postalcode, (hit.address_parts ? hit.address_parts.zip: null), true); - res += propMatch(text.state, hit.parent.region_a[0], true); - res += propMatch(text.country, hit.parent.country_a[0], true); + res += propMatch(text.state, (hit.parent.region_a ? hit.parent.region_a[0] : null), true); + res += propMatch(text.country, (hit.parent.country_a ? hit.parent.country_a[0] :null), true); res /= checkCount; } diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index e9b80177..7d6ba87d 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/test/unit/middleware/confidenceScore.js @@ -97,9 +97,11 @@ module.exports.tests.confidenceScore = function(test, common) { test('undefined region fields should be handled gracefully', function(t) { var req = { clean: { - text: 'test name1, TX', + text: '123 Main St, City, NM', parsed_text: { - state: 'TX' + number: 123, + street: 'Main St', + state: 'NM' } } }; @@ -121,7 +123,7 @@ module.exports.tests.confidenceScore = function(test, common) { }; confidenceScore(req, res, function() {}); - t.equal(res.data[0].confidence, 0.54, 'score was set'); + t.equal(res.data[0].confidence, 0.28, 'score was set'); t.end(); }); };