mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
[database][wip] refactor & improvements to add support for multiple apps
This commit is contained in:
@@ -6,6 +6,8 @@ import { setupSuites } from './tests/index';
|
||||
|
||||
global.Promise = require('bluebird');
|
||||
|
||||
console.ignoredYellowBox = ['Setting a timer for a long period of time, i.e. multiple minutes'];
|
||||
|
||||
type State = {
|
||||
loading: boolean,
|
||||
store: any,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function childTests({ describe, it, context, firebase }) {
|
||||
describe('ref().child', () => {
|
||||
function childTests({ fdescribe, it, context, firebase }) {
|
||||
fdescribe('ref().child', () => {
|
||||
context('when passed a shallow path', () => {
|
||||
it('returns correct child ref', () => {
|
||||
// Setup
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function factoryTests({ describe, it, firebase }) {
|
||||
describe('ref()', () => {
|
||||
function factoryTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref()', () => {
|
||||
it('returns root reference when provided no path', () => {
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function isEqualTests({ describe, before, it, firebase }) {
|
||||
describe('ref().isEqual()', () => {
|
||||
function isEqualTests({ fdescribe, before, it, firebase }) {
|
||||
fdescribe('ref().isEqual()', () => {
|
||||
before(() => {
|
||||
this.ref = firebase.native.database().ref('tests/types');
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import should from 'should';
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function issueTests({ describe, it, context, firebase }) {
|
||||
describe('issue_100', () => {
|
||||
function issueTests({ fdescribe, it, context, firebase }) {
|
||||
fdescribe('issue_100', () => {
|
||||
context('array-like values should', () => {
|
||||
it('return null in returned array at positions where a key is missing', async () => {
|
||||
// Setup
|
||||
@@ -18,7 +18,7 @@ function issueTests({ describe, it, context, firebase }) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue_108', () => {
|
||||
fdescribe('issue_108', () => {
|
||||
context('filters using floats', () => {
|
||||
it('return correct results', async () => {
|
||||
// Setup
|
||||
@@ -67,7 +67,7 @@ function issueTests({ describe, it, context, firebase }) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue_171', () => {
|
||||
fdescribe('issue_171', () => {
|
||||
context('non array-like values should', () => {
|
||||
it('return as objects', async () => {
|
||||
// Setup
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function keyTests({ describe, it, firebase }) {
|
||||
describe('ref().key', () => {
|
||||
function keyTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().key', () => {
|
||||
it('returns null for root ref', () => {
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'should-sinon';
|
||||
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function onceTests({ describe, firebase, it, tryCatch }) {
|
||||
describe('ref().once()', () => {
|
||||
function onceTests({ fdescribe, firebase, it, tryCatch }) {
|
||||
fdescribe('ref().once()', () => {
|
||||
it('returns a promise', () => {
|
||||
// Setup
|
||||
|
||||
@@ -62,8 +62,7 @@ function onceTests({ describe, firebase, it, tryCatch }) {
|
||||
|
||||
const failureCb = tryCatch((error) => {
|
||||
// Assertion
|
||||
|
||||
error.message.includes('permission_denied').should.be.true();
|
||||
error.code.includes('DATABASE/PERMISSION-DENIED').should.be.true();
|
||||
resolve();
|
||||
}, reject);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function parentTests({ describe, context, it, firebase }) {
|
||||
describe('ref().parent', () => {
|
||||
function parentTests({ fdescribe, context, it, firebase }) {
|
||||
fdescribe('ref().parent', () => {
|
||||
context('on the root ref', () => {
|
||||
it('returns null', () => {
|
||||
// Setup
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function setTests({ describe, it, firebase }) {
|
||||
describe('ref().priority', () => {
|
||||
function setTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().priority', () => {
|
||||
it('setPriority() should correctly set a priority for all non-null values', async () => {
|
||||
await Promise.map(Object.keys(DatabaseContents.DEFAULT), async (dataRef) => {
|
||||
// Setup
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'should-sinon';
|
||||
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function pushTests({ describe, it, firebase }) {
|
||||
describe('ref().push()', () => {
|
||||
function pushTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().push()', () => {
|
||||
it('returns a ref that can be used to set value later', async () => {
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'should-sinon';
|
||||
import Promise from 'bluebird';
|
||||
|
||||
function queryTests({ describe, it, firebase, tryCatch }) {
|
||||
describe('ref query', () => {
|
||||
function queryTests({ fdescribe, it, firebase, tryCatch }) {
|
||||
fdescribe('ref query', () => {
|
||||
it('orderByChild().equalTo()', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const successCb = tryCatch((snapshot) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function refTests({ describe, it, firebase }) {
|
||||
describe('ref().ref', () => {
|
||||
function refTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().ref', () => {
|
||||
it('returns the reference', () => {
|
||||
// Setup
|
||||
const ref = firebase.native.database().ref();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function removeTests({ describe, it, firebase }) {
|
||||
describe('ref().remove()', () => {
|
||||
function removeTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().remove()', () => {
|
||||
it('returns a promise', () => {
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function rootTests({ describe, it, context, firebase }) {
|
||||
describe('ref().root', () => {
|
||||
function rootTests({ fdescribe, it, context, firebase }) {
|
||||
fdescribe('ref().root', () => {
|
||||
context('when called on a non-root reference', () => {
|
||||
it('returns root ref', () => {
|
||||
// Setup
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function setTests({ describe, it, xit, firebase }) {
|
||||
describe('ref.set()', () => {
|
||||
xit('returns a promise', async () => {
|
||||
function setTests({ fdescribe, it, xit, firebase }) {
|
||||
fdescribe('ref.set()', () => {
|
||||
it('returns a promise', async () => {
|
||||
// Setup
|
||||
|
||||
const ref = firebase.native.database().ref('tests/types/number');
|
||||
@@ -16,7 +16,7 @@ function setTests({ describe, it, xit, firebase }) {
|
||||
returnValue.should.be.Promise();
|
||||
|
||||
await returnValue.then((value) => {
|
||||
(value === undefined).should.be.true();
|
||||
(value === null).should.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import Promise from 'bluebird';
|
||||
|
||||
function onTests({ describe, it, firebase, tryCatch }) {
|
||||
describe('ref.transaction()', () => {
|
||||
it('works', () => {
|
||||
function onTests({ fdescribe, it, firebase, tryCatch }) {
|
||||
fdescribe('ref.transaction()', () => {
|
||||
it('increments a value on a ref', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let valueBefore = 1;
|
||||
|
||||
firebase.native.database()
|
||||
.ref('tests/transaction').transaction((currentData) => {
|
||||
if (currentData === null) {
|
||||
return valueBefore + 10;
|
||||
}
|
||||
valueBefore = currentData;
|
||||
if (currentData === null) {
|
||||
return valueBefore + 10;
|
||||
}, tryCatch((error, committed, snapshot) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
}
|
||||
valueBefore = currentData;
|
||||
return valueBefore + 10;
|
||||
}, tryCatch((error, committed, snapshot) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
if (!committed) {
|
||||
return reject(new Error('Transaction did not commit.'));
|
||||
}
|
||||
if (!committed) {
|
||||
return reject(new Error('Transaction did not commit.'));
|
||||
}
|
||||
|
||||
snapshot.val().should.equal(valueBefore + 10);
|
||||
|
||||
return resolve();
|
||||
}, reject), true);
|
||||
snapshot.val().should.equal(valueBefore + 10);
|
||||
|
||||
return resolve();
|
||||
}, reject), true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,18 +33,18 @@ function onTests({ describe, it, firebase, tryCatch }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
firebase.native.database()
|
||||
.ref('tests/transaction').transaction(() => {
|
||||
return undefined;
|
||||
}, (error, committed) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
return undefined;
|
||||
}, (error, committed) => {
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
if (!committed) {
|
||||
return resolve();
|
||||
}
|
||||
if (!committed) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
return reject(new Error('Transaction did not abort commit.'));
|
||||
}, true);
|
||||
return reject(new Error('Transaction did not abort commit.'));
|
||||
}, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import Promise from 'bluebird';
|
||||
import DatabaseContents from '../../support/DatabaseContents';
|
||||
|
||||
function updateTests({ describe, it, firebase }) {
|
||||
describe('ref().update()', () => {
|
||||
function updateTests({ fdescribe, it, firebase }) {
|
||||
fdescribe('ref().update()', () => {
|
||||
it('returns a promise', () => {
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -12,7 +12,12 @@ function storageTests({ describe, it, firebase, tryCatch }) {
|
||||
resolve();
|
||||
}, reject);
|
||||
|
||||
firebase.native.storage().ref('/not.jpg').downloadFile(`${firebase.native.storage.Native.DOCUMENT_DIRECTORY_PATH}/not.jpg`).then(successCb).catch(failureCb);
|
||||
firebase.native.storage().ref('/not.jpg')
|
||||
.downloadFile(
|
||||
`${firebase.native.storage.Native.DOCUMENT_DIRECTORY_PATH}/not.jpg`,
|
||||
)
|
||||
.then(successCb)
|
||||
.catch(failureCb);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user