-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from pelias/exclude-zero-house-numbers
filter out '0' house numbers in US/CA
- Loading branch information
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var filter = require('through2-filter'); | ||
var _ = require('lodash'); | ||
|
||
function isUSorCA(record) { | ||
return _.isEqual(record.parent.country_a, ['USA']) || | ||
_.isEqual(record.parent.country_a, ['CAN']); | ||
} | ||
|
||
module.exports.create = function create() { | ||
return filter.obj(function(record) { | ||
if (record.address_parts.number === '0' && isUSorCA(record)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
var tape = require('tape'); | ||
var event_stream = require('event-stream'); | ||
|
||
var isUSorCAHouseNumberZero = require('../../lib/streams/isUSorCAHouseNumberZero'); | ||
|
||
function test_stream(input, testedStream, callback) { | ||
var input_stream = event_stream.readArray(input); | ||
var destination_stream = event_stream.writeArray(callback); | ||
|
||
input_stream.pipe(testedStream).pipe(destination_stream); | ||
} | ||
|
||
tape('isUSorCAHouseNumberZero', function(t) { | ||
t.test('non-0 house number in USA should return true', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['USA'] | ||
}, | ||
address_parts: { | ||
number: '17' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [record], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
t.test('non-0 house number in CAN should return true', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['CAN'] | ||
}, | ||
address_parts: { | ||
number: '17' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [record], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
t.test('non-0 house number in non-USA/CAN should return true', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['GBR'] | ||
}, | ||
address_parts: { | ||
number: '17' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [record], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
t.test('0 house number in USA should return false', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['USA'] | ||
}, | ||
address_parts: { | ||
number: '0' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
t.test('0 house number in CAN should return false', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['CAN'] | ||
}, | ||
address_parts: { | ||
number: '0' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
t.test('0 house number in non-USA/CAN should return true', function(t) { | ||
var record = { | ||
parent: { | ||
country_a: ['GBR'] | ||
}, | ||
address_parts: { | ||
number: '0' | ||
} | ||
}; | ||
|
||
var filter = isUSorCAHouseNumberZero.create(); | ||
|
||
test_stream([record], filter, function(err, actual) { | ||
t.deepEqual(actual, [record], 'should have returned true'); | ||
t.end(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters