Skip to content

Commit 4218bd4

Browse files
committed
Update Firestore.runTransaction to resolve promise with passed function's value
See https://cloud.google.com/nodejs/docs/reference/firestore/0.14.x/Firestore#runTransaction > If the transaction completed successfully or was explicitly aborted (by the updateFunction returning a failed Promise), the Promise returned by the updateFunction will be returned here
1 parent f45f6e3 commit 4218bd4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/firestore.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ MockFirestore.prototype.runTransaction = function(transFunc) {
6363
return doc.get();
6464
};
6565
return new Promise(function(resolve, reject) {
66-
transFunc(batch).then(function() {
67-
batch.commit().then(resolve).catch(reject);
66+
Promise.resolve(transFunc(batch)).then(function(value) {
67+
batch
68+
.commit()
69+
.then(function () {
70+
resolve(value);
71+
})
72+
.catch(reject);
6873
}).catch(reject);
6974
});
7075
};

test/unit/firestore.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ describe('MockFirestore', function () {
125125
transaction.update(db.doc('doc'), {
126126
name: 'abc'
127127
});
128+
return 'cba';
128129
});
129-
}).then(function() {
130+
}).then(function(transactionReturn) {
130131
db.doc('doc').get().then(function(doc2) {
131132
expect(doc2.get('name')).to.equal('abc');
133+
expect(transactionReturn).to.equal('cba');
132134
done();
133135
}).catch(done);
134136
}).catch(done);

0 commit comments

Comments
 (0)