Skip to content
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

do not deduplicate different units at the same address #1472

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function isAddressDifferent(item1, item2){
// else both have address info
if( isPropertyDifferent(address1, address2, 'number') ){ return true; }
if( isPropertyDifferent(address1, address2, 'street') ){ return true; }
if( isPropertyDifferent(address1, address2, 'unit') ){ return true; }

// only compare zip if both records have it, otherwise just ignore and assume it's the same
// since by this time we've already compared parent hierarchies
Expand Down Expand Up @@ -213,9 +214,9 @@ function isPropertyDifferent(item1, item2, prop ){
* ...
* 11: locality
* 13: neighbourhood
*
*
* note: Infinity is returned if layer not found in array, this is in
* order to ensure that a high value is returned rather than the
* order to ensure that a high value is returned rather than the
* default '-1' value returned for misses when using findIndex().
*/
function getPlaceTypeRank(item) {
Expand Down
109 changes: 109 additions & 0 deletions test/unit/helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,115 @@ module.exports.tests.dedupe = function(test, common) {
t.false(isDifferent(item1, item2), 'should be the same');
t.end();
});

test('same address should be considered equal', function (t) {
var item1 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};
var item2 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};

t.false(isDifferent(item1, item2), 'should not be different');
t.end();
});

test('same address and unit should be considered equal', function (t) {
var item1 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210',
'unit': 'A'
}
};
var item2 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210',
'unit': 'A'
}
};

t.false(isDifferent(item1, item2), 'should not be different');
t.end();
});

test('same address but differing unit number should be considered different', function (t) {
var item1 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210',
'unit': 'A'
}
};
var item2 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210',
'unit': 'B'
}
};

t.true(isDifferent(item1, item2), 'should be different');
t.end();
});

test('same address but only one has unit number should be considered different', function (t) {
var item1 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210',
'unit': 'A'
}
};
var item2 = {
'name': {
'default': '1 Main St'
},
'address_parts': {
'number': '1',
'street': 'Main Street',
'zip': '90210'
}
};

t.true(isDifferent(item1, item2), 'should be different');
t.end();
});
};

module.exports.all = function (tape, common) {
Expand Down