Skip to content

Commit d2af824

Browse files
committed
Merge branch 'develop' into fix-rc-73-paginate-fetchAll
2 parents 4d37ee4 + 114c603 commit d2af824

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/kuzzle.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,16 +884,19 @@ Kuzzle.prototype.dataCollectionFactory = function(index, collection) {
884884
collection = arguments[0];
885885
index = this.defaultIndex;
886886
}
887-
else if (arguments.length === 2 && typeof collection === 'object') {
888-
headers = collection;
889-
collection = index;
890-
index = this.defaultIndex;
891-
}
892887

893888
if (!index) {
894889
throw new Error('Unable to create a new data collection object: no index specified');
895890
}
896891

892+
if (typeof index !== 'string') {
893+
throw new Error('Invalid "index" argument: string expected, got ' + typeof index);
894+
}
895+
896+
if (typeof collection !== 'string') {
897+
throw new Error('Invalid "collection" argument: string expected, got ' + typeof collection);
898+
}
899+
897900
if (!this.collections[index]) {
898901
this.collections[index] = {};
899902
}

test/kuzzle/methods.test.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ describe('Kuzzle methods', function () {
178178
kuzzle = new Kuzzle('foo');
179179
});
180180

181+
it('should throw an error if arguments are not strings', () => {
182+
kuzzle.defaultIndex = 'foobar';
183+
should(function () { kuzzle.dataCollectionFactory(undefined); }).throw(/string expected/);
184+
should(function () { kuzzle.dataCollectionFactory('foo', undefined); }).throw(/string expected/);
185+
should(function () { kuzzle.dataCollectionFactory(null); }).throw(/string expected/);
186+
should(function () { kuzzle.dataCollectionFactory('foo', null); }).throw(/string expected/);
187+
should(function () { kuzzle.dataCollectionFactory(123); }).throw(/string expected/);
188+
should(function () { kuzzle.dataCollectionFactory(123, 'foo'); }).throw(/string expected/);
189+
should(function () { kuzzle.dataCollectionFactory('foo', 123); }).throw(/string expected/);
190+
should(function () { kuzzle.dataCollectionFactory({foo: 'bar'}); }).throw(/string expected/);
191+
should(function () { kuzzle.dataCollectionFactory({foo: 'bar'}, 'foo'); }).throw(/string expected/);
192+
should(function () { kuzzle.dataCollectionFactory('foo', {foo: 'bar'}); }).throw(/string expected/);
193+
should(function () { kuzzle.dataCollectionFactory(['bar']); }).throw(/string expected/);
194+
should(function () { kuzzle.dataCollectionFactory('foo', ['bar']); }).throw(/string expected/);
195+
should(function () { kuzzle.dataCollectionFactory(['bar'], 'foo'); }).throw(/string expected/);
196+
});
197+
181198
it('should throw an error if the kuzzle instance has been invalidated', function () {
182199
kuzzle.disconnect();
183200
should(function () { kuzzle.dataCollectionFactory('foo'); }).throw(Error);
@@ -204,10 +221,6 @@ describe('Kuzzle methods', function () {
204221
collection = kuzzle.dataCollectionFactory('foo');
205222
should(collection).be.instanceof(KuzzleDataCollection);
206223
should(collection.index).be.eql(defaultIndex);
207-
208-
collection = kuzzle.dataCollectionFactory('foo', {some: 'headers'});
209-
should(collection).be.instanceof(KuzzleDataCollection);
210-
should(collection.index).be.eql(defaultIndex);
211224
});
212225

213226
it('should throw an error if no index is provided and no default index has been set', function (done) {

0 commit comments

Comments
 (0)