Skip to content

Ignore ReadOptions on getAll #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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() {
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});
});
});
});
});