diff --git a/src/firestore.js b/src/firestore.js index 6cfee61f..78a1fa30 100644 --- a/src/firestore.js +++ b/src/firestore.js @@ -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(); diff --git a/test/unit/firestore.js b/test/unit/firestore.js index 150034b5..13b42bed 100644 --- a/test/unit/firestore.js +++ b/test/unit/firestore.js @@ -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'); @@ -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() { + 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}); + }); + }); }); });