|
|
|
var setup = require('../../../controller/place'),
|
|
|
|
mockBackend = require('../mock/backend');
|
|
|
|
|
|
|
|
module.exports.tests = {};
|
|
|
|
|
|
|
|
module.exports.tests.interface = function(test, common) {
|
|
|
|
test('valid interface', function(t) {
|
|
|
|
t.equal(typeof setup, 'function', 'setup is a function');
|
|
|
|
t.equal(typeof setup(), 'function', 'setup returns a controller');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// functionally test controller (backend success)
|
|
|
|
module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
|
|
|
// expected geojson features for 'client/place/ok/1' fixture
|
|
|
|
var expected = [{
|
|
|
|
type: 'Feature',
|
|
|
|
geometry: {
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [ -50.5, 100.1 ]
|
|
|
|
},
|
|
|
|
properties: {
|
|
|
|
id: 'myid1',
|
|
|
|
layer: 'mytype1',
|
|
|
|
text: 'test name1, city1, state1'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: 'Feature',
|
|
|
|
geometry: {
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [ -51.5, 100.2 ]
|
|
|
|
},
|
|
|
|
properties: {
|
|
|
|
id: 'myid2',
|
|
|
|
layer: 'mytype2',
|
|
|
|
text: 'test name2, city2, state2'
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
test('functional success', function(t) {
|
|
|
|
var backend = mockBackend( 'client/mget/ok/1', function( cmd ){
|
Return multiple results in place when osm node and way share an id
It turns out the _type parameter to the Elasticsearch
[multiget](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html)
API does not allow an array of possible values. We were depending on its
ability to search multiple types to allow searching for OSM nodes and
ways.
But, since this doesn't work we essentially have to do it ourselves.
There is also the problem that OSM nodes and ways share an ID space. So
a gid such as `osm:venue:5` could in theory correspond to 2 records.
It seems like the only nice thing to do in that case is return both
results.
This PR "unrolls" such queries. For example, in the case of
`osm:venue:5`, the sanitisers will return the following array of objects
to be turned into multiget queries:
```
[{
id: 5,
types: ["osmway", "osmnode"]
}]
```
Before, this would turn into a multiget query with only one entry, like
this:
```
{
"docs": [
{
"_index": "pelias",
"_type": [
" osmnode",
"osmway"
],
"_id": 5
}
]
}
```
now it would look like this:
{
"docs": [
{
"_index": "pelias",
"_type": "osmnode",
"_id": 5
},
{
"_index": "pelias",
"_type": "osmnode",
"_id": 5
}
]
}
TLDR you might get back more records from /place than the number of ids
you specified, but at least you will definitely get back what you are
looking for.
9 years ago
|
|
|
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'a' } ] } }, 'correct backend command');
|
|
|
|
});
|
|
|
|
var controller = setup( backend );
|
|
|
|
var res = {
|
|
|
|
status: function( code ){
|
|
|
|
t.equal(code, 200, 'status set');
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
json: function( json ){
|
|
|
|
t.equal(typeof json, 'object', 'returns json');
|
|
|
|
t.equal(typeof json.date, 'number', 'date set');
|
|
|
|
t.equal(json.type, 'FeatureCollection', 'valid geojson');
|
|
|
|
t.true(Array.isArray(json.features), 'features is array');
|
|
|
|
t.deepEqual(json.features, expected, 'values correctly mapped');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var req = { clean: { ids: [ {'id' : 123, types: [ 'a' ] } ] }, errors: [], warnings: [] };
|
|
|
|
var next = function next() {
|
|
|
|
t.equal(req.errors.length, 0, 'next was called without error');
|
|
|
|
t.end();
|
|
|
|
};
|
|
|
|
controller(req, res, next );
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// functionally test controller (backend failure)
|
|
|
|
module.exports.tests.functional_failure = function(test, common) {
|
|
|
|
test('functional failure', function(t) {
|
|
|
|
var backend = mockBackend( 'client/mget/fail/1', function( cmd ){
|
Return multiple results in place when osm node and way share an id
It turns out the _type parameter to the Elasticsearch
[multiget](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html)
API does not allow an array of possible values. We were depending on its
ability to search multiple types to allow searching for OSM nodes and
ways.
But, since this doesn't work we essentially have to do it ourselves.
There is also the problem that OSM nodes and ways share an ID space. So
a gid such as `osm:venue:5` could in theory correspond to 2 records.
It seems like the only nice thing to do in that case is return both
results.
This PR "unrolls" such queries. For example, in the case of
`osm:venue:5`, the sanitisers will return the following array of objects
to be turned into multiget queries:
```
[{
id: 5,
types: ["osmway", "osmnode"]
}]
```
Before, this would turn into a multiget query with only one entry, like
this:
```
{
"docs": [
{
"_index": "pelias",
"_type": [
" osmnode",
"osmway"
],
"_id": 5
}
]
}
```
now it would look like this:
{
"docs": [
{
"_index": "pelias",
"_type": "osmnode",
"_id": 5
},
{
"_index": "pelias",
"_type": "osmnode",
"_id": 5
}
]
}
TLDR you might get back more records from /place than the number of ids
you specified, but at least you will definitely get back what you are
looking for.
9 years ago
|
|
|
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'b' } ] } }, 'correct backend command');
|
|
|
|
});
|
|
|
|
var controller = setup( backend );
|
|
|
|
var req = { clean: { ids: [ {'id' : 123, types: [ 'b' ] } ] }, errors: [], warnings: [] };
|
|
|
|
var next = function( message ){
|
|
|
|
t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler');
|
|
|
|
t.end();
|
|
|
|
};
|
|
|
|
controller(req, undefined, next );
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.all = function (tape, common) {
|
|
|
|
|
|
|
|
function test(name, testFunction) {
|
|
|
|
return tape('GET /place ' + name, testFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var testCase in module.exports.tests ){
|
|
|
|
module.exports.tests[testCase](test, common);
|
|
|
|
}
|
|
|
|
};
|