mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-23 20:10:05 +08:00
[database] cleanup linting issues
This commit is contained in:
@@ -32,13 +32,21 @@ const CONTENT = {
|
||||
|
||||
exports.seed = function seed(path) {
|
||||
return Promise.all([
|
||||
firebase.database().ref(`${path}/types`).set(CONTENT.TYPES),
|
||||
firebase.database().ref(`${path}/query`).set(CONTENT.QUERY),
|
||||
firebase
|
||||
.database()
|
||||
.ref(`${path}/types`)
|
||||
.set(CONTENT.TYPES),
|
||||
firebase
|
||||
.database()
|
||||
.ref(`${path}/query`)
|
||||
.set(CONTENT.QUERY),
|
||||
]);
|
||||
};
|
||||
|
||||
exports.wipe = function wipe(path) {
|
||||
return firebase.database().ref(path)
|
||||
return firebase
|
||||
.database()
|
||||
.ref(path)
|
||||
.remove();
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
describe(`database().ref('.info/connected')`, () => {
|
||||
|
||||
after(() => firebase.database().goOnline());
|
||||
|
||||
it('returns false when used with once', async () => {
|
||||
@@ -43,9 +42,7 @@ describe(`database().ref('.info/connected')`, () => {
|
||||
const callback = sinon.spy();
|
||||
await firebase.database().goOffline();
|
||||
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref('.info/connected');
|
||||
const ref = firebase.database().ref('.info/connected');
|
||||
|
||||
const handler = $ => {
|
||||
callback($.val());
|
||||
|
||||
@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/onDisconnectCancel`;
|
||||
|
||||
describe('database().ref().onDisconnect().cancel()', () => {
|
||||
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
afterEach(() => {
|
||||
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().cancel()', () => {
|
||||
});
|
||||
|
||||
it('throws if onComplete is not a function', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.cancel('foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
|
||||
@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/onDisconnectRemove`;
|
||||
|
||||
describe('database().ref().onDisconnect().remove()', () => {
|
||||
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
afterEach(() => {
|
||||
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().remove()', () => {
|
||||
});
|
||||
|
||||
it('throws if onComplete is not a function', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.remove('foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().remove()', () => {
|
||||
});
|
||||
|
||||
it('removes a node whilst offline', async () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).child('removeMe');
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.child('removeMe');
|
||||
|
||||
await ref.set('foobar');
|
||||
|
||||
@@ -54,7 +59,10 @@ describe('database().ref().onDisconnect().remove()', () => {
|
||||
|
||||
it('calls back to the onComplete function', async () => {
|
||||
const callback = sinon.spy();
|
||||
const ref = firebase.database().ref(TEST_PATH).child('removeMe');
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.child('removeMe');
|
||||
|
||||
// Set an initial value
|
||||
await ref.set('foo');
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const { PATH, seed, wipe } = require('../helpers');
|
||||
const { PATH, wipe } = require('../helpers');
|
||||
|
||||
const TEST_PATH = `${PATH}/onDisconnectSet`;
|
||||
|
||||
describe('database().ref().onDisconnect().set()', () => {
|
||||
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
afterEach(() => {
|
||||
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().set()', () => {
|
||||
});
|
||||
|
||||
it('throws if value is not a defined', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.set();
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().set()', () => {
|
||||
});
|
||||
|
||||
it('throws if onComplete is not a function', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.set(null, 'foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
|
||||
@@ -20,7 +20,6 @@ const { PATH, wipe } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/onDisconnectSetWithPriority`;
|
||||
|
||||
describe('database().ref().onDisconnect().setWithPriority()', () => {
|
||||
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
afterEach(() => {
|
||||
@@ -29,7 +28,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
|
||||
});
|
||||
|
||||
it('throws if value is not a defined', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.setWithPriority();
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
@@ -40,7 +42,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
|
||||
});
|
||||
|
||||
it('throws if priority is not a valid type', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.setWithPriority(null, { foo: 'bar' });
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
@@ -51,7 +56,10 @@ describe('database().ref().onDisconnect().setWithPriority()', () => {
|
||||
});
|
||||
|
||||
it('throws if onComplete is not a function', () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).onDisconnect();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.onDisconnect();
|
||||
try {
|
||||
ref.setWithPriority(null, 1, 'foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
|
||||
@@ -79,9 +79,12 @@ describe('database().ref().onDisconnect().update()', () => {
|
||||
},
|
||||
});
|
||||
|
||||
await ref.child('foo').onDisconnect().update({
|
||||
bar: value,
|
||||
});
|
||||
await ref
|
||||
.child('foo')
|
||||
.onDisconnect()
|
||||
.update({
|
||||
bar: value,
|
||||
});
|
||||
await firebase.database().goOffline();
|
||||
await firebase.database().goOnline();
|
||||
|
||||
|
||||
@@ -37,14 +37,25 @@ describe('database().ref().isEqual()', () => {
|
||||
|
||||
it('returns false if the query is different', async () => {
|
||||
const query = await firebase.database().ref();
|
||||
const other = await firebase.database().ref().limitToLast(2);
|
||||
const other = await firebase
|
||||
.database()
|
||||
.ref()
|
||||
.limitToLast(2);
|
||||
const same = query.isEqual(other);
|
||||
same.should.eql(false);
|
||||
});
|
||||
|
||||
it('returns true if the query is created differently', async () => {
|
||||
const query = await firebase.database().ref().limitToFirst(1).orderByChild('foo');
|
||||
const other = await firebase.database().ref().orderByChild('foo').limitToFirst(1);
|
||||
const query = await firebase
|
||||
.database()
|
||||
.ref()
|
||||
.limitToFirst(1)
|
||||
.orderByChild('foo');
|
||||
const other = await firebase
|
||||
.database()
|
||||
.ref()
|
||||
.orderByChild('foo')
|
||||
.limitToFirst(1);
|
||||
const same = query.isEqual(other);
|
||||
same.should.eql(true);
|
||||
});
|
||||
|
||||
@@ -30,7 +30,10 @@ describe('database().ref().keepSynced()', () => {
|
||||
});
|
||||
|
||||
it('toggles keepSynced on and off without throwing', async () => {
|
||||
const ref = firebase.database().ref('noop').orderByValue();
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref('noop')
|
||||
.orderByValue();
|
||||
await ref.keepSynced(true);
|
||||
await ref.keepSynced(false);
|
||||
});
|
||||
|
||||
@@ -20,7 +20,6 @@ const { PATH } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/on`;
|
||||
|
||||
describe('database().ref().on()', () => {
|
||||
|
||||
it('throws if event type is invalid', async () => {
|
||||
try {
|
||||
await firebase
|
||||
|
||||
@@ -38,7 +38,10 @@ describe('database().ref().orderByPriority()', () => {
|
||||
});
|
||||
|
||||
it('order by priority', async () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).child('query');
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.child('query');
|
||||
|
||||
await Promise.all([
|
||||
ref.child('a').setPriority(2),
|
||||
@@ -47,9 +50,7 @@ describe('database().ref().orderByPriority()', () => {
|
||||
]);
|
||||
|
||||
try {
|
||||
const snapshot = await ref
|
||||
.orderByPriority()
|
||||
.once('value');
|
||||
const snapshot = await ref.orderByPriority().once('value');
|
||||
|
||||
const expected = ['c', 'a', 'b'];
|
||||
|
||||
|
||||
@@ -38,7 +38,10 @@ describe('database().ref().orderByValue()', () => {
|
||||
});
|
||||
|
||||
it('order by value', async () => {
|
||||
const ref = firebase.database().ref(TEST_PATH).child('query');
|
||||
const ref = firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.child('query');
|
||||
|
||||
await ref.set({
|
||||
a: 2,
|
||||
@@ -47,9 +50,7 @@ describe('database().ref().orderByValue()', () => {
|
||||
});
|
||||
|
||||
try {
|
||||
const snapshot = await ref
|
||||
.orderByValue()
|
||||
.once('value');
|
||||
const snapshot = await ref.orderByValue().once('value');
|
||||
|
||||
const expected = ['c', 'a', 'b'];
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
*/
|
||||
|
||||
describe('database().ref().toJSON()', () => {
|
||||
|
||||
it('returns a string version of the current query path', async () => {
|
||||
const res = firebase.database().ref('foo/bar/baz').toJSON();
|
||||
const res = firebase
|
||||
.database()
|
||||
.ref('foo/bar/baz')
|
||||
.toJSON();
|
||||
const expected = `${firebase.database()._customUrlOrRegion}/foo/bar/baz`;
|
||||
should.equal(res, expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
describe('database().ref().onDisconnect()', () => {
|
||||
it('returns a new DatabaseOnDisconnect instance', () => {
|
||||
const instance = firebase.database().ref().onDisconnect();
|
||||
const instance = firebase
|
||||
.database()
|
||||
.ref()
|
||||
.onDisconnect();
|
||||
instance.constructor.name.should.eql('DatabaseOnDisconnect');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,16 +15,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const { PATH, seed, wipe } = require('../helpers');
|
||||
// const { PATH, seed, wipe } = require('../helpers');
|
||||
|
||||
const TEST_PATH = `${PATH}/push`;
|
||||
|
||||
describe('database().ref().push()', () => {
|
||||
// const TEST_PATH = `${PATH}/push`;
|
||||
|
||||
xdescribe('database().ref().push()', () => {
|
||||
// before(() => seed(TEST_PATH));
|
||||
// after(() => wipe(TEST_PATH));
|
||||
|
||||
|
||||
// TODO
|
||||
|
||||
});
|
||||
|
||||
@@ -20,13 +20,15 @@ const { PATH, seed, wipe } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/set`;
|
||||
|
||||
describe('database().ref().set()', () => {
|
||||
|
||||
before(() => seed(TEST_PATH));
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
it('throws if no value is provided', async () => {
|
||||
try {
|
||||
await firebase.database().ref(TEST_PATH).set();
|
||||
await firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.set();
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql(`'value' must be defined`);
|
||||
@@ -36,7 +38,10 @@ describe('database().ref().set()', () => {
|
||||
|
||||
it('throws if onComplete is not a function', async () => {
|
||||
try {
|
||||
await firebase.database().ref(TEST_PATH).set(null, 'foo');
|
||||
await firebase
|
||||
.database()
|
||||
.ref(TEST_PATH)
|
||||
.set(null, 'foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql(`'onComplete' must be a function if provided`);
|
||||
|
||||
@@ -20,13 +20,15 @@ const { PATH, CONTENT, seed, wipe } = require('../helpers');
|
||||
const TEST_PATH = `${PATH}/priority`;
|
||||
|
||||
describe('database().ref().setPriority()', () => {
|
||||
|
||||
before(() => seed(TEST_PATH));
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
it('throws if priority is not a valid type', async () => {
|
||||
try {
|
||||
await firebase.database().ref().setPriority({});
|
||||
await firebase
|
||||
.database()
|
||||
.ref()
|
||||
.setPriority({});
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql(`'priority' must be a number, string or null value`);
|
||||
@@ -36,7 +38,10 @@ describe('database().ref().setPriority()', () => {
|
||||
|
||||
it('throws if onComplete is not a function', async () => {
|
||||
try {
|
||||
await firebase.database().ref().setPriority(null, 'foo');
|
||||
await firebase
|
||||
.database()
|
||||
.ref()
|
||||
.setPriority(null, 'foo');
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql(`'onComplete' must be a function if provided`);
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const { PATH, CONTENT, seed, wipe } = require('../helpers');
|
||||
const { PATH, seed, wipe } = require('../helpers');
|
||||
|
||||
const TEST_PATH = `${PATH}/setWithPriority`;
|
||||
|
||||
describe('database().ref().setWithPriority()', () => {
|
||||
|
||||
before(() => seed(TEST_PATH));
|
||||
after(() => wipe(TEST_PATH));
|
||||
|
||||
|
||||
@@ -56,9 +56,12 @@ describe('database().ref().update()', () => {
|
||||
await firebase
|
||||
.database()
|
||||
.ref(`${PATH}/update`)
|
||||
.update({
|
||||
foo: 'bar',
|
||||
}, 'foo');
|
||||
.update(
|
||||
{
|
||||
foo: 'bar',
|
||||
},
|
||||
'foo',
|
||||
);
|
||||
return Promise.reject(new Error('Did not throw an Error.'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql(`'onComplete' must be a function if provided`);
|
||||
|
||||
Reference in New Issue
Block a user