From cd911d2442b86161f6739456da3a7a5497443ac8 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Tue, 7 Nov 2017 12:49:59 +0000 Subject: [PATCH 1/2] [tests][firestore] Add test for onSnapshot with a query applied --- tests/ios/Podfile.lock | 14 +++---- .../firestore/collectionReferenceTests.js | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index d324ae75..2d2e60bb 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -150,7 +150,7 @@ PODS: - React/Core - React/fishhook - React/RCTBlob - - RNFirebase (3.1.0-alpha.1): + - RNFirebase (3.1.0): - React - yoga (0.49.1.React) @@ -176,11 +176,11 @@ DEPENDENCIES: EXTERNAL SOURCES: React: - :path: ../node_modules/react-native + :path: "../node_modules/react-native" RNFirebase: - :path: ./../../ + :path: "./../../" yoga: - :path: ../node_modules/react-native/ReactCommon/yoga + :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: BoringSSL: 19083b821ef3ae0f758fae15482e183003b1e265 @@ -199,7 +199,7 @@ SPEC CHECKSUMS: FirebaseStorage: 0cca42d9b889a0227c3a50121f45a4469fc9eb27 Google-Mobile-Ads-SDK: ed8004a7265b424568dc84f3d2bbe3ea3fff958f GoogleToolboxForMac: 8e329f1b599f2512c6b10676d45736bcc2cbbeb0 - gRPC: 07788969b862af21491908f82b83d17ac08c94cd + gRPC: '07788969b862af21491908f82b83d17ac08c94cd' gRPC-Core: f707ade59c559fe718e27713189607d03b15f571 gRPC-ProtoRPC: de7505e493a9d1b6b96c8ea8f976c73100fdf53f gRPC-RxLibrary: 17b9699beb0a838b95b57832244f9ead18e66777 @@ -208,9 +208,9 @@ SPEC CHECKSUMS: nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 03eef2ee0b674770735cf79d9c4d3659cf6908e8 React: cf892fb84b7d06bf5fea7f328e554c6dcabe85ee - RNFirebase: 0467ca8122b9257acd7f1bb6de1670d9fd51cede + RNFirebase: a76befd482c5e84df7f69893358abda498ee9f76 yoga: 3abf02d6d9aeeb139b4c930eb1367feae690a35a PODFILE CHECKSUM: b5674be55653f5dda937c8b794d0479900643d45 -COCOAPODS: 1.3.1 +COCOAPODS: 1.2.1 diff --git a/tests/src/tests/firestore/collectionReferenceTests.js b/tests/src/tests/firestore/collectionReferenceTests.js index f61fcd6b..ed2073a9 100644 --- a/tests/src/tests/firestore/collectionReferenceTests.js +++ b/tests/src/tests/firestore/collectionReferenceTests.js @@ -737,6 +737,43 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft }); }); + context('onSnapshot()', () => { + it('gets called correctly', async () => { + const collectionRef = collectionTests.orderBy('timestamp').endAt(new Date(2017, 2, 12, 10, 0, 0)); + const newDocValue = { ...COL_1, foo: 'updated' }; + + const callback = sinon.spy(); + + // Test + + let unsubscribe; + await new Promise((resolve2) => { + unsubscribe = collectionRef.onSnapshot((snapshot) => { + callback(snapshot.docs.map(doc => doc.data().daz)); + resolve2(); + }); + }); + + callback.should.be.calledWith([123, 234, 345]); + + const docRef = firebase.native.firestore().doc('collection-tests2/col1'); + await docRef.set(newDocValue); + + await new Promise((resolve2) => { + setTimeout(() => resolve2(), 5); + }); + + // Assertions + + callback.should.be.calledWith([123, 234, 345]); + callback.should.be.calledTwice(); + + // Tear down + + unsubscribe(); + }); + }); + after(() => { return cleanCollection(collectionTests); }); From e6ea5348ff957cd286f768fdada45dac947b5fb4 Mon Sep 17 00:00:00 2001 From: Chris Bianca Date: Tue, 7 Nov 2017 13:15:16 +0000 Subject: [PATCH 2/2] [tests][firestore] Add test cases for limit with onSnapshot --- .../firestore/collectionReferenceTests.js | 50 +++++++++++++++---- tests/src/tests/firestore/index.js | 3 ++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/tests/src/tests/firestore/collectionReferenceTests.js b/tests/src/tests/firestore/collectionReferenceTests.js index ed2073a9..dc7eb3cc 100644 --- a/tests/src/tests/firestore/collectionReferenceTests.js +++ b/tests/src/tests/firestore/collectionReferenceTests.js @@ -500,9 +500,12 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft }); }); }); + }); - it('correctly handles limit', async () => { - const collectionTests = firebase.native.firestore().collection('collection-tests2'); + context('limit', () => { + let collectionTests; + before(async () => { + collectionTests = firebase.native.firestore().collection('collection-tests2'); await Promise.all([ collectionTests.doc('col1').set(COL_1), collectionTests.doc('col2').set({ ...COL_1, daz: 234 }), @@ -510,7 +513,9 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft collectionTests.doc('col4').set({ ...COL_1, daz: 234 }), collectionTests.doc('col5').set({ ...COL_1, daz: 234 }), ]); + }); + it('correctly works with get()', async () => { return collectionTests.limit(3) .get() .then((querySnapshot) => { @@ -518,6 +523,33 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft return cleanCollection(collectionTests); }); }); + + it('correctly works with onSnapshot()', async () => { + const collectionRef = collectionTests.limit(3); + const callback = sinon.spy(); + + // Test + + let unsubscribe; + await new Promise((resolve2) => { + unsubscribe = collectionRef.onSnapshot((snapshot) => { + callback(snapshot.size); + resolve2(); + }); + }); + + // Assertions + + callback.should.be.calledWith(3); + + // Tear down + + unsubscribe(); + }); + + after(() => { + return cleanCollection(collectionTests); + }); }); context('cursors', () => { @@ -526,10 +558,10 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft collectionTests = firebase.native.firestore().collection('collection-tests2'); await Promise.all([ collectionTests.doc('col1').set({ ...COL_1, foo: 'bar0' }), - collectionTests.doc('col2').set({ ...COL_1, foo: 'bar1', daz: 234, timestamp: new Date(2017, 2, 11, 10, 0, 0) }), - collectionTests.doc('col3').set({ ...COL_1, foo: 'bar2', daz: 345, timestamp: new Date(2017, 2, 12, 10, 0, 0) }), - collectionTests.doc('col4').set({ ...COL_1, foo: 'bar3', daz: 456, timestamp: new Date(2017, 2, 13, 10, 0, 0) }), - collectionTests.doc('col5').set({ ...COL_1, foo: 'bar4', daz: 567, timestamp: new Date(2017, 2, 14, 10, 0, 0) }), + collectionTests.doc('col2').set({ ...COL_1, foo: 'bar1', daz: 234, object: { daz: 234 }, timestamp: new Date(2017, 2, 11, 10, 0, 0) }), + collectionTests.doc('col3').set({ ...COL_1, foo: 'bar2', daz: 345, object: { daz: 345 }, timestamp: new Date(2017, 2, 12, 10, 0, 0) }), + collectionTests.doc('col4').set({ ...COL_1, foo: 'bar3', daz: 456, object: { daz: 456 }, timestamp: new Date(2017, 2, 13, 10, 0, 0) }), + collectionTests.doc('col5').set({ ...COL_1, foo: 'bar4', daz: 567, object: { daz: 567 }, timestamp: new Date(2017, 2, 14, 10, 0, 0) }), ]); }); @@ -739,8 +771,8 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft context('onSnapshot()', () => { it('gets called correctly', async () => { - const collectionRef = collectionTests.orderBy('timestamp').endAt(new Date(2017, 2, 12, 10, 0, 0)); - const newDocValue = { ...COL_1, foo: 'updated' }; + const collectionRef = collectionTests.orderBy('object.daz').endAt(345); + const newDocValue = { ...COL_1, object: { daz: 346 } }; const callback = sinon.spy(); @@ -765,7 +797,7 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft // Assertions - callback.should.be.calledWith([123, 234, 345]); + callback.should.be.calledWith([234, 345]); callback.should.be.calledTwice(); // Tear down diff --git a/tests/src/tests/firestore/index.js b/tests/src/tests/firestore/index.js index 502eed95..fea39013 100644 --- a/tests/src/tests/firestore/index.js +++ b/tests/src/tests/firestore/index.js @@ -16,6 +16,9 @@ export const COL_1 = { gaz: 12.1234567, geopoint: new firebase.native.firestore.GeoPoint(0, 0), naz: null, + object: { + daz: 123, + }, timestamp: new Date(2017, 2, 10, 10, 0, 0), };