Skip to content

Commit 31253d8

Browse files
committed
implement firestore.getAll mock
1 parent f45f6e3 commit 31253d8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,25 @@ describe('MockFirestore', function () {
186186
db.flush();
187187
});
188188
});
189+
190+
describe('getAll', function() {
191+
it('', function() {
192+
var doc1 = db.doc('doc1');
193+
var doc2 = db.doc('doc2');
194+
var doc3 = db.doc('doc3');
195+
196+
db.autoFlush();
197+
198+
doc1.set({value: 1});
199+
doc2.set({value: 2});
200+
201+
return db
202+
.getAll(doc1, doc2, doc3)
203+
.then(function(snaps) {
204+
expect(snaps[0].data()).to.deep.equal({value: 1});
205+
expect(snaps[1].data()).to.deep.equal({value: 2});
206+
expect(snaps[2].exists).to.equal(false);
207+
});
208+
});
209+
});
189210
});

0 commit comments

Comments
 (0)