Skip to content
Closed
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
7 changes: 7 additions & 0 deletions src/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ MockFirestore.prototype.toString = function () {

MockFirestore.prototype.getAll = function(/* ...docs */) {
var docs = Array.from(arguments);
if (_.isEmpty(docs)) {
throw new Error('Firestore.getAll: Function requires at least 1 argument.');
}
// ReadOptions is not honored but at least ignored
if (!_.isUndefined(docs[docs.length - 1].fieldMask)) {
docs.pop();
}
return Promise.all(
docs.map(function(doc) {
return doc.get();
Expand Down
20 changes: 20 additions & 0 deletions test/unit/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ describe('MockFirestore', function () {
});

describe('#getAll', function() {
it('requires one argument', function() {
expect(db.getAll).to.throw('Function requires at least 1 argument');
});
it('gets the value of all passed documents', function() {
var doc1 = db.doc('doc1');
var doc2 = db.doc('doc2');
Expand All @@ -281,5 +284,22 @@ describe('MockFirestore', function () {
expect(snaps[2].exists).to.equal(false);
});
});
it('gets the value of all passed documents honoring the read options', function() {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Honoring' is definitely not the right word here. Did you mean 'Ignoring'?

var doc1 = db.doc('doc1');
var doc2 = db.doc('doc2');

doc1.set({value: 1});
doc2.set({value: 2});

var getAll = db
.getAll(doc1, doc2, { fieldMask: ['value'] });

db.flush();

return getAll.then(function(snaps) {
expect(snaps[0].data()).to.deep.equal({value: 1});
expect(snaps[1].data()).to.deep.equal({value: 2});
});
});
});
});