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
31 changes: 27 additions & 4 deletions src/controllers/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,48 @@ 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'
}, options)
.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',
Expand Down
24 changes: 15 additions & 9 deletions test/controllers/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand All @@ -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);
Expand Down