New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge staging into production #895

Merged
merged 28 commits into from May 30, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+44 −0
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Prefer openaddresses results with zip code

  • Loading branch information...
kevincennis committed May 15, 2017
commit 512cec994565e9df298e82b7e3f9137d00ecc055
View
@@ -65,6 +65,14 @@ function dedupeResults(req, res, next) {
function isPreferred(existing, candidateReplacement) {
// NOTE: we are assuming here that the layer for both records is the same
var isOA = _.flow(_.property('source'), _.eq.bind(null, 'openaddresses'));
var hasZip = _.bind(_.has, null, _.bind.placeholder, 'address_parts.zip');
// https://github.com/pelias/api/issues/872
if (isOA(existing) && isOA(candidateReplacement)) {
return hasZip(candidateReplacement) && !hasZip(existing);
}
//bind the trumps function to the data items to keep the rest of the function clean
var trumpsFunc = trumps.bind(null, existing, candidateReplacement);
@@ -186,6 +186,42 @@ module.exports.tests.trump = function(test, common) {
t.end();
});
});
test('openaddresses with zip trumps openaddresses without zip', function (t) {
var req = {
clean: {
text: '100 Main St',
size: 100
}
};
var res = {
data: [
{
'name': { 'default': '100 Main St' },
'source': 'openaddresses',
'source_id': '123456',
'layer': 'address',
'address_parts': {}
},
{
'name': { 'default': '100 Main St' },
'source': 'openaddresses',
'source_id': '654321',
'layer': 'address',
'address_parts': {
'zip': '54321'
}
}
]
};
var expectedCount = 1;
dedupe(req, res, function () {
t.equal(res.data.length, expectedCount, 'results have fewer items than before');
t.deepEqual(res.data[0].source_id, '654321', 'openaddresses result with zip won');
t.end();
});
});
};
module.exports.all = function (tape, common) {