Skip to content

Commit

Permalink
Adapt integration suite to new elasticsearch package
Browse files Browse the repository at this point in the history
- On success, elasticsearch errors are now *null* rather than *undefined*,
which broke some tests. Now we just check that `err` is falsy rather than strictly
equal to `undefined`.

- Payload moved from res to res.body

- `statusCode` moved from top level callback arg to `res.statuCode`

- normalized function formatting for tests to `(err, { body })` there
  were a few different styles/indentations.
  • Loading branch information
michaelkirk committed Mar 11, 2024
1 parent 7bfef13 commit 4767be5
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 159 deletions.
62 changes: 31 additions & 31 deletions integration/address_matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.number': 30 } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'match street number' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'match street number' );
done();
});
});
Expand All @@ -82,9 +82,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match_phrase: { 'address_parts.street': 'west 26th street' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 2, 'match street name' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 2, 'match street name' );
done();
});
});
Expand All @@ -96,9 +96,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match_phrase: { 'address_parts.street': 'W 26th ST' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 2, 'match street name - abbr' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 2, 'match street name - abbr' );
done();
});
});
Expand All @@ -110,9 +110,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': '10010' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 3, 'match zip - numeric' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 3, 'match zip - numeric' );
done();
});
});
Expand All @@ -124,9 +124,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': 'e24dn' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'match zip - string' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'match zip - string' );
done();
});
});
Expand All @@ -138,9 +138,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': '100-10' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 3, 'match zip - numeric - punct' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 3, 'match zip - numeric - punct' );
done();
});
});
Expand All @@ -152,9 +152,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': '10 0 10' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 3, 'match zip - numeric - whitespace' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 3, 'match zip - numeric - whitespace' );
done();
});
});
Expand All @@ -166,9 +166,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': 'E2-4DN' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'match zip - string - punct' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'match zip - string - punct' );
done();
});
});
Expand All @@ -180,9 +180,9 @@ module.exports.tests.functional = function(test, common){
body: { query: { bool: { must: [
{ match: { 'address_parts.zip': 'E2 4DN' } }
]}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'match zip - string - whitespace' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'match zip - string - whitespace' );
done();
});
});
Expand Down Expand Up @@ -289,10 +289,10 @@ module.exports.tests.venue_vs_address = function(test, common){
}
}
}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), TOTAL_ADDRESS_DOCS+1, 'matched all docs' );
t.equal( res.hits.hits[TOTAL_ADDRESS_DOCS]._id, '1', 'exact name match first' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), TOTAL_ADDRESS_DOCS+1, 'matched all docs' );
t.equal( body.hits.hits[TOTAL_ADDRESS_DOCS]._id, '1', 'exact name match first' );
done();
});
});
Expand Down
72 changes: 36 additions & 36 deletions integration/admin_abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -77,10 +77,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -99,10 +99,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -121,10 +121,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand Down Expand Up @@ -177,10 +177,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -199,10 +199,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -221,10 +221,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand All @@ -243,10 +243,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand Down Expand Up @@ -311,10 +311,10 @@ module.exports.tests.synonyms = function (test, common) {
}
}
}
}, (err, res) => {
t.equal(err, undefined);
t.equal(getTotalHits(res.hits), 2, 'matches both documents');
t.equal(res.hits.hits[0]._score, res.hits.hits[1]._score, 'scores match');
}, (err, { body }) => {
t.false(err);
t.equal(getTotalHits(body.hits), 2, 'matches both documents');
t.equal(body.hits.hits[0]._score, body.hits.hits[1]._score, 'scores match');
done();
});
});
Expand Down
18 changes: 9 additions & 9 deletions integration/admin_matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ module.exports.tests.functional = function(test, common){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country': 'Test Country' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'document found' );
done();
});
});
Expand All @@ -58,9 +58,9 @@ module.exports.tests.functional = function(test, common){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country_a': 'TestCountry' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'document found' );
done();
});
});
Expand All @@ -70,9 +70,9 @@ module.exports.tests.functional = function(test, common){
suite.client.search({
index: suite.props.index,
body: { query: { match: { 'parent.country_id': '100' } } }
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'document found' );
done();
});
});
Expand Down
14 changes: 7 additions & 7 deletions integration/analyzer_peliasPhrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ module.exports.tests.slop_query = function(test, common){
suite.assert( function( done ){
suite.client.search({
index: suite.props.index,
type: config.schema.typeName,
searchType: 'dfs_query_then_fetch',
body: buildQuery('Lake Cayuga')
}, function( err, res ){
t.equal( getTotalHits(res.hits), 3 );
var hits = res.hits.hits;
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 3 );
var hits = body.hits.hits;

t.equal( hits[0]._source.name.default, 'Lake Cayuga' );

Expand Down Expand Up @@ -273,9 +273,9 @@ module.exports.tests.slop = function(test, common){
'slop': 3,
}
}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'document found' );
done();
});
});
Expand Down
18 changes: 9 additions & 9 deletions integration/autocomplete_abbreviated_street_names.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm
'query': 'Grolmanstr.'
}
}}}
}, function( err, res ){
t.equal( err, undefined );
t.equal( getTotalHits(res.hits), 1, 'document found' );
}, (err, { body }) => {
t.false(err);
t.equal( getTotalHits(body.hits), 1, 'document found' );
done();
});
});
Expand Down Expand Up @@ -78,9 +78,9 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm
// 'query': 'Grolmanstraße'
// }
// }}}
// }, function( err, res ){
// t.equal( err, undefined );
// t.equal( getTotalHits(res.hits), 1, 'document found' );
// }, (err, { body }) => {
// t.false(err);
// t.equal( getTotalHits(body.hits), 1, 'document found' );
// done();
// });
// });
Expand All @@ -98,9 +98,9 @@ module.exports.tests.index_expanded_form_search_contracted = function(test, comm
// 'query': 'Grolmanstraße'
// }
// }}}
// }, function( err, res ){
// t.equal( err, undefined );
// t.equal( getTotalHits(res.hits), 1, 'document found' );
// }, (err, { body }) => {
// t.false(err);
// t.equal( getTotalHits(body.hits), 1, 'document found' );
// done();
// });
// });
Expand Down
Loading

0 comments on commit 4767be5

Please sign in to comment.