Skip to content

Commit 1e845d1

Browse files
committed
fixes issue #81
1 parent 114c603 commit 1e845d1

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/kuzzle.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -873,20 +873,19 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
873873
* Create a new instance of a KuzzleDataCollection object.
874874
* If no index is specified, takes the default index.
875875
*
876-
* @param {string} [index] - The name of the data index containing the data collection
877876
* @param {string} collection - The name of the data collection you want to manipulate
877+
* @param {string} [index] - The name of the data index containing the data collection
878878
* @returns {object} A KuzzleDataCollection instance
879879
*/
880-
Kuzzle.prototype.dataCollectionFactory = function(index, collection) {
880+
Kuzzle.prototype.dataCollectionFactory = function(collection, index) {
881881
this.isValid();
882882

883-
if (arguments.length === 1) {
884-
collection = arguments[0];
885-
index = this.defaultIndex;
886-
}
887-
888883
if (!index) {
889-
throw new Error('Unable to create a new data collection object: no index specified');
884+
if (!this.defaultIndex) {
885+
throw new Error('Unable to create a new data collection object: no index specified');
886+
}
887+
888+
index = this.defaultIndex;
890889
}
891890

892891
if (typeof index !== 'string') {

test/kuzzle/methods.test.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ describe('Kuzzle methods', function () {
181181
it('should throw an error if arguments are not strings', () => {
182182
kuzzle.defaultIndex = 'foobar';
183183
should(function () { kuzzle.dataCollectionFactory(undefined); }).throw(/string expected/);
184-
should(function () { kuzzle.dataCollectionFactory('foo', undefined); }).throw(/string expected/);
184+
should(function () { kuzzle.dataCollectionFactory(undefined, 'foo'); }).throw(/string expected/);
185185
should(function () { kuzzle.dataCollectionFactory(null); }).throw(/string expected/);
186-
should(function () { kuzzle.dataCollectionFactory('foo', null); }).throw(/string expected/);
186+
should(function () { kuzzle.dataCollectionFactory(null, 'foo'); }).throw(/string expected/);
187187
should(function () { kuzzle.dataCollectionFactory(123); }).throw(/string expected/);
188188
should(function () { kuzzle.dataCollectionFactory(123, 'foo'); }).throw(/string expected/);
189189
should(function () { kuzzle.dataCollectionFactory('foo', 123); }).throw(/string expected/);
@@ -203,13 +203,13 @@ describe('Kuzzle methods', function () {
203203
it('should create and store the data collection instance if needed', function () {
204204
var collection = kuzzle.dataCollectionFactory('foo', 'bar');
205205

206-
should(kuzzle.collections['foo']['bar']).not.be.undefined().and.be.instanceof(KuzzleDataCollection);
206+
should(kuzzle.collections['bar']['foo']).not.be.undefined().and.be.instanceof(KuzzleDataCollection);
207207
should(collection).be.instanceof(KuzzleDataCollection);
208208
});
209209

210210
it('should simply pull the collection from the collection history if reinvoked', function () {
211211
kuzzle.collections['foo'] = { bar: 'qux'};
212-
should(kuzzle.dataCollectionFactory('foo', 'bar')).be.a.String().and.be.exactly('qux');
212+
should(kuzzle.dataCollectionFactory('bar', 'foo')).be.a.String().and.be.exactly('qux');
213213
});
214214

215215
it('should use the default index if no index is provided', function () {
@@ -223,14 +223,8 @@ describe('Kuzzle methods', function () {
223223
should(collection.index).be.eql(defaultIndex);
224224
});
225225

226-
it('should throw an error if no index is provided and no default index has been set', function (done) {
227-
try {
228-
kuzzle.dataCollectionFactory('foo');
229-
done(new Error('Should have thrown an error'));
230-
}
231-
catch (e) {
232-
done();
233-
}
226+
it('should throw an error if no index is provided and no default index has been set', () => {
227+
should(function () { kuzzle.dataCollectionFactory('foo'); }).throw(/no index specified/);
234228
});
235229
});
236230

0 commit comments

Comments
 (0)