Skip to content

Commit

Permalink
feat: Merge pull request #247 from pelias/remove-set-alpha3-support
Browse files Browse the repository at this point in the history
Remove set alpha3 support
  • Loading branch information
trescube authored Jul 10, 2017
2 parents b18e9b2 + 8702c79 commit 6d0f9ab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 91 deletions.
4 changes: 0 additions & 4 deletions src/peliasDocGenerators.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ function assignField(hierarchyElement, wofDoc) {
if (iso3166.is2(hierarchyElement.abbreviation)) {
var iso3 = iso3166.to3(hierarchyElement.abbreviation);

// only set iso3 for country records
if (hierarchyElement.place_type === 'country') {
wofDoc.setAlpha3(iso3);
}
wofDoc.addParent(hierarchyElement.place_type, hierarchyElement.name, hierarchyElement.id.toString(), iso3);

} else {
Expand Down
130 changes: 43 additions & 87 deletions test/peliasDocGeneratorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,49 @@ tape('create', function(test) {

});

test.test('country with abbreviation known as iso3 should use iso3 as abbreviation', function(t) {
var wofRecords = {
1: {
id: 1,
name: 'record name',
abbreviation: 'FR',
lat: 12.121212,
lon: 21.212121,
place_type: 'country'
}
};

// extract all the values from wofRecords to an array since that's how test_stream works
// sure, this could be done with map, but this is clearer
var input = [
wofRecords['1']
];

var expected = [
new Document( 'whosonfirst', 'country', '1')
.setName('default', 'record name')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent( 'country', 'record name', '1', 'FRA')
];

var hierarchies_finder = function() {
return [
[
wofRecords['1']
]
];
};

var docGenerator = peliasDocGenerators.create(hierarchies_finder);

test_stream(input, docGenerator, function(err, actual) {
t.deepEqual(actual, expected, 'should have returned true');
});

t.end();

});

test.test('wofRecord with bounding_box should have bounding box in Document', function(t) {
var wofRecords = {
1: {
Expand Down Expand Up @@ -296,89 +339,6 @@ tape('create', function(test) {

});

test.test('country record without abbreviation should not set alpha3', function(t) {
var wofRecords = {
1: {
id: 1,
name: 'name 1',
lat: 12.121212,
lon: 21.212121,
place_type: 'country'
}
};

// extract all the values from wofRecords to an array since that's how test_stream works
// sure, this could be done with map, but this is clearer
var input = [
wofRecords['1']
];

var expected = [
new Document( 'whosonfirst', 'country', '1')
.setName('default', 'name 1')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'name 1', '1')
];

var hierarchies_finder = function() {
return [
[
wofRecords['1']
]
];
};

var docGenerator = peliasDocGenerators.create(hierarchies_finder);

test_stream(input, docGenerator, function(err, actual) {
t.deepEqual(actual, expected, 'there should be no alpha3');
t.end();
});

});

test.test('country record with unknown abbreviation should not set alpha3', function(t) {
var wofRecords = {
1: {
id: 1,
name: 'name 1',
lat: 12.121212,
lon: 21.212121,
place_type: 'country',
abbreviation: 'this is not a known ISO2 country code'
}
};

// extract all the values from wofRecords to an array since that's how test_stream works
// sure, this could be done with map, but this is clearer
var input = [
wofRecords['1']
];

var expected = [
new Document( 'whosonfirst', 'country', '1')
.setName('default', 'name 1')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'name 1', '1')
];

var hierarchies_finder = function() {
return [
[
wofRecords['1']
]
];
};

var docGenerator = peliasDocGenerators.create(hierarchies_finder);

test_stream(input, docGenerator, function(err, actual) {
t.deepEqual(actual, expected, 'there should be no alpha3');
t.end();
});

});

test.test('undefined population should not set population in doc', function(t) {
var wofRecords = {
1: {
Expand All @@ -403,7 +363,6 @@ tape('create', function(test) {
.setName('default', 'United States')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'United States', '1', 'USA')
.setAlpha3( 'USA' )
];

var hierarchies_finder = function() {
Expand Down Expand Up @@ -447,7 +406,6 @@ tape('create', function(test) {
.setName('default', 'United States')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'United States', '1', 'USA')
.setAlpha3( 'USA' )
.setPopulation(98765)
];

Expand Down Expand Up @@ -492,7 +450,6 @@ tape('create', function(test) {
.setName('default', 'United States')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'United States', '1', 'USA')
.setAlpha3( 'USA' )
];

var hierarchies_finder = function() {
Expand Down Expand Up @@ -536,7 +493,6 @@ tape('create', function(test) {
.setName('default', 'United States')
.setCentroid({ lat: 12.121212, lon: 21.212121 })
.addParent('country', 'United States', '1', 'USA')
.setAlpha3( 'USA' )
.setPopularity(87654)
];

Expand Down

0 comments on commit 6d0f9ab

Please sign in to comment.