[tests] Add missing core tests

This commit is contained in:
Chris Bianca 2018-03-01 15:04:33 +00:00
parent b31569ba4c
commit 7ec62f9415
1 changed files with 61 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import should from 'should';
import RNFirebase from './../../../firebase';
import firebase from './../../../firebase';
const androidTestConfig = {
// firebase android sdk completely ignores client id
@ -33,49 +33,44 @@ function rand(from = 1, to = 9999) {
}
function coreTests({ describe, it }) {
describe('Core', () => {
describe('Firebase', () => {
it('it should create js apps for natively initialized apps', () => {
should.equal(RNFirebase.app()._nativeInitialized, true);
should.equal(firebase.app()._nativeInitialized, true);
return Promise.resolve();
});
it('natively initialized apps should have options available in js', () => {
should.equal(
RNFirebase.app().options.apiKey,
firebase.app().options.apiKey,
Platform.OS === 'ios' ? iosTestConfig.apiKey : androidTestConfig.apiKey
);
should.equal(
RNFirebase.app().options.appId,
firebase.app().options.appId,
Platform.OS === 'ios' ? iosTestConfig.appId : androidTestConfig.appId
);
should.equal(
RNFirebase.app().options.databaseURL,
firebase.app().options.databaseURL,
iosTestConfig.databaseURL
);
should.equal(
RNFirebase.app().options.messagingSenderId,
firebase.app().options.messagingSenderId,
iosTestConfig.messagingSenderId
);
should.equal(RNFirebase.app().options.projectId, iosTestConfig.projectId);
should.equal(firebase.app().options.projectId, iosTestConfig.projectId);
should.equal(
RNFirebase.app().options.storageBucket,
firebase.app().options.storageBucket,
iosTestConfig.storageBucket
);
return Promise.resolve();
});
it('it should resolve onReady for natively initialized apps', () =>
RNFirebase.app().onReady());
it('it should provide an array of apps', () => {
should.equal(!!RNFirebase.apps.length, true);
should.equal(RNFirebase.apps.includes(RNFirebase.app('[DEFAULT]')), true);
return Promise.resolve();
});
firebase.app().onReady());
it('it should initialize dynamic apps', () => {
const name = `testscoreapp${rand()}`;
return RNFirebase.initializeApp(
return firebase
.initializeApp(
Platform.OS === 'ios' ? iosTestConfig : androidTestConfig,
name
)
@ -90,6 +85,52 @@ function coreTests({ describe, it }) {
return Promise.resolve();
});
});
it('SDK_VERSION should return a string version', () => {
firebase.SDK_VERSION.should.be.a.String();
});
});
describe('App', () => {
it('apps should provide an array of apps', () => {
should.equal(!!firebase.apps.length, true);
should.equal(firebase.apps.includes(firebase.app('[DEFAULT]')), true);
return Promise.resolve();
});
it('delete is unsupported', () => {
(() => {
firebase.app().delete();
}).should.throw(
'app.delete() is unsupported by the native Firebase SDKs.'
);
});
it('extendApp should error if an object is not supplied', () => {
(() => {
firebase.app().extendApp('string');
}).should.throw(
"Missing required argument of type 'Object' for method 'extendApp()'."
);
});
it('extendApp should error if a protected property is supplied', () => {
(() => {
firebase.app().extendApp({
database: {},
});
}).should.throw(
"Property 'database' is protected and can not be overridden by extendApp."
);
});
it('extendApp should provide additional functionality', () => {
const extension = {};
firebase.app().extendApp({
extension,
});
firebase.app().extension.should.equal(extension);
});
});
}