Skip to content

Commit 6c7d805

Browse files
authored
KZL-547 - Update validateSpecifications signature to take index and collection (#318)
* Update validatespecification signature to take index and collection * specifications is mandatory * typos
1 parent 76a39d9 commit 6c7d805

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/controllers/collection.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,48 @@ class CollectionController {
171171
.then(response => response.result);
172172
}
173173

174-
updateSpecifications (index, collection, body, options = {}) {
174+
updateSpecifications (index, collection, specifications, options = {}) {
175175
if (!index) {
176176
throw new Error('Kuzzle.collection.updateSpecifications: index is required');
177177
}
178178
if (!collection) {
179179
throw new Error('Kuzzle.collection.updateSpecifications: collection is required');
180180
}
181+
if (!specifications) {
182+
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
183+
}
184+
185+
const body = {
186+
[index]: {
187+
[collection]: specifications
188+
}
189+
};
181190

182191
return this.kuzzle.query({
183-
index,
184-
collection,
185192
body,
186193
controller: 'collection',
187194
action: 'updateSpecifications'
188195
}, options)
189196
.then(response => response.result);
190197
}
191198

192-
validateSpecifications (body, options = {}) {
199+
validateSpecifications (index, collection, specifications, options = {}) {
200+
if (!index) {
201+
throw new Error('Kuzzle.collection.validateSpecifications: index is required');
202+
}
203+
if (!collection) {
204+
throw new Error('Kuzzle.collection.validateSpecifications: collection is required');
205+
}
206+
if (!specifications) {
207+
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
208+
}
209+
210+
const body = {
211+
[index]: {
212+
[collection]: specifications
213+
}
214+
};
215+
193216
return this.kuzzle.query({
194217
body,
195218
controller: 'collection',

test/controllers/collection.test.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,19 @@ describe('Collection Controller', () => {
411411
it('should call collection/updateSpecifications query with the new specifications and return a Promise which resolves a json object', () => {
412412
kuzzle.query.resolves({result: {foo: 'bar'}});
413413

414-
const body = {foo: 'bar'};
415-
return kuzzle.collection.updateSpecifications('index', 'collection', body, options)
414+
const specifications = {foo: 'bar'};
415+
return kuzzle.collection.updateSpecifications('index', 'collection', specifications, options)
416416
.then(res => {
417417
should(kuzzle.query)
418418
.be.calledOnce()
419419
.be.calledWith({
420-
body,
420+
body: {
421+
index: {
422+
collection: specifications
423+
}
424+
},
421425
controller: 'collection',
422-
action: 'updateSpecifications',
423-
index: 'index',
424-
collection: 'collection'
426+
action: 'updateSpecifications'
425427
}, options);
426428

427429
should(res).match({foo: 'bar'});
@@ -439,13 +441,17 @@ describe('Collection Controller', () => {
439441
}
440442
});
441443

442-
const body = {foo: 'bar'};
443-
return kuzzle.collection.validateSpecifications(body, options)
444+
const specifications = {foo: 'bar'};
445+
return kuzzle.collection.validateSpecifications('index', 'collection', specifications, options)
444446
.then(res => {
445447
should(kuzzle.query)
446448
.be.calledOnce()
447449
.be.calledWith({
448-
body,
450+
body: {
451+
index: {
452+
collection: specifications
453+
}
454+
},
449455
controller: 'collection',
450456
action: 'validateSpecifications'
451457
}, options);

0 commit comments

Comments
 (0)