From a3f5b01d6735a5cf9215b01f47744e3bb0333b33 Mon Sep 17 00:00:00 2001 From: Salakar Date: Thu, 12 Apr 2018 12:54:29 +0100 Subject: [PATCH] [tests][firestore] start of migrating firestore tests --- bridge/e2e/firestore/documentSnapshot.e2e.js | 42 ++++++++++++++++++++ bridge/e2e/firestore/fieldPath.e2e.js | 34 ++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 bridge/e2e/firestore/documentSnapshot.e2e.js diff --git a/bridge/e2e/firestore/documentSnapshot.e2e.js b/bridge/e2e/firestore/documentSnapshot.e2e.js new file mode 100644 index 00000000..7ae3746b --- /dev/null +++ b/bridge/e2e/firestore/documentSnapshot.e2e.js @@ -0,0 +1,42 @@ +describe.only('firestore()', () => { + describe('DocumentSnapshot', () => { + before(async () => { + await TestHelpers.firestore.resetTestCollectionDoc(); + }); + + describe('get()', () => { + it('using a dot notated path string', async () => { + const { testCollectionDoc } = TestHelpers.firestore; + const snapshot = await testCollectionDoc().get(); + + should.equal(snapshot.get('foo'), 'bar'); + should.equal(snapshot.get('object.daz'), 123); + should.equal(snapshot.get('nonexistent.object'), undefined); + }); + + it('using a FieldPath instance', async () => { + const { testCollectionDoc } = TestHelpers.firestore; + const snapshot = await testCollectionDoc().get(); + + should.equal(snapshot.get('foo'), 'bar'); + + should.equal( + snapshot.get(new firebase.firestore.FieldPath('foo')), + 'bar' + ); + + should.equal( + snapshot.get(new firebase.firestore.FieldPath('object', 'daz')), + 123 + ); + + should.equal( + snapshot.get( + new firebase.firestore.FieldPath('nonexistent', 'object') + ), + undefined + ); + }); + }); + }); +}); diff --git a/bridge/e2e/firestore/fieldPath.e2e.js b/bridge/e2e/firestore/fieldPath.e2e.js index e69de29b..40171d58 100644 --- a/bridge/e2e/firestore/fieldPath.e2e.js +++ b/bridge/e2e/firestore/fieldPath.e2e.js @@ -0,0 +1,34 @@ +describe('firestore()', () => { + describe('FieldPath', () => { + before(async () => { + await TestHelpers.firestore.resetTestCollectionDoc(); + }); + + it('documentId() should return a FieldPath', () => { + const documentId = firebase.firestore.FieldPath.documentId(); + documentId.should.be.instanceof(firebase.firestore.FieldPath); + }); + + it('should allow getting values via documentSnapshot.get(FieldPath)', async () => { + const { testCollectionDoc } = TestHelpers.firestore; + const snapshot = await testCollectionDoc().get(); + + should.equal(snapshot.get('foo'), 'bar'); + + should.equal( + snapshot.get(new firebase.firestore.FieldPath('foo')), + 'bar' + ); + + should.equal( + snapshot.get(new firebase.firestore.FieldPath('object', 'daz')), + 123 + ); + + should.equal( + snapshot.get(new firebase.firestore.FieldPath('nonexistent', 'object')), + undefined + ); + }); + }); +});