Browse Source

Handle case where record has no region_ a field

pull/599/head
Julian Simioni 8 years ago
parent
commit
f18e278e51
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 2
      middleware/confidenceScore.js
  2. 30
      test/unit/middleware/confidenceScore.js

2
middleware/confidenceScore.js

@ -93,7 +93,7 @@ function checkForDealBreakers(req, hit) {
return false;
}
if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a[0]) {
if (check.assigned(req.clean.parsed_text.state) && hit.parent.region_a && req.clean.parsed_text.state !== hit.parent.region_a[0]) {
logger.debug('[confidence][deal-breaker]: state !== region_a');
return true;
}

30
test/unit/middleware/confidenceScore.js

@ -94,6 +94,36 @@ module.exports.tests.confidenceScore = function(test, common) {
t.end();
});
test('undefined region fields should be handled gracefully', function(t) {
var req = {
clean: {
text: 'test name1, TX',
parsed_text: {
state: 'TX'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: ['country1'],
region: undefined,
region_a: undefined,
county: ['city1']
}
}],
meta: {scores: [10]}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.54, 'score was set');
t.end();
});
};
module.exports.all = function (tape, common) {

Loading…
Cancel
Save