UNPKG

p2p-db-osm

Version:

API for p2p-db adding OpenStreetMap data types and querying.

43 lines (37 loc) 1.11 kB
module.exports = function (t, db, data, expected, cb) { var batch = data.map(function (elm) { var id = elm.id delete elm.id return { type: 'put', id: id, value: elm } }) db.osm.batch(batch, function (err) { t.error(err) ;(function next () { var q = expected.shift() if (!q) return cb() var pending = 2 db.osm.query(q.bbox, function (err, res) { t.error(err, 'no error on cb query') var ids = res.map(function (elm) { return elm.id }).sort() t.deepEquals(ids, q.expected.sort(), 'ids match cb query') if (!--pending) next() }) collect(db.osm.query(q.bbox), function (err, res) { t.error(err, 'no error on streaming query') var ids = res.map(function (elm) { return elm.id }).sort() t.deepEquals(ids, q.expected.sort(), 'ids match cb query') if (!--pending) next() }) })() }) } function collect (stream, cb) { var res = [] stream.on('data', res.push.bind(res)) stream.once('end', cb.bind(null, null, res)) stream.once('error', cb.bind(null)) }