Skip to content

Commit 19c14b6

Browse files
committed
Skip collections that has no documents
1 parent 1a22ffa commit 19c14b6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/firestore-document.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ MockFirestoreDocument.prototype.getCollections = function () {
175175
return new Promise(function (resolve, reject) {
176176
self._defer('getCollections', _.toArray(arguments), function () {
177177
if (err === null) {
178-
resolve(_.toArray(this.children));
178+
var collections = _.toArray(this.children);
179+
// Filter out empty collections
180+
collections = _.filter(collections, function (collection) {
181+
return !_.isEmpty(collection.data);
182+
});
183+
resolve(collections);
179184
} else {
180185
reject(err);
181186
}

test/unit/firestore-document.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,29 @@ describe('MockFirestoreDocument', function () {
391391
});
392392

393393
context('when not present', function () {
394-
it('returns deeply nested collections of document', function (done) {
394+
it('returns empty list of collections', function (done) {
395395
db.doc('not-existing').getCollections().then(function (colRefs) {
396396
expect(colRefs).to.be.an('array');
397397
expect(colRefs).to.have.length(0);
398398
done();
399399
});
400400
db.flush();
401401
});
402+
403+
it('skips collections that has no documents', function (done) {
404+
db.doc('doc/subcol/subcol-doc').delete();
405+
db.doc('doc/subcol2/subcol-doc').delete();
406+
db.doc('doc/subcol/subcol-doc/deep-col/deep-doc').delete();
407+
db.doc('doc/subcol/subcol-doc/deep-col2/deep-doc').delete();
408+
db.flush();
409+
410+
db.doc('doc').getCollections().then(function (colRefs) {
411+
expect(colRefs).to.be.an('array');
412+
expect(colRefs).to.have.length(0);
413+
done();
414+
});
415+
db.flush();
416+
});
402417
});
403418
});
404419
});

0 commit comments

Comments
 (0)