Skip to content

Commit 38eb62e

Browse files
author
David Bengsch
authored
Merge pull request #96 from kuzzleio/fix-develop-95-empty-mapping
fix #95: handle empty mappings
2 parents 61f1960 + d7047e4 commit 38eb62e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/kuzzleDataMapping.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
111111
if (res.result[self.collection.index]) {
112112
if (res.result[self.collection.index].mappings[self.collection.collection]) {
113113
self.mapping = res.result[self.collection.index].mappings[self.collection.collection].properties;
114+
115+
// Mappings can be empty. The mapping property should never be "undefined"
116+
if (self.mapping === undefined) {
117+
self.mapping = {};
118+
}
114119
} else {
115120
return cb ? cb(new Error('No mapping found for collection ' + self.collection.collection)) : false;
116121
}

test/kuzzleDataMapping/methods.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ describe('KuzzleDataMapping methods', function () {
236236
done();
237237
});
238238
});
239+
240+
it('should return an empty mapping if the stored mapping is empty', done => {
241+
var mapping = new KuzzleDataMapping(dataCollection);
242+
243+
result = { result: {bar: { mappings: { foo: {}}}}};
244+
245+
mapping.refresh((err, res) => {
246+
should(emitted).be.true();
247+
should(err).be.null();
248+
should(res).be.exactly(mapping);
249+
should(res.mapping).be.empty().and.not.be.undefined();
250+
done();
251+
});
252+
});
239253
});
240254

241255
describe('#set', function () {

0 commit comments

Comments
 (0)