Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One _request function since they are all the same (DRY)! Initial test…
…s for add and query. Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
- Loading branch information
Showing
2 changed files
with
67 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
var lib = require('../index'), | |||
assert = require('assert'); | |||
|
|||
module.exports = { | |||
'test client connection': function(beforeExit) { | |||
var n = 0; | |||
var client = lib.createClient({index:'_all'}); | |||
client.status({}, function(err, status) { | |||
status = JSON.parse(status.toString()); | |||
assert.ok(status.ok); | |||
n++; | |||
}); | |||
beforeExit(function() { | |||
assert.equal(1, n, 'callbacks'); | |||
}); | |||
}, | |||
'add and find document': function(beforeExit) { | |||
var n = 0; | |||
var doc = {field1: 'test field', field2: 'second test field'}; | |||
var client = lib.createClient({index:'test'}); | |||
client.add({type:'info', id:'1'}, doc, function(err, result) { | |||
result = JSON.parse(result.toString()); | |||
assert.ok(result.ok); | |||
n++; | |||
client.query({query: {field: {field1: 'test'}}}, function(err, result) { | |||
result = JSON.parse(result.toString()); | |||
assert.equal(result.hits.total, 1); | |||
assert.deepEqual(result.hits.hits[0]._source, doc); | |||
n++; | |||
}); | |||
}); | |||
beforeExit(function() { | |||
assert.equal(2, n, 'callbacks'); | |||
}); | |||
} | |||
} |