diff --git a/src/controllers/collection.js b/src/controllers/collection.js index d16178388..dec3cf363 100644 --- a/src/controllers/collection.js +++ b/src/controllers/collection.js @@ -171,17 +171,24 @@ class CollectionController { .then(response => response.result); } - updateSpecifications (index, collection, body, options = {}) { + updateSpecifications (index, collection, specifications, options = {}) { if (!index) { throw new Error('Kuzzle.collection.updateSpecifications: index is required'); } if (!collection) { throw new Error('Kuzzle.collection.updateSpecifications: collection is required'); } + if (!specifications) { + throw new Error('Kuzzle.collection.updateSpecifications: specifications are required'); + } + + const body = { + [index]: { + [collection]: specifications + } + }; return this.kuzzle.query({ - index, - collection, body, controller: 'collection', action: 'updateSpecifications' @@ -189,7 +196,23 @@ class CollectionController { .then(response => response.result); } - validateSpecifications (body, options = {}) { + validateSpecifications (index, collection, specifications, options = {}) { + if (!index) { + throw new Error('Kuzzle.collection.validateSpecifications: index is required'); + } + if (!collection) { + throw new Error('Kuzzle.collection.validateSpecifications: collection is required'); + } + if (!specifications) { + throw new Error('Kuzzle.collection.updateSpecifications: specifications are required'); + } + + const body = { + [index]: { + [collection]: specifications + } + }; + return this.kuzzle.query({ body, controller: 'collection', diff --git a/test/controllers/collection.test.js b/test/controllers/collection.test.js index f7ca8a5d1..12fb9a39d 100644 --- a/test/controllers/collection.test.js +++ b/test/controllers/collection.test.js @@ -411,17 +411,19 @@ describe('Collection Controller', () => { it('should call collection/updateSpecifications query with the new specifications and return a Promise which resolves a json object', () => { kuzzle.query.resolves({result: {foo: 'bar'}}); - const body = {foo: 'bar'}; - return kuzzle.collection.updateSpecifications('index', 'collection', body, options) + const specifications = {foo: 'bar'}; + return kuzzle.collection.updateSpecifications('index', 'collection', specifications, options) .then(res => { should(kuzzle.query) .be.calledOnce() .be.calledWith({ - body, + body: { + index: { + collection: specifications + } + }, controller: 'collection', - action: 'updateSpecifications', - index: 'index', - collection: 'collection' + action: 'updateSpecifications' }, options); should(res).match({foo: 'bar'}); @@ -439,13 +441,17 @@ describe('Collection Controller', () => { } }); - const body = {foo: 'bar'}; - return kuzzle.collection.validateSpecifications(body, options) + const specifications = {foo: 'bar'}; + return kuzzle.collection.validateSpecifications('index', 'collection', specifications, options) .then(res => { should(kuzzle.query) .be.calledOnce() .be.calledWith({ - body, + body: { + index: { + collection: specifications + } + }, controller: 'collection', action: 'validateSpecifications' }, options);