[tests] misc merge

This commit is contained in:
Salakar 2018-03-04 19:05:17 +00:00
commit b3938036b7
9 changed files with 1893 additions and 53920 deletions

File diff suppressed because it is too large Load Diff

236
tests/ios/Podfile.lock Normal file
View File

@ -0,0 +1,236 @@
PODS:
- BoringSSL (9.2):
- BoringSSL/Implementation (= 9.2)
- BoringSSL/Interface (= 9.2)
- BoringSSL/Implementation (9.2):
- BoringSSL/Interface (= 9.2)
- BoringSSL/Interface (9.2)
- Crashlytics (3.9.3):
- Fabric (~> 1.7.2)
- Fabric (1.7.3)
- Firebase/AdMob (4.8.2):
- Firebase/Core
- Google-Mobile-Ads-SDK (= 7.27.0)
- Firebase/Auth (4.8.2):
- Firebase/Core
- FirebaseAuth (= 4.4.2)
- Firebase/Core (4.8.2):
- FirebaseAnalytics (= 4.0.9)
- FirebaseCore (= 4.0.14)
- Firebase/Crash (4.8.2):
- Firebase/Core
- FirebaseCrash (= 2.0.2)
- Firebase/Database (4.8.2):
- Firebase/Core
- FirebaseDatabase (= 4.1.4)
- Firebase/DynamicLinks (4.8.2):
- Firebase/Core
- FirebaseDynamicLinks (= 2.3.2)
- Firebase/Firestore (4.8.2):
- Firebase/Core
- FirebaseFirestore (= 0.10.0)
- Firebase/Messaging (4.8.2):
- Firebase/Core
- FirebaseMessaging (= 2.0.8)
- Firebase/Performance (4.8.2):
- Firebase/Core
- FirebasePerformance (= 1.1.1)
- Firebase/RemoteConfig (4.8.2):
- Firebase/Core
- FirebaseRemoteConfig (= 2.1.1)
- Firebase/Storage (4.8.2):
- Firebase/Core
- FirebaseStorage (= 2.1.2)
- FirebaseABTesting (1.0.0):
- FirebaseCore (~> 4.0)
- Protobuf (~> 3.1)
- FirebaseAnalytics (4.0.9):
- FirebaseCore (~> 4.0)
- FirebaseInstanceID (~> 2.0)
- GoogleToolboxForMac/NSData+zlib (~> 2.1)
- nanopb (~> 0.3)
- FirebaseAuth (4.4.2):
- FirebaseAnalytics (~> 4.0)
- GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)
- GTMSessionFetcher/Core (~> 1.1)
- FirebaseCore (4.0.14):
- GoogleToolboxForMac/NSData+zlib (~> 2.1)
- FirebaseCrash (2.0.2):
- FirebaseAnalytics (~> 4.0)
- FirebaseInstanceID (~> 2.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- GoogleToolboxForMac/NSData+zlib (~> 2.1)
- Protobuf (~> 3.1)
- FirebaseDatabase (4.1.4):
- FirebaseAnalytics (~> 4.0)
- FirebaseCore (~> 4.0)
- leveldb-library (~> 1.18)
- FirebaseDynamicLinks (2.3.2):
- FirebaseAnalytics (~> 4.0)
- FirebaseFirestore (0.10.0):
- FirebaseAnalytics (~> 4.0)
- FirebaseCore (~> 4.0)
- gRPC-ProtoRPC (~> 1.0)
- leveldb-library (~> 1.18)
- Protobuf (~> 3.1)
- FirebaseInstanceID (2.0.8):
- FirebaseCore (~> 4.0)
- FirebaseMessaging (2.0.8):
- FirebaseAnalytics (~> 4.0)
- FirebaseCore (~> 4.0)
- FirebaseInstanceID (~> 2.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- Protobuf (~> 3.1)
- FirebasePerformance (1.1.1):
- FirebaseAnalytics (~> 4.0)
- FirebaseInstanceID (~> 2.0)
- FirebaseSwizzlingUtilities (~> 1.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- GoogleToolboxForMac/NSData+zlib (~> 2.1)
- GTMSessionFetcher/Core (~> 1.1)
- Protobuf (~> 3.1)
- FirebaseRemoteConfig (2.1.1):
- FirebaseABTesting (~> 1.0)
- FirebaseAnalytics (~> 4.0)
- FirebaseCore (~> 4.0)
- FirebaseInstanceID (~> 2.0)
- GoogleToolboxForMac/NSData+zlib (~> 2.1)
- Protobuf (~> 3.1)
- FirebaseStorage (2.1.2):
- FirebaseAnalytics (~> 4.0)
- FirebaseCore (~> 4.0)
- GTMSessionFetcher/Core (~> 1.1)
- FirebaseSwizzlingUtilities (1.0.0)
- Google-Mobile-Ads-SDK (7.27.0)
- GoogleToolboxForMac/DebugUtils (2.1.3):
- GoogleToolboxForMac/Defines (= 2.1.3)
- GoogleToolboxForMac/Defines (2.1.3)
- GoogleToolboxForMac/Logger (2.1.3):
- GoogleToolboxForMac/Defines (= 2.1.3)
- GoogleToolboxForMac/NSData+zlib (2.1.3):
- GoogleToolboxForMac/Defines (= 2.1.3)
- GoogleToolboxForMac/NSDictionary+URLArguments (2.1.3):
- GoogleToolboxForMac/DebugUtils (= 2.1.3)
- GoogleToolboxForMac/Defines (= 2.1.3)
- GoogleToolboxForMac/NSString+URLArguments (= 2.1.3)
- GoogleToolboxForMac/NSString+URLArguments (2.1.3)
- gRPC (1.9.1):
- gRPC-RxLibrary (= 1.9.1)
- gRPC/Main (= 1.9.1)
- gRPC-Core (1.9.1):
- gRPC-Core/Implementation (= 1.9.1)
- gRPC-Core/Interface (= 1.9.1)
- gRPC-Core/Implementation (1.9.1):
- BoringSSL (~> 9.0)
- gRPC-Core/Interface (= 1.9.1)
- nanopb (~> 0.3)
- gRPC-Core/Interface (1.9.1)
- gRPC-ProtoRPC (1.9.1):
- gRPC (= 1.9.1)
- gRPC-RxLibrary (= 1.9.1)
- Protobuf (~> 3.0)
- gRPC-RxLibrary (1.9.1)
- gRPC/Main (1.9.1):
- gRPC-Core (= 1.9.1)
- gRPC-RxLibrary (= 1.9.1)
- GTMSessionFetcher/Core (1.1.13)
- leveldb-library (1.20)
- nanopb (0.3.8):
- nanopb/decode (= 0.3.8)
- nanopb/encode (= 0.3.8)
- nanopb/decode (0.3.8)
- nanopb/encode (0.3.8)
- Protobuf (3.5.0)
- React (0.52.3):
- React/Core (= 0.52.3)
- React/BatchedBridge (0.52.3):
- React/Core
- React/cxxreact_legacy
- React/Core (0.52.3):
- yoga (= 0.52.3.React)
- React/cxxreact_legacy (0.52.3):
- React/jschelpers_legacy
- React/jsinspector_legacy
- React/fishhook (0.52.3)
- React/jschelpers_legacy (0.52.3)
- React/jsinspector_legacy (0.52.3)
- React/RCTBlob (0.52.3):
- React/Core
- React/RCTNetwork (0.52.3):
- React/Core
- React/RCTText (0.52.3):
- React/Core
- React/RCTWebSocket (0.52.3):
- React/Core
- React/fishhook
- React/RCTBlob
- RNFirebase (3.2.7):
- React
- yoga (0.52.3.React)
DEPENDENCIES:
- Crashlytics (~> 3.9.3)
- Fabric (~> 1.7.2)
- Firebase/AdMob
- Firebase/Auth
- Firebase/Core
- Firebase/Crash
- Firebase/Database
- Firebase/DynamicLinks
- Firebase/Firestore
- Firebase/Messaging
- Firebase/Performance
- Firebase/RemoteConfig
- Firebase/Storage
- React/BatchedBridge (from `../node_modules/react-native`)
- React/Core (from `../node_modules/react-native`)
- React/RCTNetwork (from `../node_modules/react-native`)
- React/RCTText (from `../node_modules/react-native`)
- React/RCTWebSocket (from `../node_modules/react-native`)
- RNFirebase (from `../../ios/RNFirebase.podspec`)
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)
EXTERNAL SOURCES:
React:
:path: ../node_modules/react-native
RNFirebase:
:path: ../../ios/RNFirebase.podspec
yoga:
:path: ../node_modules/react-native/ReactCommon/yoga
SPEC CHECKSUMS:
BoringSSL: f3d6b8ce199b9c450a8cfc14895d07a2627fc232
Crashlytics: dbb07d01876c171c5ccbdf7826410380189e452c
Fabric: bb495bb9a7a7677c6d03a1f8b83d95bc49b47e41
Firebase: 7d3b8cd837ad9fcd391657734c0d56dab8e9a5a3
FirebaseABTesting: d07d0ee833b842d5153549e4c7e2e2cb1c23a3f9
FirebaseAnalytics: 388b630c15713f5dbf364071f5f3d6077fb52f4e
FirebaseAuth: bd2738c5c1e92b108ba5f7f7335908097a4e50bb
FirebaseCore: 2e0b98fb2d64ca8140136beff15772bdd14d2dd7
FirebaseCrash: cded0fc566c03651aea606a101bc156085f333ca
FirebaseDatabase: de4446507ccd3257fca37d16f40e1540324571fd
FirebaseDynamicLinks: 38b68641d24e78d0277a9205d988ce22875d5a25
FirebaseFirestore: 713f0c555e7af5ac03d0fec0e2477c48857f4977
FirebaseInstanceID: 81df5805a08001e69138664bdd02c6719a9ac80f
FirebaseMessaging: dfdcd307c2382290a1e297a81d0f18370f5b1bcd
FirebasePerformance: 4e1f8091e400eaf88505234caef5718313653709
FirebaseRemoteConfig: 3310f264fff78b6c2e78b24dcfc4c1b3d6766209
FirebaseStorage: 181bb543d39ee3c53e0558de7ba86b1286a0427f
FirebaseSwizzlingUtilities: f1c49a5a372ac852c853722a5891a0a5e2344a6c
Google-Mobile-Ads-SDK: 83f7f890e638ce8f1debd440ea363338c9f6be3b
GoogleToolboxForMac: 2501e2ad72a52eb3dfe7bd9aee7dad11b858bd20
gRPC: 58828d611419d49da19ad02a60679ffa10a10a87
gRPC-Core: 66413bf1f2d038a6221bc7bfcbeeaa5a117cee29
gRPC-ProtoRPC: f29e8b7445e0d3c0311678ab121e6c164da4ca5e
gRPC-RxLibrary: 8e0067bfe8a054022c7a81470baace4f2f633b48
GTMSessionFetcher: 5bb1eae636127de695590f50e7d248483eb891e6
leveldb-library: 08cba283675b7ed2d99629a4bc5fd052cd2bb6a5
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03
React: c0dfd2dfc970019d1ae7d48bf24cef530992e079
RNFirebase: 3a141a97041ea0757e2036c2bb18acbe9f0e105d
yoga: f45a46b966e1eb0c7a532cfd4beec5b97332ba48
PODFILE CHECKSUM: 67c98bcb203cb992da590bcab6f690f727653ca5
COCOAPODS: 1.3.1

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,11 @@ import firebase from '../../firebase';
import TestSuite from '../../../lib/TestSuite';
import authTests from './authTests';
import userTests from './userTests';
const suite = new TestSuite('Auth', 'firebase.auth()', firebase);
suite.addTests(authTests);
suite.addTests(userTests);
export default suite;

View File

@ -0,0 +1,399 @@
import should from 'should';
const randomString = (length, chars) => {
let mask = '';
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (chars.indexOf('#') > -1) mask += '0123456789';
if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
let result = '';
for (let i = length; i > 0; --i) {
result += mask[Math.round(Math.random() * (mask.length - 1))];
}
return result;
};
export default (userTests = ({ tryCatch, context, describe, it, firebase }) => {
describe('User', () => {
context('getIdToken()', () => {
it('should return a token', () => {
const random = randomString(12, '#aA');
const email = `${random}@${random}.com`;
const pass = random;
const successCb = newUser => {
newUser.uid.should.be.a.String();
newUser.email.should.equal(email.toLowerCase());
newUser.emailVerified.should.equal(false);
newUser.isAnonymous.should.equal(false);
newUser.providerId.should.equal('firebase');
return newUser.getIdToken().then(token => {
token.should.be.a.String();
token.length.should.be.greaterThan(24);
return firebase.native.auth().currentUser.delete();
});
};
return firebase.native
.auth()
.createUserWithEmailAndPassword(email, pass)
.then(successCb);
});
});
context('getToken()', () => {
it('should return a token', () => {
const random = randomString(12, '#aA');
const email = `${random}@${random}.com`;
const pass = random;
const successCb = newUser => {
newUser.uid.should.be.a.String();
newUser.email.should.equal(email.toLowerCase());
newUser.emailVerified.should.equal(false);
newUser.isAnonymous.should.equal(false);
newUser.providerId.should.equal('firebase');
return newUser.getToken().then(token => {
token.should.be.a.String();
token.length.should.be.greaterThan(24);
return firebase.native.auth().currentUser.delete();
});
};
return firebase.native
.auth()
.createUserWithEmailAndPassword(email, pass)
.then(successCb);
});
});
context('linkWithCredential()', () => {
it('it should link anonymous account <-> email account', () => {
const random = randomString(12, '#aA');
const email = `${random}@${random}.com`;
const pass = random;
const successCb = currentUser => {
currentUser.should.be.an.Object();
currentUser.uid.should.be.a.String();
currentUser.toJSON().should.be.an.Object();
should.equal(currentUser.toJSON().email, null);
currentUser.isAnonymous.should.equal(true);
currentUser.providerId.should.equal('firebase');
firebase.native.auth().currentUser.uid.should.be.a.String();
const credential = firebase.native.auth.EmailAuthProvider.credential(
email,
pass
);
return currentUser
.linkWithCredential(credential)
.then(linkedUser => {
linkedUser.should.be.an.Object();
linkedUser.should.equal(firebase.native.auth().currentUser);
linkedUser.uid.should.be.a.String();
linkedUser.toJSON().should.be.an.Object();
// iOS and Android are inconsistent in returning lowercase / mixed case
linkedUser
.toJSON()
.email.toLowerCase()
.should.eql(email.toLowerCase());
linkedUser.isAnonymous.should.equal(false);
linkedUser.providerId.should.equal('firebase');
return firebase.native.auth().signOut();
})
.catch(error =>
firebase.native
.auth()
.signOut()
.then(() => Promise.reject(error))
);
};
return firebase.native
.auth()
.signInAnonymously()
.then(successCb);
});
it('it should error on link anon <-> email if email already exists', () => {
const email = 'test@test.com';
const pass = 'test1234';
const successCb = currentUser => {
currentUser.should.be.an.Object();
currentUser.uid.should.be.a.String();
currentUser.toJSON().should.be.an.Object();
should.equal(currentUser.toJSON().email, null);
currentUser.isAnonymous.should.equal(true);
currentUser.providerId.should.equal('firebase');
firebase.native.auth().currentUser.uid.should.be.a.String();
const credential = firebase.native.auth.EmailAuthProvider.credential(
email,
pass
);
return currentUser
.linkWithCredential(credential)
.then(() =>
firebase.native
.auth()
.signOut()
.then(() => Promise.reject(new Error('Did not error on link')))
)
.catch(error =>
firebase.native
.auth()
.signOut()
.then(() => {
error.code.should.equal('auth/email-already-in-use');
error.message.should.equal(
'The email address is already in use by another account.'
);
return Promise.resolve();
})
);
};
return firebase.native
.auth()
.signInAnonymously()
.then(successCb);
});
});
context('linkAndRetrieveDataWithCredential()', () => {
it('it should link anonymous account <-> email account', () => {
const random = randomString(12, '#aA');
const email = `${random}@${random}.com`;
const pass = random;
const successCb = currentUser => {
currentUser.should.be.an.Object();
currentUser.uid.should.be.a.String();
currentUser.toJSON().should.be.an.Object();
should.equal(currentUser.toJSON().email, null);
currentUser.isAnonymous.should.equal(true);
currentUser.providerId.should.equal('firebase');
firebase.native.auth().currentUser.uid.should.be.a.String();
const credential = firebase.native.auth.EmailAuthProvider.credential(
email,
pass
);
return currentUser
.linkAndRetrieveDataWithCredential(credential)
.then(linkedUserCredential => {
linkedUserCredential.should.be.an.Object();
const linkedUser = linkedUserCredential.user;
linkedUser.should.be.an.Object();
linkedUser.should.equal(firebase.native.auth().currentUser);
linkedUser.uid.should.be.a.String();
linkedUser.toJSON().should.be.an.Object();
// iOS and Android are inconsistent in returning lowercase / mixed case
linkedUser
.toJSON()
.email.toLowerCase()
.should.eql(email.toLowerCase());
linkedUser.isAnonymous.should.equal(false);
linkedUser.providerId.should.equal('firebase');
// TODO: iOS is incorrect, passes on Android
// const additionalUserInfo = linkedUserCredential.additionalUserInfo;
// additionalUserInfo.should.be.an.Object();
// additionalUserInfo.isNewUser.should.equal(false);
return firebase.native.auth().signOut();
})
.catch(error =>
firebase.native
.auth()
.signOut()
.then(() => Promise.reject(error))
);
};
return firebase.native
.auth()
.signInAnonymously()
.then(successCb);
});
it('it should error on link anon <-> email if email already exists', () => {
const email = 'test@test.com';
const pass = 'test1234';
const successCb = currentUser => {
currentUser.should.be.an.Object();
currentUser.uid.should.be.a.String();
currentUser.toJSON().should.be.an.Object();
should.equal(currentUser.toJSON().email, null);
currentUser.isAnonymous.should.equal(true);
currentUser.providerId.should.equal('firebase');
firebase.native.auth().currentUser.uid.should.be.a.String();
const credential = firebase.native.auth.EmailAuthProvider.credential(
email,
pass
);
return currentUser
.linkAndRetrieveDataWithCredential(credential)
.then(() =>
firebase.native
.auth()
.signOut()
.then(() => Promise.reject(new Error('Did not error on link')))
)
.catch(error =>
firebase.native
.auth()
.signOut()
.then(() => {
error.code.should.equal('auth/email-already-in-use');
error.message.should.equal(
'The email address is already in use by another account.'
);
return Promise.resolve();
})
);
};
return firebase.native
.auth()
.signInAnonymously()
.then(successCb);
});
});
context('signOut()', () => {
it('it should reject signOut if no currentUser', () =>
new Promise((resolve, reject) => {
if (firebase.native.auth().currentUser) {
return reject(
new Error(
`A user is currently signed in. ${
firebase.native.auth().currentUser.uid
}`
)
);
}
const successCb = tryCatch(() => {
reject(new Error('No signOut error returned'));
}, reject);
const failureCb = tryCatch(error => {
error.code.should.equal('auth/no-current-user');
error.message.should.equal('No user currently signed in.');
resolve();
}, reject);
return firebase.native
.auth()
.signOut()
.then(successCb)
.catch(failureCb);
}));
});
context('linkWithPhoneNumber()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.linkWithPhoneNumber();
}).should.throw(
'User.linkWithPhoneNumber() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('linkWithPopup()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.linkWithPopup();
}).should.throw(
'User.linkWithPopup() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('linkWithRedirect()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.linkWithRedirect();
}).should.throw(
'User.linkWithRedirect() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('reauthenticateWithPhoneNumber()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.reauthenticateWithPhoneNumber();
}).should.throw(
'User.reauthenticateWithPhoneNumber() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('reauthenticateWithPopup()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.reauthenticateWithPopup();
}).should.throw(
'User.reauthenticateWithPopup() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('reauthenticateWithRedirect()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.reauthenticateWithRedirect();
}).should.throw(
'User.reauthenticateWithRedirect() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('updatePhoneNumber()', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.updatePhoneNumber();
}).should.throw(
'User.updatePhoneNumber() is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
context('refreshToken', () => {
it('should throw an unsupported error', async () => {
await firebase.native.auth().signInAnonymouslyAndRetrieveData();
(() => {
firebase.native.auth().currentUser.refreshToken;
}).should.throw(
'User.refreshToken is unsupported by the native Firebase SDKs.'
);
await firebase.native.auth().signOut();
});
});
});
});

