Browse Source

Use createExpectedQuery() instead of writing them out.

test/unit/query/search.js
	-Rather than writing out full elasticsearch queries as object
	literals, use `createExpectedQuery()` as much as possible.
	Reduces duplication.
search-suggest-categories
Severyn Kozak 10 years ago
parent
commit
32a3515d05
  1. 62
      test/unit/query/search.js

62
test/unit/query/search.js

@ -110,6 +110,7 @@ function createExpectedQuery(){
'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({
@ -150,31 +151,8 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var expected = { var expected = createExpectedQuery();
'query': { expected.query.filtered.filter.bool.must = [];
'filtered': {
'query': {
'bool': {
'must': [{
'match': {
'name.default': 'test'
}
}
]
}
},
'filter': {
'bool': {
'must': []
}
}
}
},
'size': 10,
'sort': sort,
'track_scores': true
};
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(query, expected, 'valid search query');
t.end(); t.end();
}); });
@ -186,23 +164,8 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var expected = { var expected = createExpectedQuery();
'query': { expected.query.filtered.filter.bool.must = [{
'filtered': {
'query': {
'bool': {
'must': [{
'match': {
'name.default': 'test'
}
}
]
}
},
'filter': {
'bool': {
'must': [
{
'geo_distance': { 'geo_distance': {
'distance': '50km', 'distance': '50km',
'distance_type': 'plane', 'distance_type': 'plane',
@ -213,13 +176,9 @@ module.exports.tests.query = function(test, common) {
'lon': '-82.51' 'lon': '-82.51'
} }
} }
} }];
] expected.sort.shift();
} expected.sort.unshift(
}
}
},
'sort': [
'_score', '_score',
{ {
'_geo_distance': { '_geo_distance': {
@ -231,10 +190,7 @@ module.exports.tests.query = function(test, common) {
'unit': 'km' 'unit': 'km'
} }
} }
].concat(sort.slice(1)), );
'size': 10,
'track_scores': true
};
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(query, expected, 'valid search query');
t.end(); t.end();

Loading…
Cancel
Save