diff --git a/bridge/e2e/firestore/documentSnapshot.e2e.js b/bridge/e2e/firestore/documentSnapshot.e2e.js index 666e3fb7..73d88c12 100644 --- a/bridge/e2e/firestore/documentSnapshot.e2e.js +++ b/bridge/e2e/firestore/documentSnapshot.e2e.js @@ -24,14 +24,60 @@ describe('firestore()', () => { }); }); - describe('get()', () => { - it('using a dot notated path string', async () => { + describe('metadata', () => { + it('returns an object of meta data', async () => { + const { testCollectionDoc } = TestHelpers.firestore; + const { metadata } = await testCollectionDoc().get(); + metadata.should.be.an.Object(); + metadata.should.have.property('hasPendingWrites'); + metadata.should.have.property('fromCache'); + metadata.hasPendingWrites.should.be.a.Boolean(); + metadata.fromCache.should.be.a.Boolean(); + }); + }); + + describe('exists', () => { + it('returns a boolean', async () => { + const { testCollectionDoc } = TestHelpers.firestore; + const { exists } = await testCollectionDoc().get(); + exists.should.be.a.Boolean(); + exists.should.be.true(); + }); + }); + + describe('data()', () => { + it('returns document data', async () => { + // additionally tests context binding not lost during destructuring const { testCollectionDoc } = TestHelpers.firestore; const snapshot = await testCollectionDoc().get(); + const { data } = snapshot; + + snapshot.data.should.be.a.Function(); + data.should.be.a.Function(); + + snapshot.data().should.be.a.Object(); + data().should.be.a.Object(); + + snapshot.data().baz.should.be.true(); + data().baz.should.be.true(); + }); + }); + + describe('get()', () => { + it('using a dot notated path string', async () => { + // additionally tests context binding not lost during destructuring + const { testCollectionDoc } = TestHelpers.firestore; + const snapshot = await testCollectionDoc().get(); + const { get } = snapshot; should.equal(snapshot.get('foo'), 'bar'); + should.equal(get('foo'), 'bar'); + should.equal(snapshot.get('object.daz'), 123); + should.equal(get('object.daz'), 123); + should.equal(snapshot.get('nonexistent.object'), undefined); + should.equal(get('nonexistent.object'), undefined); }); it('using a FieldPath instance', async () => { diff --git a/lib/modules/firestore/DocumentSnapshot.js b/lib/modules/firestore/DocumentSnapshot.js index aae8dc7e..7fbe760a 100644 --- a/lib/modules/firestore/DocumentSnapshot.js +++ b/lib/modules/firestore/DocumentSnapshot.js @@ -55,15 +55,13 @@ export default class DocumentSnapshot { return this._ref; } - data(): Object | void { - return this._data; - } + data = (): Object | void => this._data; - get(fieldPath: string | FieldPath): any { + get = (fieldPath: string | FieldPath): any => { if (fieldPath instanceof FieldPath) { return extractFieldPathData(this._data, fieldPath._segments); } return deepGet(this._data, fieldPath, '.'); - } + }; }