View File

@ -26,6 +26,15 @@ function collectionReferenceTests({
}));
});
context('parent', () => {
it('should return parent document', () => {
const collection = firebase.native
.firestore()
.collection('collection/document/subcollection');
collection.parent.path.should.equal('collection/document');
});
});
context('add()', () => {
it('should create Document', () =>
firebase.native
@ -51,6 +60,15 @@ function collectionReferenceTests({
should.equal(docRef.path, 'collection-tests/doc');
resolve();
}));
it('should error when supplied an incorrect path', () => {
(() => {
firebase.native
.firestore()
.collection('collection')
.doc('invalid/doc');
}).should.throw('Argument "documentPath" must point to a document.');
});
});
context('get()', () => {
@ -68,6 +86,47 @@ function collectionReferenceTests({
});
context('onSnapshot()', () => {
it('QuerySnapshot has correct properties', async () => {
const snapshot = await firebase.native
.firestore()
.collection('collection-tests')
.get();
snapshot.docChanges.should.be.an.Array();
snapshot.empty.should.equal(false);
snapshot.metadata.should.be.an.Object();
snapshot.query.should.be.an.Object();
});
it('DocumentChange has correct properties', async () => {
const collectionRef = firebase.native
.firestore()
.collection('collection-tests');
// Test
let unsubscribe;
let changes;
await new Promise(resolve2 => {
unsubscribe = collectionRef.onSnapshot(snapshot => {
changes = snapshot.docChanges;
resolve2();
});
});
// Assertions
changes.should.be.a.Array();
changes[0].doc.should.be.an.Object();
changes[0].newIndex.should.be.a.Number();
changes[0].oldIndex.should.be.a.Number();
changes[0].type.should.be.a.String();
// Tear down
unsubscribe();
});
it('calls callback with the initial data and then when document changes', async () => {
const collectionRef = firebase.native
.firestore()
@ -104,9 +163,7 @@ function collectionReferenceTests({
unsubscribe();
});
});
context('onSnapshot()', () => {
it('calls callback with the initial data and then when document is added', async () => {
const collectionRef = firebase.native
.firestore()
@ -144,9 +201,7 @@ function collectionReferenceTests({
unsubscribe();
});
});
context('onSnapshot()', () => {
it("doesn't call callback when the ref is updated with the same value", async () => {
const collectionRef = firebase.native
.firestore()
@ -181,9 +236,7 @@ function collectionReferenceTests({
unsubscribe();
});
});
context('onSnapshot()', () => {
it('allows binding multiple callbacks to the same ref', async () => {
// Setup
const collectionRef = firebase.native
@ -234,9 +287,7 @@ function collectionReferenceTests({
unsubscribeA();
unsubscribeB();
});
});
context('onSnapshot()', () => {
it('listener stops listening when unsubscribed', async () => {
// Setup
const collectionRef = firebase.native
@ -310,9 +361,7 @@ function collectionReferenceTests({
callbackA.should.be.calledTwice();
callbackB.should.be.calledThrice();
});
});
context('onSnapshot()', () => {
it('supports options and callback', async () => {
const collectionRef = firebase.native
.firestore()
@ -354,9 +403,7 @@ function collectionReferenceTests({
unsubscribe();
});
});
context('onSnapshot()', () => {
it('supports observer', async () => {
const collectionRef = firebase.native
.firestore()
@ -396,9 +443,7 @@ function collectionReferenceTests({
unsubscribe();
});
});
context('onSnapshot()', () => {
it('supports options and observer', async () => {
const collectionRef = firebase.native
.firestore()
@ -416,6 +461,7 @@ function collectionReferenceTests({
snapshot.forEach(doc => callback(doc.data()));
resolve2();
},
error: () => {},
};
unsubscribe = collectionRef.onSnapshot(
{
@ -443,6 +489,84 @@ function collectionReferenceTests({
unsubscribe();
});
it('errors when invalid parameters supplied', async () => {
const colRef = firebase.native
.firestore()
.collection('collection-tests');
(() => {
colRef.onSnapshot(() => {}, 'error');
}).should.throw(
'Query.onSnapshot failed: Second argument must be a valid function.'
);
(() => {
colRef.onSnapshot({
next: () => {},
error: 'error',
});
}).should.throw(
'Query.onSnapshot failed: Observer.error must be a valid function.'
);
(() => {
colRef.onSnapshot(
{
includeQueryMetadataChanges: true,
},
() => {},
'error'
);
}).should.throw(
'Query.onSnapshot failed: Third argument must be a valid function.'
);
(() => {
colRef.onSnapshot(
{
includeQueryMetadataChanges: true,
},
{
next: () => {},
error: 'error',
}
);
}).should.throw(
'Query.onSnapshot failed: Observer.error must be a valid function.'
);
(() => {
colRef.onSnapshot(
{
includeQueryMetadataChanges: true,
},
{
next: 'error',
}
);
}).should.throw(
'Query.onSnapshot failed: Observer.next must be a valid function.'
);
(() => {
colRef.onSnapshot(
{
includeQueryMetadataChanges: true,
},
'error'
);
}).should.throw(
'Query.onSnapshot failed: Second argument must be a function or observer.'
);
(() => {
colRef.onSnapshot({
error: 'error',
});
}).should.throw(
'Query.onSnapshot failed: First argument must be a function, observer or options.'
);
(() => {
colRef.onSnapshot();
}).should.throw(
'Query.onSnapshot failed: Called with invalid arguments.'
);
});
});
// Where

View File

@ -17,6 +17,28 @@ function documentReferenceTests({ describe, it, context, firebase }) {
}));
});
context('id', () => {
it('should return document id', () => {
const document = firebase.native.firestore().doc('documents/doc1');
document.id.should.equal('doc1');
});
});
context('parent', () => {
it('should return parent collection', () => {
const document = firebase.native.firestore().doc('documents/doc1');
document.parent.id.should.equal('documents');
});
});
context('collection()', () => {
it('should return a child collection', () => {
const document = firebase.native.firestore().doc('documents/doc1');
const collection = document.collection('pages');
collection.id.should.equal('pages');
});
});
context('delete()', () => {
it('should delete Document', () =>
firebase.native
@ -32,6 +54,17 @@ function documentReferenceTests({ describe, it, context, firebase }) {
}));
});
context('get()', () => {
it('DocumentSnapshot should have correct properties', async () => {
const snapshot = await firebase.native
.firestore()
.doc('document-tests/doc1')
.get();
snapshot.id.should.equal('doc1');
snapshot.metadata.should.be.an.Object();
});
});
context('onSnapshot()', () => {
it('calls callback with the initial data and then when value changes', async () => {
const docRef = firebase.native.firestore().doc('document-tests/doc1');
@ -321,6 +354,7 @@ function documentReferenceTests({ describe, it, context, firebase }) {
callback(snapshot.data());
resolve2();
},
error: () => {},
};
unsubscribe = docRef.onSnapshot(
{ includeMetadataChanges: true },
@ -346,6 +380,88 @@ function documentReferenceTests({ describe, it, context, firebase }) {
unsubscribe();
});
it('errors when invalid parameters supplied', async () => {
const docRef = firebase.native.firestore().doc('document-tests/doc1');
(() => {
docRef.onSnapshot(() => {}, 'error');
}).should.throw(
'DocumentReference.onSnapshot failed: Second argument must be a valid function.'
);
(() => {
docRef.onSnapshot({
next: () => {},
error: 'error',
});
}).should.throw(
'DocumentReference.onSnapshot failed: Observer.error must be a valid function.'
);
(() => {
docRef.onSnapshot({
next: 'error',
});
}).should.throw(
'DocumentReference.onSnapshot failed: Observer.next must be a valid function.'
);
(() => {
docRef.onSnapshot(
{
includeMetadataChanges: true,
},
() => {},
'error'
);
}).should.throw(
'DocumentReference.onSnapshot failed: Third argument must be a valid function.'
);
(() => {
docRef.onSnapshot(
{
includeMetadataChanges: true,
},
{
next: () => {},
error: 'error',
}
);
}).should.throw(
'DocumentReference.onSnapshot failed: Observer.error must be a valid function.'
);
(() => {
docRef.onSnapshot(
{
includeMetadataChanges: true,
},
{
next: 'error',
}
);
}).should.throw(
'DocumentReference.onSnapshot failed: Observer.next must be a valid function.'
);
(() => {
docRef.onSnapshot(
{
includeMetadataChanges: true,
},
'error'
);
}).should.throw(
'DocumentReference.onSnapshot failed: Second argument must be a function or observer.'
);
(() => {
docRef.onSnapshot({
error: 'error',
});
}).should.throw(
'DocumentReference.onSnapshot failed: First argument must be a function, observer or options.'
);
(() => {
docRef.onSnapshot();
}).should.throw(
'DocumentReference.onSnapshot failed: Called with invalid arguments.'
);
});
});
context('set()', () => {
@ -464,6 +580,25 @@ function documentReferenceTests({ describe, it, context, firebase }) {
doc.data().nested.firstname.should.equal('First Name');
doc.data().nested.lastname.should.equal('Last Name');
}));
it('errors when invalid parameters supplied', async () => {
const docRef = firebase.native.firestore().doc('document-tests/doc1');
(() => {
docRef.update('error');
}).should.throw(
'DocumentReference.update failed: If using a single argument, it must be an object.'
);
(() => {
docRef.update('error1', 'error2', 'error3');
}).should.throw(
'DocumentReference.update failed: Must have either a single object argument, or equal numbers of key/value pairs.'
);
(() => {
docRef.update(0, 'error');
}).should.throw(
'DocumentReference.update failed: Argument at index 0 must be a string or FieldPath'
);
});
});
context('types', () => {

View File

@ -2,6 +2,13 @@ import should from 'should';
function fieldPathTests({ describe, it, context, firebase }) {
describe('FieldPath', () => {
context('documentId', () => {
it('should be a FieldPath', () => {
const documentId = firebase.native.firestore.FieldPath.documentId();
documentId.should.be.instanceof(firebase.native.firestore.FieldPath);
});
});
context('DocumentSnapshot.get()', () => {
it('should get the correct values', () =>
firebase.native

View File

@ -11,6 +11,14 @@ function firestoreTests({ describe, it, context, fcontext, firebase }) {
should.equal(collectionRef.id, 'collection2');
resolve();
}));
it('should error if invalid collection path supplied', () => {
(() => {
firebase.native.firestore().collection('collection1/doc1');
}).should.throw(
'Argument "collectionPath" must point to a collection.'
);
});
});
context('doc()', () => {
@ -22,6 +30,12 @@ function firestoreTests({ describe, it, context, fcontext, firebase }) {
should.equal(docRef.path, 'collection1/doc1/collection2/doc2');
resolve();
}));
it('should error if invalid document path supplied', () => {
(() => {
firebase.native.firestore().doc('collection1');
}).should.throw('Argument "documentPath" must point to a document.');
});
});
context('batch()', () => {
@ -90,6 +104,54 @@ function firestoreTests({ describe, it, context, fcontext, firebase }) {
sfDoc.data().nested.lastname.should.equal('Last Name');
});
});
it('errors when invalid parameters supplied', async () => {
const ref = firebase.native.firestore().doc('collection/doc');
const batch = firebase.native.firestore().batch();
(() => {
batch.update(ref, 'error');
}).should.throw(
'WriteBatch.update failed: If using two arguments, the second must be an object.'
);
(() => {
batch.update(ref, 'error1', 'error2', 'error3');
}).should.throw(
'WriteBatch.update failed: Must have a document reference, followed by either a single object argument, or equal numbers of key/value pairs.'
);
(() => {
batch.update(ref, 0, 'error');
}).should.throw(
'WriteBatch.update failed: Argument at index 0 must be a string or FieldPath'
);
});
});
context('enablePersistence()', () => {
it('should throw an unsupported error', () => {
(() => {
firebase.native.firestore().enablePersistence();
}).should.throw(
'Persistence is enabled by default on the Firestore SDKs'
);
});
});
context('setLogLevel()', () => {
it('should throw an unsupported error', () => {
(() => {
firebase.native.firestore().setLogLevel();
}).should.throw(
'firebase.firestore().setLogLevel() is unsupported by the native Firebase SDKs.'
);
});
});
context('settings()', () => {
it('should throw an unsupported error', () => {
(() => {
firebase.native.firestore().settings();
}).should.throw('firebase.firestore().settings() coming soon');
});
});
context('runTransaction()', () => {