Browse Source

adding controller tests to test details=true test case

pull/103/head
Harish Krishna 10 years ago
parent
commit
0e9af3b9b8
  1. 50
      test/unit/controller/doc.js
  2. 50
      test/unit/controller/search.js
  3. 60
      test/unit/controller/suggest.js

50
test/unit/controller/doc.js

@ -16,7 +16,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.functional_success = function(test, common) {
// expected geojson features for 'client/doc/ok/1' fixture
var expected_details = [{
var expected = [{
type: 'Feature',
geometry: {
type: 'Point',
@ -25,10 +25,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'
}
}, {
@ -40,15 +36,33 @@ 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/mget/ok/1', function( cmd ){
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');
t.end();
}
};
controller( { clean: { ids: [ {'id' : 123, 'type': 'a' } ] } }, res );
});
var detailed_expectation = [{
type: 'Feature',
geometry: {
type: 'Point',
@ -57,6 +71,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'
}
}, {
@ -68,11 +86,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/mget/ok/1', function( cmd ){
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'a' } ] } }, 'correct backend command');
});
@ -87,11 +109,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 correctly mapped along with details');
t.end();
}
};
controller( { clean: { ids: [ {'id' : 123, 'type': 'a' } ] } }, res );
controller( { clean: { ids: [ {'id' : 123, 'type': 'a' } ], details: true } }, res );
});
};

50
test/unit/controller/search.js

@ -17,7 +17,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.functional_success = function(test, common) {
// expected geojson features for 'client/suggest/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,33 @@ 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/search/ok/1', function( cmd ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend 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: { a: 'b' } }, res );
});
var detailed_expectation = [{
type: 'Feature',
geometry: {
type: 'Point',
@ -58,6 +72,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,13 +87,17 @@ 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/search/ok/1', function( cmd ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command');
t.deepEqual(cmd, { body: { a: 'b', details: true }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command');
});
var controller = setup( backend, mockQuery() );
var res = {
@ -88,11 +110,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: { a: 'b' } }, res );
controller( { clean: { a: 'b', details: true } }, res );
});
};

60
test/unit/controller/suggest.js

@ -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 );
});
};

Loading…
Cancel
Save