|
| 1 | + |
| 2 | +const through = require('through2'); |
| 3 | +const mapper = require('../../stream/addresses_without_street'); |
| 4 | +const Document = require('pelias-model').Document; |
| 5 | + |
| 6 | +module.exports.tests = {}; |
| 7 | + |
| 8 | +// test exports |
| 9 | +module.exports.tests.interface = function(test, common) { |
| 10 | + test('interface: factory', function(t) { |
| 11 | + t.equal(typeof mapper, 'function', 'stream factory'); |
| 12 | + t.end(); |
| 13 | + }); |
| 14 | + test('interface: stream', function(t) { |
| 15 | + var stream = mapper(); |
| 16 | + t.equal(typeof stream, 'object', 'valid stream'); |
| 17 | + t.equal(typeof stream._read, 'function', 'valid readable'); |
| 18 | + t.equal(typeof stream._write, 'function', 'valid writeable'); |
| 19 | + t.end(); |
| 20 | + }); |
| 21 | +}; |
| 22 | + |
| 23 | +// a tags with missing required extra tag (addr:housenumber) |
| 24 | +// should pass through the stream without being modified. |
| 25 | +// @ref https://github.com/pelias/openstreetmap/pull/565#issuecomment-1062874227 |
| 26 | +module.exports.tests.passthrough = function(test, common) { |
| 27 | + test('passthrough: missing addr:housenumber tag', function(t) { |
| 28 | + var original = new Document('a','b', 1); |
| 29 | + original.setMeta('tags', { 'addr:place': 'L14' }); |
| 30 | + var stream = mapper(); |
| 31 | + stream.pipe( through.obj( function( doc, enc, next ){ |
| 32 | + t.deepEqual(doc.getMeta('tags'), original.getMeta('tags'), 'tags not modified' ); |
| 33 | + t.end(); // test will fail if not called (or called twice). |
| 34 | + next(); |
| 35 | + })); |
| 36 | + stream.write(original); |
| 37 | + }); |
| 38 | +}; |
| 39 | + |
| 40 | +// // ======================== addresses ========================= |
| 41 | + |
| 42 | +module.exports.tests.karlsruhe_schema = function(test, common) { |
| 43 | + test('maps - karlsruhe schema with filled street', function(t) { |
| 44 | + var doc = new Document('a','b', 1); |
| 45 | + doc.setMeta('tags', { 'addr:street': 'BBB' }); |
| 46 | + var stream = mapper(); |
| 47 | + stream.pipe( through.obj( function( doc, enc, next ){ |
| 48 | + var tags = doc.getMeta('tags'); |
| 49 | + t.equal(tags['addr:street'], 'BBB', 'correctly mapped'); |
| 50 | + t.end(); // test will fail if not called (or called twice). |
| 51 | + next(); |
| 52 | + })); |
| 53 | + stream.write(doc); |
| 54 | + }); |
| 55 | + test('maps - karlsruhe schema with empty street and filled place', function(t) { |
| 56 | + var doc = new Document('a','b', 1); |
| 57 | + doc.setMeta('tags', { 'addr:place': 'L14', 'addr:street': '', 'addr:housenumber': '14' }); |
| 58 | + var stream = mapper(); |
| 59 | + stream.pipe( through.obj( function( doc, enc, next ){ |
| 60 | + var tags = doc.getMeta('tags'); |
| 61 | + t.equal(tags['addr:street'], 'L14', 'correctly mapped'); |
| 62 | + t.end(); // test will fail if not called (or called twice). |
| 63 | + next(); |
| 64 | + })); |
| 65 | + stream.write(doc); |
| 66 | + }); |
| 67 | + test('maps - karlsruhe schema without street and with filled place', function(t) { |
| 68 | + var doc = new Document('a','b', 1); |
| 69 | + doc.setMeta('tags', { 'addr:place': 'L14', 'addr:housenumber': '14' }); |
| 70 | + var stream = mapper(); |
| 71 | + stream.pipe( through.obj( function( doc, enc, next ){ |
| 72 | + var tags = doc.getMeta('tags'); |
| 73 | + t.equal(tags['addr:street'], 'L14', 'correctly mapped'); |
| 74 | + t.end(); // test will fail if not called (or called twice). |
| 75 | + next(); |
| 76 | + })); |
| 77 | + stream.write(doc); |
| 78 | + }); |
| 79 | + test('maps - karlsruhe schema with both street and place', function(t) { |
| 80 | + var doc = new Document('a','b', 1); |
| 81 | + doc.setMeta('tags', { 'addr:place': 'L14', 'addr:street': 'BBB', 'addr:housenumber': '14' }); |
| 82 | + var stream = mapper(); |
| 83 | + stream.pipe( through.obj( function( doc, enc, next ){ |
| 84 | + var tags = doc.getMeta('tags'); |
| 85 | + t.equal(tags['addr:street'], 'BBB', 'correctly mapped'); |
| 86 | + t.end(); // test will fail if not called (or called twice). |
| 87 | + next(); |
| 88 | + })); |
| 89 | + stream.write(doc); |
| 90 | + }); |
| 91 | +}; |
| 92 | + |
| 93 | +module.exports.all = function (tape, common) { |
| 94 | + |
| 95 | + function test(name, testFunction) { |
| 96 | + return tape('address_without_street: ' + name, testFunction); |
| 97 | + } |
| 98 | + |
| 99 | + for( var testCase in module.exports.tests ){ |
| 100 | + module.exports.tests[testCase](test, common); |
| 101 | + } |
| 102 | +}; |
0 commit comments