Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

correct some tests

  • Loading branch information...
commit 2341b3e94d9ad65b3c3cd69c72b5b512cb701ffc 1 parent 0675352
@pedrosnk authored
Showing with 26 additions and 11 deletions.
  1. +19 −9 lib/elastico.js
  2. +7 −2 test/elastico_test.js
View
28 lib/elastico.js
@@ -41,6 +41,7 @@ Elastico.prototype = {
'Content-Type': 'application/json',
}
};
+
var req = http.request(options, function(res) {
var jsonData = [];
res.on('data',function(chucked){
@@ -51,6 +52,7 @@ Elastico.prototype = {
callback(JSON.parse(jsonData));
});
});
+
if(body !== undefined){
req.setHeader('Content-Length', body.length.toString() );
req.write(JSON.stringify(extras));
@@ -65,7 +67,7 @@ Elastico.prototype = {
var options = {
host: this.options.host,
port: this.options.port,
- path: "/" + index + "/" + type + "?refresh=true",
+ path: "/" + index + "/" + type,
method: 'POST',
headers: {
'Content-Type': 'application/json'
@@ -88,7 +90,7 @@ Elastico.prototype = {
var options = {
host: this.options.host,
port: this.options.port,
- path: "/" + index + "/" + type + "/" + id + "?refresh=true",
+ path: "/" + index + "/" + type + "/" + id,
method: 'PUT',
headers: {
'Content-Type': 'application/json'
@@ -131,19 +133,28 @@ Elastico.prototype = {
},
createIndex: function(index, callback){
- var req = http.request(this.options.protocol + "://" + this.options.host + ":" +
- this.options.port + "/" + index + "?refresh=true", function(res){
+ var options = {
+ host: this.options.host,
+ port: this.options.port,
+ path: "/" + index,
+ method: 'POST'
+ }
+ var req = http.request(options, function(res){
if (callback != undefined){
callback(res.statusCode < 300 && res.statusCode >= 200);
}
});
- req.method = "POST";
req.end();
},
removeIndex: function(index, callback){
- var req = http.request(this.options.protocol + "://" + this.options.host + ":" +
- this.options.port + "/" + index + "?refresh=true", function(res){
+ var options = {
+ host: this.options.host,
+ port: this.options.port,
+ path: "/" + index,
+ method: 'DELETE',
+ }
+ var req = http.request(options, function(res){
if (callback != undefined){
if (res.statusCode < 300 && res.statusCode >= 200){
callback(true);
@@ -152,7 +163,6 @@ Elastico.prototype = {
}
}
});
- req.method = "DELETE";
req.end();
},
@@ -160,7 +170,7 @@ Elastico.prototype = {
var options = {
host: this.options.host,
port: this.options.port,
- path: "/" + index + "/" + type + "/_bulk?refresh=true",
+ path: "/" + index + "/" + type + "/_bulk",
method: 'POST',
headers: {
'Content-Type': 'application/json'
View
9 test/elastico_test.js
@@ -9,7 +9,6 @@ describe('Elastico', function(){
done();
});
});
-
});
it('should get an object of the elastic search', function(done){
@@ -38,7 +37,7 @@ describe('Elastico', function(){
});
it('should insert an data into the elastic search with an pre existing id', function(done){
- elastic_search.insertWithId("test","ids", "zomgid" , '{"key", "value"}', function(created){
+ elastic_search.insertWithId("test","ids", "zomgid" , '{"key": "value"}', function(created){
created.should.be.true;
done();
});
@@ -63,4 +62,10 @@ describe('Elastico', function(){
});
});
+ after(function(done){
+ elastic_search.removeIndex('test', function(removed){
+ done();
+ });
+ });
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.