Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.tests.sport_wildcard = function(test, common) {
var doc = new Document('osm','a',1);
doc.setMeta( 'tags', { 'sport': 'rugby_union' } );
test('maps - sports inherit recreation via wildcard', function(t) {
var stream = mapper( defaultMapping );
stream.pipe( through.obj( function( doc, enc, next ){
t.deepEqual(doc.category, ['recreation','entertainment'], 'correctly mapped');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};
test('errors - catch thrown errors', function(t) {
var doc = new Document('a','b', 1);
// this method will throw a generic Error for testing
doc.getLayer = function(){ throw new Error('test'); };
test_stream([doc], extractor(), function( err, actual ) {
t.equal(actual.length, 0, 'no results');
t.end();
});
});
test('errors - catch thrown errors', function(t) {
var doc = new Document('osm','a',1);
// this method will throw a generic Error for testing
doc.getMeta = function(){ throw new Error('test'); };
var stream = mapper();
stream.pipe( through.obj( function( doc, enc, next ){
t.deepEqual( doc.getLayer(), 'a', 'doc passthrough' );
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};
module.exports.tests.international_airport = function(test, common) {
var doc = new Document('a','venue',1);
doc.setMeta('tags', { 'aerodrome': 'international', 'iata': 'JFK' });
test('alias - international airport', function(t) {
var stream = mapper();
stream.pipe( through.obj( function( doc, enc, next ){
t.deepEqual(doc.getPopularity(), 15000);
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};
module.exports.tests.nonvenue = function (test, common) {
var doc = new Document('osm', 'address', 1);
doc.setMeta('tags', { 'importance': 'international' });
test('does not map - non-venue', t => {
var stream = mapper();
stream.pipe(through.obj((doc, enc, next) => {
t.false(doc.getPopularity(), 'no mapping performed');
t.end(); // test will fail if not called (or called twice).
next();
}));
stream.write(doc);
});
};
docs.completeDoc = new Document('osm','venue','item:6');
docs.completeDoc.address_parts = {
number: '13', street: 'Goldsmiths row', test: 'prop'
};
docs.completeDoc
.setName('default','item6')
.setName('alt','item six')
.setCentroid({lat:6,lon:6})
.setMeta('foo','bar')
.setMeta('bing','bang');
docs.osmNode1 = new Document('osm','venue','item:7')
.setName('node','node7')
.setCentroid({lat:7,lon:7});
docs.osmWay1 = new Document('osm','venue','way:8')
.setName('way','way8')
.setMeta('nodes', [
{ lat: 10, lon: 10 },
{ lat: 06, lon: 10 },
{ lat: 06, lon: 06 },
{ lat: 10, lon: 06 }
]);
docs.osmRelation1 = new Document('osm','venue','item:9')
.setName('relation','relation9')
.setCentroid({lat:9,lon:9});
// ref: https://github.com/pelias/openstreetmap/issues/21
docs.semicolonStreetNumbers = new Document('osm','venue','item:10');
docs.semicolonStreetNumbers.setName('default','poi10');
docs.semicolonStreetNumbers.setCentroid({lat:10,lon:10});
function setupDocument(record, hierarchy) {
var wofDoc = new Document( 'whosonfirst', record.place_type, record.id );
if (record.name) {
wofDoc.setName('default', record.name);
// index a version of postcode which doesn't contain whitespace
if (record.place_type === 'postalcode' && typeof record.name === 'string') {
var sans_whitespace = record.name.replace(/\s/g, '');
if (sans_whitespace !== record.name) {
wofDoc.setNameAlias('default', sans_whitespace);
}
}
// index name aliases for all other records (where available)
else {
if (record.name_aliases.length) {
record.name_aliases.forEach(alias => {
function geojsonifyPlace(params, place) {
const gid_components = decode_gid(place._id);
// setup the base doc
const doc = {
id: gid_components.id,
gid: new Document(place.source, place.layer, gid_components.id).getGid(),
layer: place.layer,
source: place.source,
source_id: gid_components.id,
bounding_box: place.bounding_box,
lat: parseFloat(place.center_point.lat),
lng: parseFloat(place.center_point.lon)
};
// assign name, logging a warning if it doesn't exist
if (_.has(place, 'name.default')) {
doc.name = field.getStringValue(place.name.default);
} else {
logger.warn(`doc ${doc.gid} does not contain name.default`);
}
// assign all the details info into the doc
docs.namedWithAddress.address_parts = {
number: '11', street: 'Sesame st'
};
docs.completeDoc = new Document('osm','venue','item:6');
docs.completeDoc.address_parts = {
number: '13', street: 'Goldsmiths row', test: 'prop'
};
docs.completeDoc
.setName('default','item6')
.setName('alt','item six')
.setCentroid({lat:6,lon:6})
.setMeta('foo','bar')
.setMeta('bing','bang');
docs.osmNode1 = new Document('osm','venue','item:7')
.setName('node','node7')
.setCentroid({lat:7,lon:7});
docs.osmWay1 = new Document('osm','venue','way:8')
.setName('way','way8')
.setMeta('nodes', [
{ lat: 10, lon: 10 },
{ lat: 06, lon: 10 },
{ lat: 06, lon: 06 },
{ lat: 10, lon: 06 }
]);
docs.osmRelation1 = new Document('osm','venue','item:9')
.setName('relation','relation9')
.setCentroid({lat:9,lon:9});
function makeNewId(source, placeType, id) {
if (!id) {
return;
}
var doc = new Document(source, placeType, id);
return doc.getGid();
}