Browse Source

Remove singleton expected query object.

test/unit/query/search.js
	-Rather than maintaining a "singleton" expected query object,
	which poses problems for tests that want to slightly modify it
	(for instance, by conditionally adding a constraint to
	`filter.bool.must`), make a function that returns it on demand,
	thereby creating a new one each time.
search-suggest-categories
Severyn Kozak 10 years ago
parent
commit
eca8a82818
  1. 73
      test/unit/query/search.js

73
test/unit/query/search.js

@ -71,44 +71,45 @@ var sort = [
} }
]; ];
var expected = { function createExpectedQuery(){
'query': { return {
'filtered': { 'query': {
'query': { 'filtered': {
'bool': { 'query': {
'must': [{ 'bool': {
'match': { 'must': [{
'name.default': 'test' 'match': {
'name.default': 'test'
}
} }
} ]
] }
} },
}, 'filter': {
'filter': { 'bool': {
'bool': { 'must': [
'must': [ {
{ 'geo_bounding_box': {
'geo_bounding_box': { 'center_point': {
'center_point': { 'top': '47.47',
'top': '47.47', 'right': '-61.84',
'right': '-61.84', 'bottom':'11.51',
'bottom':'11.51', 'left': '-103.16'
'left': '-103.16' },
}, '_cache': true,
'_cache': true, 'type': 'indexed'
'type': 'indexed' }
} }
} ]
] }
} }
} }
} },
}, 'sort': sort,
'sort': sort, 'size': 10,
'size': 10, 'track_scores': true
'track_scores': true };
}; }
module.exports.tests.query = function(test, common) { module.exports.tests.query = function(test, common) {
test('valid query', function(t) { test('valid query', function(t) {
var query = generate({ var query = generate({
@ -123,7 +124,7 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(query, createExpectedQuery(), 'valid search query');
t.end(); t.end();
}); });
@ -139,7 +140,7 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(query, createExpectedQuery(), 'valid search query');
t.end(); t.end();
}); });

Loading…
Cancel
Save