File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ function isLayerDifferent(item1, item2){
4040 return false ;
4141}
4242
43+ function isUsState ( item ) {
44+ if ( ! _ . isArray ( item . parent . country_a ) ) { return false ; }
45+ return item . parent . country_a [ 0 ] === 'USA' && item . layer === 'region' ;
46+ }
47+
4348/**
4449 * Compare the parent properties if they exist.
4550 * Returns false if the objects are the same, else true.
@@ -59,6 +64,13 @@ function isParentHierarchyDifferent(item1, item2){
5964 // note: this really shouldn't happen as at least one parent should exist
6065 if ( ! isPojo1 || ! isPojo2 ) { return false ; }
6166
67+ // US states should not be deduplicated, except against other US states
68+ if ( isUsState ( item1 ) || isUsState ( item2 ) ) {
69+ if ( ! isUsState ( item1 ) || ! isUsState ( item2 ) ) {
70+ return true ;
71+ }
72+ }
73+
6274 // special handling of postal codes, which we consider to be strictly
6375 // unique within a single country/dependency regardless of the rest of
6476 // the hierarchy (ie. we ignore other parent properties)
Original file line number Diff line number Diff line change @@ -82,6 +82,46 @@ module.exports.tests.dedupe = function(test, common) {
8282 t . end ( ) ;
8383 } ) ;
8484
85+ test ( 'isParentHierarchyDifferent: do not dedupe US states' , function ( t ) {
86+ var item1 = {
87+ layer : 'region' ,
88+ parent : {
89+ region_id : '123' ,
90+ country_a : [ 'USA' ]
91+ }
92+ } ;
93+ var item2 = {
94+ layer : 'locality' ,
95+ parent : {
96+ region_id : '123' ,
97+ locality_id : '456'
98+ }
99+ } ;
100+
101+ t . true ( isDifferent ( item1 , item2 ) , 'should be considered different' ) ;
102+ t . end ( ) ;
103+ } ) ;
104+
105+ test ( 'isParentHierarchyDifferent: do not dedupe US states, except against each other' , function ( t ) {
106+ var item1 = {
107+ layer : 'region' ,
108+ parent : {
109+ region_id : '123' ,
110+ country_a : [ 'USA' ]
111+ }
112+ } ;
113+ var item2 = {
114+ layer : 'region' ,
115+ parent : {
116+ region_id : '123' ,
117+ country_a : [ 'USA' ]
118+ }
119+ } ;
120+
121+ t . false ( isDifferent ( item1 , item2 ) , 'should not be considered different' ) ;
122+ t . end ( ) ;
123+ } ) ;
124+
85125 test ( 'isParentHierarchyDifferent: do compare parentage at higher levels than the highest item placetypes' , function ( t ) {
86126 var item1 = {
87127 'layer' : 'country' ,
You can’t perform that action at this time.
0 commit comments