Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Collection.prototype.mCreateDocument = function (documents, options, cb) {
});

self.kuzzle.query(this.buildQueryArgs('document', 'mCreate'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
cb(err, res && res.result);
});

return self;
Expand Down Expand Up @@ -403,7 +403,7 @@ Collection.prototype.mCreateOrReplaceDocument = function (documents, options, cb
});

self.kuzzle.query(this.buildQueryArgs('document', 'mCreateOrReplace'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
cb(err, res && res.result);
});

return self;
Expand Down Expand Up @@ -437,7 +437,7 @@ Collection.prototype.mDeleteDocument = function (documentIds, options, cb) {
self.kuzzle.callbackRequired('Collection.mDelete', cb);

self.kuzzle.query(this.buildQueryArgs('document', 'mDelete'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
cb(err, res && res.result);
});

return self;
Expand Down Expand Up @@ -540,7 +540,7 @@ Collection.prototype.mUpdateDocument = function (documents, options, cb) {
});

self.kuzzle.query(this.buildQueryArgs('document', 'mUpdate'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
cb(err, res && res.result);
});

return self;
Expand Down
111 changes: 110 additions & 1 deletion test/Collection/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,33 @@ describe('Collection methods', function () {

kuzzle.query.yield(null, { result: result });
});

it('should handle partial errors', function (done) {
this.timeout(50);

collection.mCreateDocument(content.documents, function (err, res) {
should(res).be.instanceof(Object);
should(res).match(result);
should(err).be.instanceof(Object);
should(err).match({status: 206});
done();
});

kuzzle.query.yield({status: 206}, { result: result });
});

it('should handle global errors', function (done) {
this.timeout(50);

collection.mCreateDocument(content.documents, function (err, res) {
should(res).be.undefined();
should(err).be.instanceof(Object);
should(err).match({status: 503});
done();
});

kuzzle.query.yield({status: 503});
});
});

describe('#mCreateOrReplaceDocument', function () {
Expand Down Expand Up @@ -916,6 +943,33 @@ describe('Collection methods', function () {

kuzzle.query.yield(null, { result: result });
});

it('should handle partial errors', function (done) {
this.timeout(50);

collection.mCreateOrReplaceDocument(content.documents, function (err, res) {
should(res).be.instanceof(Object);
should(res).match(result);
should(err).be.instanceof(Object);
should(err).match({status: 206});
done();
});

kuzzle.query.yield({status: 206}, { result: result });
});

it('should handle global errors', function (done) {
this.timeout(50);

collection.mCreateOrReplaceDocument(content.documents, function (err, res) {
should(res).be.undefined();
should(err).be.instanceof(Object);
should(err).match({status: 503});
done();
});

kuzzle.query.yield({status: 503});
});
});

describe('#mDeleteDocument', function () {
Expand Down Expand Up @@ -960,6 +1014,33 @@ describe('Collection methods', function () {

kuzzle.query.yield(null, { result: result });
});

it('should handle partial errors', function (done) {
this.timeout(50);

collection.mDeleteDocument(content.ids, function (err, res) {
should(res).be.instanceof(Object);
should(res).match(result);
should(err).be.instanceof(Object);
should(err).match({status: 206});
done();
});

kuzzle.query.yield({status: 206}, { result: result });
});

it('should handle global errors', function (done) {
this.timeout(50);

collection.mDeleteDocument(content.ids, function (err, res) {
should(res).be.undefined();
should(err).be.instanceof(Object);
should(err).match({status: 503});
done();
});

kuzzle.query.yield({status: 503});
});
});

describe('#mGetDocument', function () {
Expand Down Expand Up @@ -1096,13 +1177,41 @@ describe('Collection methods', function () {
this.timeout(50);

collection.mUpdateDocument(content.documents, function (err, res) {
should(res).should.be.instanceof(Object);
should(res).be.instanceof(Object);
should(res).match(result);
should(err).be.null();
done();
});

kuzzle.query.yield(null, { result: result });
});

it('should handle partial errors', function (done) {
this.timeout(50);

collection.mUpdateDocument(content.documents, function (err, res) {
should(res).be.instanceof(Object);
should(res).match(result);
should(err).be.instanceof(Object);
should(err).match({status: 206});
done();
});

kuzzle.query.yield({status: 206}, { result: result });
});

it('should handle global errors', function (done) {
this.timeout(50);

collection.mUpdateDocument(content.documents, function (err, res) {
should(res).be.undefined();
should(err).be.instanceof(Object);
should(err).match({status: 503});
done();
});

kuzzle.query.yield({status: 503});
});
});

describe('#getSpecifications', function () {
Expand Down