diff --git a/android/build.gradle b/android/build.gradle index ece1ef74..7010bfdd 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.firebaseVersion = '11.2.0' + ext.firebaseVersion = '11.3.0' repositories { jcenter() } @@ -82,12 +82,12 @@ dependencies { compile "com.google.android.gms:play-services-base:$firebaseVersion" compile "com.google.firebase:firebase-core:$firebaseVersion" compile "com.google.firebase:firebase-config:$firebaseVersion" - compile "com.google.firebase:firebase-auth:11.3.0" + compile "com.google.firebase:firebase-auth:$firebaseVersion" compile "com.google.firebase:firebase-database:$firebaseVersion" compile "com.google.firebase:firebase-storage:$firebaseVersion" compile "com.google.firebase:firebase-messaging:$firebaseVersion" compile "com.google.firebase:firebase-crash:$firebaseVersion" compile "com.google.firebase:firebase-perf:$firebaseVersion" compile "com.google.firebase:firebase-ads:$firebaseVersion" - compile 'com.google.firebase:firebase-firestore:11.3.0' + compile "com.google.firebase:firebase-firestore:$firebaseVersion" } diff --git a/android/src/main/java/io/invertase/firebase/firestore/FirestoreSerialize.java b/android/src/main/java/io/invertase/firebase/firestore/FirestoreSerialize.java index 7fc04663..3bcb84ec 100644 --- a/android/src/main/java/io/invertase/firebase/firestore/FirestoreSerialize.java +++ b/android/src/main/java/io/invertase/firebase/firestore/FirestoreSerialize.java @@ -44,9 +44,7 @@ public class FirestoreSerialize { WritableMap queryMap = Arguments.createMap(); List documentChanges = querySnapshot.getDocumentChanges(); - if (!documentChanges.isEmpty()) { - queryMap.putArray(KEY_CHANGES, documentChangesToWritableArray(documentChanges)); - } + queryMap.putArray(KEY_CHANGES, documentChangesToWritableArray(documentChanges)); // documents WritableArray documents = Arguments.createArray(); diff --git a/android/src/main/java/io/invertase/firebase/firestore/RNFirebaseFirestore.java b/android/src/main/java/io/invertase/firebase/firestore/RNFirebaseFirestore.java index d3fc6883..382f1708 100644 --- a/android/src/main/java/io/invertase/firebase/firestore/RNFirebaseFirestore.java +++ b/android/src/main/java/io/invertase/firebase/firestore/RNFirebaseFirestore.java @@ -216,8 +216,8 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule { @Override public Map getConstants() { final Map constants = new HashMap<>(); - constants.put("deleteFieldValue", FieldValue.delete()); - constants.put("serverTimestampFieldValue", FieldValue.serverTimestamp()); + constants.put("deleteFieldValue", FieldValue.delete().toString()); + constants.put("serverTimestampFieldValue", FieldValue.serverTimestamp().toString()); return constants; } } diff --git a/lib/firebase-app.js b/lib/firebase-app.js index 7e48bb24..f4eb69e4 100644 --- a/lib/firebase-app.js +++ b/lib/firebase-app.js @@ -12,6 +12,7 @@ import RemoteConfig from './modules/config'; import Storage, { statics as StorageStatics } from './modules/storage'; import Database, { statics as DatabaseStatics } from './modules/database'; import Messaging, { statics as MessagingStatics } from './modules/messaging'; +import Firestore, { statics as FirestoreStatics } from './modules/firestore'; const FirebaseCoreModule = NativeModules.RNFirebase; @@ -32,6 +33,7 @@ export default class FirebaseApp { this.config = this._staticsOrModuleInstance({}, RemoteConfig); this.crash = this._staticsOrModuleInstance({}, Crash); this.database = this._staticsOrModuleInstance(DatabaseStatics, Database); + this.firestore = this._staticsOrModuleInstance(FirestoreStatics, Firestore); this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging); this.perf = this._staticsOrModuleInstance({}, Performance); this.storage = this._staticsOrModuleInstance(StorageStatics, Storage); diff --git a/lib/firebase.js b/lib/firebase.js index b31352f5..c67b4f8f 100644 --- a/lib/firebase.js +++ b/lib/firebase.js @@ -20,6 +20,7 @@ import RemoteConfig from './modules/config'; import Storage, { statics as StorageStatics } from './modules/storage'; import Database, { statics as DatabaseStatics } from './modules/database'; import Messaging, { statics as MessagingStatics } from './modules/messaging'; +import Firestore, { statics as FirestoreStatics } from './modules/firestore'; const FirebaseCoreModule = NativeModules.RNFirebase; @@ -47,6 +48,7 @@ class FirebaseCore { this.config = this._appNamespaceOrStatics({}, RemoteConfig); this.crash = this._appNamespaceOrStatics({}, Crash); this.database = this._appNamespaceOrStatics(DatabaseStatics, Database); + this.firestore = this._appNamespaceOrStatics(FirestoreStatics, Firestore); this.messaging = this._appNamespaceOrStatics(MessagingStatics, Messaging); this.perf = this._appNamespaceOrStatics(DatabaseStatics, Performance); this.storage = this._appNamespaceOrStatics(StorageStatics, Storage); diff --git a/lib/utils/ModuleBase.js b/lib/utils/ModuleBase.js index d2c58cf5..127050f9 100644 --- a/lib/utils/ModuleBase.js +++ b/lib/utils/ModuleBase.js @@ -13,6 +13,7 @@ const logs = {}; const MULTI_APP_MODULES = [ 'auth', 'database', + 'firestore', 'storage', ]; diff --git a/tests/android/app/build.gradle b/tests/android/app/build.gradle index 347d6988..ec316968 100644 --- a/tests/android/app/build.gradle +++ b/tests/android/app/build.gradle @@ -71,7 +71,7 @@ android { } } -project.ext.firebaseVersion = '11.2.0' +project.ext.firebaseVersion = '11.3.0' dependencies { // compile(project(':react-native-firebase')) { @@ -82,7 +82,6 @@ dependencies { compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.google.android.gms:play-services-base:$firebaseVersion" compile "com.google.firebase:firebase-ads:$firebaseVersion" - compile "com.google.firebase:firebase-ads:$firebaseVersion" compile "com.google.firebase:firebase-auth:$firebaseVersion" compile "com.google.firebase:firebase-config:$firebaseVersion" compile "com.google.firebase:firebase-core:$firebaseVersion" @@ -91,6 +90,7 @@ dependencies { compile "com.google.firebase:firebase-messaging:$firebaseVersion" compile "com.google.firebase:firebase-perf:$firebaseVersion" compile "com.google.firebase:firebase-storage:$firebaseVersion" + compile "com.google.firebase:firebase-firestore:$firebaseVersion" compile "com.android.support:appcompat-v7:26.0.1" compile "com.facebook.react:react-native:+" // From node_modules } diff --git a/tests/android/app/google-services.json b/tests/android/app/google-services.json index 30a94c5d..35ae2548 100644 --- a/tests/android/app/google-services.json +++ b/tests/android/app/google-services.json @@ -1,27 +1,30 @@ { "project_info": { - "project_number": "305229645282", - "firebase_url": "https://rnfirebase-b9ad4.firebaseio.com", - "project_id": "rnfirebase-b9ad4", - "storage_bucket": "rnfirebase-b9ad4.appspot.com" + "project_number": "17067372085", + "firebase_url": "https://rnfirebase-5579a.firebaseio.com", + "project_id": "rnfirebase", + "storage_bucket": "rnfirebase.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:305229645282:android:efe37851d57e1d05", + "mobilesdk_app_id": "1:17067372085:android:efe37851d57e1d05", "android_client_info": { "package_name": "com.reactnativefirebasedemo" } }, "oauth_client": [ { - "client_id": "305229645282-j8ij0jev9ut24odmlk9i215pas808ugn.apps.googleusercontent.com", + "client_id": "17067372085-n572o9802h9jbv9oo60h53117pk9333k.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyCzbBYFyX8d6VdSu7T4s10IWYbPc-dguwM" + "current_key": "AIzaSyB-z0ytgXRRiClvslJl0tp-KbhDub9o6AM" + }, + { + "current_key": "AIzaSyAJw8mR1fPcEYC9ouZbkCStJufcCQrhmjQ" } ], "services": { diff --git a/tests/android/app/src/main/java/com/reactnativefirebasedemo/MainApplication.java b/tests/android/app/src/main/java/com/reactnativefirebasedemo/MainApplication.java index 68af9279..a9ec77f6 100644 --- a/tests/android/app/src/main/java/com/reactnativefirebasedemo/MainApplication.java +++ b/tests/android/app/src/main/java/com/reactnativefirebasedemo/MainApplication.java @@ -10,6 +10,7 @@ import io.invertase.firebase.auth.RNFirebaseAuthPackage; import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; import io.invertase.firebase.crash.RNFirebaseCrashPackage; import io.invertase.firebase.database.RNFirebaseDatabasePackage; +import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; import io.invertase.firebase.perf.RNFirebasePerformancePackage; import io.invertase.firebase.storage.RNFirebaseStoragePackage; @@ -42,6 +43,7 @@ public class MainApplication extends Application implements ReactApplication { new RNFirebaseRemoteConfigPackage(), new RNFirebaseCrashPackage(), new RNFirebaseDatabasePackage(), + new RNFirebaseFirestorePackage(), new RNFirebaseMessagingPackage(), new RNFirebasePerformancePackage(), new RNFirebaseStoragePackage() diff --git a/tests/android/build.gradle b/tests/android/build.gradle index 59621ffe..32ba1492 100644 --- a/tests/android/build.gradle +++ b/tests/android/build.gradle @@ -6,8 +6,8 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' - classpath 'com.google.gms:google-services:3.1.0' - classpath 'com.google.firebase:firebase-plugins:1.1.0' + classpath 'com.google.gms:google-services:3.1.1' + classpath 'com.google.firebase:firebase-plugins:1.1.1' } } @@ -18,6 +18,7 @@ allprojects { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } + mavenLocal() google() } } diff --git a/tests/src/tests/firestore/collection/index.js b/tests/src/tests/firestore/collection/index.js new file mode 100644 index 00000000..d46d4e9e --- /dev/null +++ b/tests/src/tests/firestore/collection/index.js @@ -0,0 +1,30 @@ +// import docSnapTests from './docSnapTests'; +// import querySnapTests from './querySnapTests'; +// import onSnapshotTests from './onSnapshotTests'; +// import bugTests from './bugTests'; +import whereTests from './whereTests'; + +const testGroups = [ + // onSnapshotTests, + // querySnapTests, + // docSnapTests, + // bugTests, + whereTests, +]; + +function registerTestSuite(testSuite) { + testSuite.beforeEach(async function () { + // todo reset test data + }); + + testSuite.afterEach(async function () { + // todo reset test data + }); + + testGroups.forEach((testGroup) => { + testGroup(testSuite); + }); +} + + +module.exports = registerTestSuite; diff --git a/tests/src/tests/firestore/collection/whereTests.js b/tests/src/tests/firestore/collection/whereTests.js new file mode 100644 index 00000000..9dfe6da7 --- /dev/null +++ b/tests/src/tests/firestore/collection/whereTests.js @@ -0,0 +1,86 @@ +import should from 'should'; + +/** + +Test document structure from fb console: + + baz: true + daz: 123 + foo: "bar" + gaz: 12.1234567 + naz: null + +*/ + +function whereTests({ describe, it, context, firebase }) { + describe('CollectionReference.where()', () => { + context('correctly handles', () => { + it('== boolean values', () => { + return firebase.native.firestore() + .collection('tests') + .where('baz', '==', true) + .get() + .then((querySnapshot) => { + should.equal(querySnapshot.size, 1); + querySnapshot.forEach((documentSnapshot) => { + should.equal(documentSnapshot.data().baz, true); + }); + }); + }); + + it('== string values', () => { + return firebase.native.firestore() + .collection('tests') + .where('foo', '==', 'bar') + .get() + .then((querySnapshot) => { + should.equal(querySnapshot.size, 1); + querySnapshot.forEach((documentSnapshot) => { + should.equal(documentSnapshot.data().foo, 'bar'); + }); + }); + }); + + it('== null values', () => { + return firebase.native.firestore() + .collection('tests') + .where('naz', '==', null) + .get() + .then((querySnapshot) => { + should.equal(querySnapshot.size, 1); + querySnapshot.forEach((documentSnapshot) => { + should.equal(documentSnapshot.data().naz, null); + }); + }); + }); + + it('>= number values', () => { + return firebase.native.firestore() + .collection('tests') + .where('daz', '>=', 123) + .get() + .then((querySnapshot) => { + should.equal(querySnapshot.size, 1); + querySnapshot.forEach((documentSnapshot) => { + should.equal(documentSnapshot.data().daz, 123); + }); + }); + }); + + it('<= float values', () => { + return firebase.native.firestore() + .collection('tests') + .where('gaz', '<=', 12.1234666) + .get() + .then((querySnapshot) => { + should.equal(querySnapshot.size, 1); + querySnapshot.forEach((documentSnapshot) => { + should.equal(documentSnapshot.data().gaz, 12.1234567); + }); + }); + }); + }); + }); +} + +export default whereTests; diff --git a/tests/src/tests/firestore/document/index.js b/tests/src/tests/firestore/document/index.js new file mode 100644 index 00000000..d6949789 --- /dev/null +++ b/tests/src/tests/firestore/document/index.js @@ -0,0 +1,22 @@ +// import whereTests from './whereTests'; + +const testGroups = [ + // whereTests, +]; + +function registerTestSuite(testSuite) { + testSuite.beforeEach(async function () { + // todo reset test data + }); + + testSuite.afterEach(async function () { + // todo reset test data + }); + + testGroups.forEach((testGroup) => { + testGroup(testSuite); + }); +} + + +module.exports = registerTestSuite; diff --git a/tests/src/tests/firestore/index.js b/tests/src/tests/firestore/index.js new file mode 100644 index 00000000..20990491 --- /dev/null +++ b/tests/src/tests/firestore/index.js @@ -0,0 +1,19 @@ +import firebase from '../../firebase'; +import TestSuite from '../../../lib/TestSuite'; + +/* + Test suite files + */ +import collectionTestGroups from './collection/index'; +import documentTestGroups from './document/index'; + +const suite = new TestSuite('Firestore', 'firebase.firestore()', firebase); + +/* + Register tests with test suite + */ + +suite.addTests(documentTestGroups); +suite.addTests(collectionTestGroups); + +export default suite; diff --git a/tests/src/tests/index.js b/tests/src/tests/index.js index 85d1a390..5c4d2bf2 100644 --- a/tests/src/tests/index.js +++ b/tests/src/tests/index.js @@ -1,26 +1,28 @@ import { setSuiteStatus, setTestStatus } from '../actions/TestActions'; -import analytics from './analytics/index'; -import crash from './crash/index'; -import core from './core/index'; -import database from './database/index'; -import messaging from './messaging/index'; -import storage from './storage/index'; -import auth from './auth/index'; -import config from './config/index'; -import performance from './perf/index'; -import admob from './admob/index'; +import analytics from './analytics'; +import crash from './crash'; +import core from './core'; +import database from './database'; +import messaging from './messaging'; +import storage from './storage'; +import auth from './auth'; +import config from './config'; +import performance from './perf'; +import admob from './admob'; +import firestore from './firestore'; const testSuiteInstances = [ - database, - auth, - analytics, - messaging, - crash, - core, - storage, - config, - performance, admob, + analytics, + auth, + config, + core, + crash, + database, + firestore, + messaging, + performance, + storage, ]; /*