Skip to content

Commit 3ef50fa

Browse files
authored
fix(getSettings): allow empty call (#664)
1 parent 08fd028 commit 3ef50fa

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,15 @@ Index.prototype.clearIndex = function(callback) {
608608
* @param opts.advanced get more settings like nbShards (useful for Enterprise)
609609
* @param callback (optional) the result callback called with two arguments
610610
* error: null or Error('message')
611-
* content: the settings object or the error message if a failure occured
611+
* content: the settings object or the error message if a failure occurred
612612
*/
613613
Index.prototype.getSettings = function(opts, callback) {
614-
if (arguments.length === 1 || typeof opts === 'function') {
615-
callback = opts;
616-
opts = {};
614+
if (arguments.length < 2) {
615+
if (typeof opts === 'function') {
616+
callback = opts;
617+
opts = {};
618+
}
619+
opts = opts || {};
617620
}
618621

619622
var indexName = encodeURIComponent(this.indexName);

test/run-integration.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ _.bindAll(index);
4848
test('index.clearIndex', clearIndex);
4949
if (canPUT) {
5050
test('index.setSettings', setSettings);
51+
test('index.getSettings', getSettings);
5152
}
5253
test('index.saveObjects', saveObjects);
5354
if (canPUT) {
@@ -137,6 +138,20 @@ function setSettings(t) {
137138
.then(noop, _.bind(t.error, t));
138139
}
139140

141+
function getSettings(t) {
142+
t.plan(2);
143+
144+
index
145+
.setSettings({attributesForFaceting: ['searchable(category)']})
146+
.then(function() {return index.getSettings({advanced: 1});})
147+
.then(get('attributesForFaceting'))
148+
.then(_.partialRight(t.deepEqual, ['searchable(category)'], 'Settings were get (advanced)'))
149+
.then(index.getSettings)
150+
.then(get('attributesForFaceting'))
151+
.then(_.partialRight(t.deepEqual, ['searchable(category)'], 'Settings were get'))
152+
.then(noop, _.bind(t.error, t));
153+
}
154+
140155
function searchForFacetValues(t) {
141156
t.plan(1);
142157

0 commit comments

Comments
 (0)