Skip to content

Commit e379b23

Browse files
authored
Merge pull request soumak77#92 from Storr-co/firestore-add-getAll
Implement firestore.getAll mock
2 parents 11f67c5 + 1ac76b2 commit e379b23

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/firestore.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ MockFirestore.prototype.toString = function () {
5757
return this.path;
5858
};
5959

60+
MockFirestore.prototype.getAll = function(/* ...docs */) {
61+
var docs = Array.from(arguments);
62+
return Promise.all(
63+
docs.map(function(doc) {
64+
return doc.get();
65+
})
66+
);
67+
};
68+
6069
MockFirestore.prototype.runTransaction = function(transFunc) {
6170
var batch = this.batch();
6271
batch.get = function(doc) {

test/unit/firestore.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,26 @@ describe('MockFirestore', function () {
248248
});
249249
});
250250
});
251+
252+
describe('#getAll', function() {
253+
it('gets the value of all passed documents', function() {
254+
var doc1 = db.doc('doc1');
255+
var doc2 = db.doc('doc2');
256+
var doc3 = db.doc('doc3');
257+
258+
doc1.set({value: 1});
259+
doc2.set({value: 2});
260+
261+
var getAll = db
262+
.getAll(doc1, doc2, doc3);
263+
264+
db.flush();
265+
266+
return getAll.then(function(snaps) {
267+
expect(snaps[0].data()).to.deep.equal({value: 1});
268+
expect(snaps[1].data()).to.deep.equal({value: 2});
269+
expect(snaps[2].exists).to.equal(false);
270+
});
271+
});
272+
});
251273
});

0 commit comments

Comments
 (0)