Skip to content

Commit

Permalink
Merge pull request #10 from pelias/require-lat-lon
Browse files Browse the repository at this point in the history
fix(documentStream): Require centroid to import record
  • Loading branch information
orangejulius authored Jan 22, 2019
2 parents 4b8b6f7 + 86743aa commit f428ff8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/streams/documentStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function getStreet(record) {
return getCaseInsensitive('street', record);
}

function getCrossStreet(record) {
return getCaseInsensitive('cross_street', record);
}

function getCaseInsensitive(field, record) {
if (typeof field !== 'string') {
return;
Expand Down Expand Up @@ -66,6 +70,8 @@ function processRecord(record, next_uid, stats) {
const centroid = getCentroid(record);
if (centroid) {
pelias_document.setCentroid( centroid );
} else {
throw 'Invalid centroid'; //centroid is required
}

const street = getStreet(record);
Expand Down
30 changes: 30 additions & 0 deletions test/streams/documentStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ tape( 'documentStream catches records with no street', function(test) {
});
});

tape( 'documentStream catches records with no lat', function(test) {
const input = {
name: 'foo',
LON: 7
};
const stats = { badRecordCount: 0 };
const documentStream = DocumentStream.create('prefix', stats);

test_stream([input], documentStream, function(err, actual) {
test.equal(actual.length, 0, 'no documents should be pushed' );
test.equal(stats.badRecordCount, 1, 'bad record count updated');
test.end();
});
});

tape( 'documentStream catches records with no lon', function(test) {
const input = {
name: 'foo',
LAT: 7
};
const stats = { badRecordCount: 0 };
const documentStream = DocumentStream.create('prefix', stats);

test_stream([input], documentStream, function(err, actual) {
test.equal(actual.length, 0, 'no documents should be pushed' );
test.equal(stats.badRecordCount, 1, 'bad record count updated');
test.end();
});
});

tape( 'documentStream does not set zipcode if zipcode is emptystring', function(test) {
const input = {
NUMBER: '5',
Expand Down

0 comments on commit f428ff8

Please sign in to comment.