Skip to content

Commit 314b0a4

Browse files
authored
Adding Firestore.setLogFunction() to the typings; Adding tests (#123)
1 parent d5754a6 commit 314b0a4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ declare namespace admin.firestore {
410410
export import FieldValue = _firestore.FieldValue;
411411
export import Firestore = _firestore.Firestore;
412412
export import GeoPoint = _firestore.GeoPoint;
413+
export import setLogFunction = _firestore.setLogFunction;
413414
}
414415

415416
declare module 'firebase-admin' {

test/integration/firestore.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,33 @@ function test(utils) {
126126
});
127127
}
128128

129-
return Promise.resolve()
129+
function testSetLogFunction() {
130+
const logs = [];
131+
const source = admin.firestore().collection('cities').doc();
132+
return Promise.resolve().then(() => {
133+
admin.firestore.setLogFunction((log) => {
134+
logs.push(log);
135+
})
136+
return source.set({name: 'San Francisco'});
137+
}).then(result => {
138+
return source.delete();
139+
}).then(result => {
140+
utils.assert(
141+
logs.length > 0,
142+
'firestore.setLogFunction()',
143+
'Log function did not update');
144+
}).catch(err => {
145+
utils.logFailure('firestore.setLogFunction()', 'Error while setting log function: ' + err);
146+
});
147+
}
148+
149+
return Promise.resolve()
130150
.then(testFirestore)
131151
.then(testFieldValue)
132152
.then(testFieldPath)
133153
.then(testGeoPoint)
134-
.then(testSetDocumentReference);
154+
.then(testSetDocumentReference)
155+
.then(testSetLogFunction);
135156
}
136157

137158
module.exports = {

test/unit/firebase-namespace.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import {
3636
Firestore,
3737
FieldPath,
3838
FieldValue,
39-
GeoPoint
39+
GeoPoint,
40+
setLogFunction,
4041
} from '@google-cloud/firestore';
4142

4243
chai.should();
@@ -478,5 +479,9 @@ describe('FirebaseNamespace', () => {
478479
it('should return a reference to GeoPoint type', () => {
479480
expect(firebaseNamespace.firestore.GeoPoint).to.be.deep.equal(GeoPoint);
480481
});
482+
483+
it('should return a reference to setLogFunction', () => {
484+
expect(firebaseNamespace.firestore.setLogFunction).to.be.deep.equal(setLogFunction);
485+
});
481486
});
482487
});

0 commit comments

Comments
 (0)