Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/firestore-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ MockFirestoreCollection.prototype.doc = function (path) {
return child;
};

MockFirestoreCollection.prototype.listDocuments = function () {
var err = this._nextErr('listDocuments');
var self = this;
return new Promise(function (resolve, reject) {
self._defer('listDocuments', _.toArray(arguments), function () {
if (err === null) {
var docs = _.map(self.data, function (value, key) {
return self.doc(key);
});
resolve(docs);
} else {
reject(err);
}
});
});
};

MockFirestoreCollection.prototype._hasChild = function (key) {
return _.isObject(this.data) && _.has(this.data, key);
};
Expand Down
27 changes: 27 additions & 0 deletions test/unit/firestore-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,33 @@ describe('MockFirestoreCollection', function () {
]);
});
});
describe('#listDocuments', function () {
it('retrieves all data for existing collection', function(done) {
db.autoFlush();
var keys = Object.keys(require('./data.json').collections);
collection.listDocuments().then(function(refs) {
expect(refs.length).to.equal(6);
refs.forEach(function(ref) {
expect(keys).to.contain(ref.id);
});
done();
}).catch(done);
});

it('retrieves data added to collection', function(done) {
db.autoFlush();
db.collection('group').add({
name: 'test'
});
db.collection('group').listDocuments().then(function(refs) {
expect(refs.length).to.equal(1);
refs[0].get().then(function(doc) {
expect(doc.data().name).to.equal('test');
done();
}).catch(done);
}).catch(done);
});
});

describe('#onSnapshot', function () {
it('returns value after collection is updated', function (done) {
Expand Down