From a1773fddc7b1f930ce908801e30a4068b33fecb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rjan=20Fors?= Date: Fri, 1 Mar 2019 15:41:10 +0100 Subject: [PATCH 1/2] Require at least one argument in getAll This mimics the argument validator found in the Firestore client. --- src/firestore.js | 3 +++ test/unit/firestore.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/firestore.js b/src/firestore.js index 6cfee61f..df7d8297 100644 --- a/src/firestore.js +++ b/src/firestore.js @@ -59,6 +59,9 @@ 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.'); + } return Promise.all( docs.map(function(doc) { return doc.get(); diff --git a/test/unit/firestore.js b/test/unit/firestore.js index 150034b5..00a42d24 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'); From 7354047a769ba9ff49fec5e48c42f5ea6fb24bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96rjan=20Fors?= Date: Fri, 1 Mar 2019 15:48:47 +0100 Subject: [PATCH 2/2] Ignore any ReadOptions passed to getAll --- src/firestore.js | 4 ++++ test/unit/firestore.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/firestore.js b/src/firestore.js index df7d8297..78a1fa30 100644 --- a/src/firestore.js +++ b/src/firestore.js @@ -62,6 +62,10 @@ MockFirestore.prototype.getAll = function(/* ...docs */) { 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 00a42d24..13b42bed 100644 --- a/test/unit/firestore.js +++ b/test/unit/firestore.js @@ -284,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}); + }); + }); }); });