|
|
|
@ -17,7 +17,7 @@ module.exports.tests.interface = function(test, common) {
|
|
|
|
|
module.exports.tests.functional_success = function(test, common) { |
|
|
|
|
|
|
|
|
|
// expected geojson features for 'client/mget/ok/1' fixture
|
|
|
|
|
var expected_details = [{ |
|
|
|
|
var expected = [{ |
|
|
|
|
type: 'Feature', |
|
|
|
|
geometry: { |
|
|
|
|
type: 'Point', |
|
|
|
@ -26,10 +26,6 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
properties: { |
|
|
|
|
id: 'myid1', |
|
|
|
|
layer: 'mytype1', |
|
|
|
|
name: 'test name1', |
|
|
|
|
admin0: 'country1', |
|
|
|
|
admin1: 'state1', |
|
|
|
|
admin2: 'city1', |
|
|
|
|
text: 'test name1, city1, state1' |
|
|
|
|
} |
|
|
|
|
}, { |
|
|
|
@ -41,15 +37,43 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
properties: { |
|
|
|
|
id: 'myid2', |
|
|
|
|
layer: 'mytype2', |
|
|
|
|
name: 'test name2', |
|
|
|
|
admin0: 'country2', |
|
|
|
|
admin1: 'state2', |
|
|
|
|
admin2: 'city2', |
|
|
|
|
text: 'test name2, city2, state2' |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
var expected = [{ |
|
|
|
|
test('functional success', function(t) { |
|
|
|
|
var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){ |
|
|
|
|
// the backend executes suggest (vanilla and admin-only) and mget, so we check them all based on cmd
|
|
|
|
|
if( cmd.body.docs ){ |
|
|
|
|
t.deepEqual(cmd, {
|
|
|
|
|
body: { docs: [
|
|
|
|
|
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
|
|
|
|
|
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' } |
|
|
|
|
]} |
|
|
|
|
}, 'correct mget command'); |
|
|
|
|
} else { |
|
|
|
|
t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
var controller = setup( backend, mockQuery() ); |
|
|
|
|
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'); |
|
|
|
|
t.end(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
controller( { clean: { input: 'b' } }, res ); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var detailed_expectation = [{ |
|
|
|
|
type: 'Feature', |
|
|
|
|
geometry: { |
|
|
|
|
type: 'Point', |
|
|
|
@ -58,6 +82,10 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
properties: { |
|
|
|
|
id: 'myid1', |
|
|
|
|
layer: 'mytype1', |
|
|
|
|
name: 'test name1', |
|
|
|
|
admin0: 'country1', |
|
|
|
|
admin1: 'state1', |
|
|
|
|
admin2: 'city1', |
|
|
|
|
text: 'test name1, city1, state1' |
|
|
|
|
} |
|
|
|
|
}, { |
|
|
|
@ -69,11 +97,15 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
properties: { |
|
|
|
|
id: 'myid2', |
|
|
|
|
layer: 'mytype2', |
|
|
|
|
name: 'test name2', |
|
|
|
|
admin0: 'country2', |
|
|
|
|
admin1: 'state2', |
|
|
|
|
admin2: 'city2', |
|
|
|
|
text: 'test name2, city2, state2' |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
test('functional success', function(t) { |
|
|
|
|
test('functional success (with details)', function(t) { |
|
|
|
|
var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){ |
|
|
|
|
// the backend executes suggest (vanilla and admin-only) and mget, so we check them all based on cmd
|
|
|
|
|
if( cmd.body.docs ){ |
|
|
|
@ -84,7 +116,7 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
]} |
|
|
|
|
}, 'correct mget command'); |
|
|
|
|
} else { |
|
|
|
|
t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command'); |
|
|
|
|
t.deepEqual(cmd, { body: { input: 'b', details: true }, index: 'pelias' }, 'correct suggest command'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
var controller = setup( backend, mockQuery() ); |
|
|
|
@ -98,11 +130,11 @@ module.exports.tests.functional_success = function(test, common) {
|
|
|
|
|
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'); |
|
|
|
|
t.deepEqual(json.features, detailed_expectation, 'values with details correctly mapped'); |
|
|
|
|
t.end(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
controller( { clean: { input: 'b' } }, res ); |
|
|
|
|
controller( { clean: { input: 'b', details: true } }, res ); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|