Merge commit '36c936779b9badf72a0a3d789efafd2dcdb5ba36'

# Conflicts:
#	ios/RNFirebase.xcodeproj/project.pbxproj
#	package.json
This commit is contained in:
Chris Bianca
2017-10-31 14:33:31 +00:00
32 changed files with 692 additions and 272 deletions

View File

@@ -150,7 +150,7 @@ PODS:
- React/Core
- React/fishhook
- React/RCTBlob
- RNFirebase (3.0.0):
- RNFirebase (3.0.5):
- React
- yoga (0.49.1.React)
@@ -208,7 +208,7 @@ SPEC CHECKSUMS:
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
Protobuf: 03eef2ee0b674770735cf79d9c4d3659cf6908e8
React: cf892fb84b7d06bf5fea7f328e554c6dcabe85ee
RNFirebase: 901a473c68fcbaa28125c56a911923f2fbe5d61b
RNFirebase: 7c86b4efd2860700048d927f34db237fbce1d5fc
yoga: 3abf02d6d9aeeb139b4c930eb1367feae690a35a
PODFILE CHECKSUM: b5674be55653f5dda937c8b794d0479900643d45

View File

@@ -1,4 +1,6 @@
import should from 'should';
import sinon from 'sinon';
import 'should-sinon';
import DatabaseContents from '../../support/DatabaseContents';
function issueTests({ describe, it, context, firebase }) {
@@ -81,6 +83,212 @@ function issueTests({ describe, it, context, firebase }) {
});
});
});
describe('issue_489', () => {
context('long numbers should', () => {
it('return as longs', async () => {
// Setup
const long1Ref = firebase.native.database().ref('tests/issues/489/long1');
const long2Ref = firebase.native.database().ref('tests/issues/489/long2');
const long2 = 1234567890123456;
// Test
let snapshot = await long1Ref.once('value');
snapshot.val().should.eql(DatabaseContents.ISSUES[489].long1);
await long2Ref.set(long2);
snapshot = await long2Ref.once('value');
snapshot.val().should.eql(long2);
return Promise.resolve();
});
});
});
describe('issue_521', () => {
context('orderByChild (numerical field) and limitToLast', () => {
it('once() returns correct results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521');
// Test
return ref
.orderByChild('number')
.limitToLast(1)
.once('value')
.then((snapshot) => {
const val = snapshot.val();
// Assertion
val.key3.should.eql(DatabaseContents.ISSUES[521].key3);
should.equal(Object.keys(val).length, 1);
return Promise.resolve();
});
});
it('on() returns correct initial results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521').orderByChild('number').limitToLast(2);
const callback = sinon.spy();
// Test
await new Promise((resolve) => {
ref.on('value', (snapshot) => {
callback(snapshot.val());
resolve();
});
});
callback.should.be.calledWith({
key2: DatabaseContents.ISSUES[521].key2,
key3: DatabaseContents.ISSUES[521].key3,
});
callback.should.be.calledOnce();
return Promise.resolve();
});
it('on() returns correct subsequent results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521').orderByChild('number').limitToLast(2);
const callback = sinon.spy();
// Test
await new Promise((resolve) => {
ref.on('value', (snapshot) => {
callback(snapshot.val());
resolve();
});
});
callback.should.be.calledWith({
key2: DatabaseContents.ISSUES[521].key2,
key3: DatabaseContents.ISSUES[521].key3,
});
callback.should.be.calledOnce();
const newDataValue = {
name: 'Item 4',
number: 4,
string: 'item4',
};
const newRef = firebase.native.database().ref('tests/issues/521/key4');
await newRef.set(newDataValue);
await new Promise((resolve) => {
setTimeout(() => resolve(), 5);
});
// Assertions
callback.should.be.calledWith({
key3: DatabaseContents.ISSUES[521].key3,
key4: newDataValue,
});
callback.should.be.calledTwice();
return Promise.resolve();
});
});
context('orderByChild (string field) and limitToLast', () => {
it('once() returns correct results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521');
// Test
return ref
.orderByChild('string')
.limitToLast(1)
.once('value')
.then((snapshot) => {
const val = snapshot.val();
// Assertion
val.key3.should.eql(DatabaseContents.ISSUES[521].key3);
should.equal(Object.keys(val).length, 1);
return Promise.resolve();
});
});
it('on() returns correct initial results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521').orderByChild('string').limitToLast(2);
const callback = sinon.spy();
// Test
await new Promise((resolve) => {
ref.on('value', (snapshot) => {
callback(snapshot.val());
resolve();
});
});
callback.should.be.calledWith({
key2: DatabaseContents.ISSUES[521].key2,
key3: DatabaseContents.ISSUES[521].key3,
});
callback.should.be.calledOnce();
return Promise.resolve();
});
it('on() returns correct subsequent results', async () => {
// Setup
const ref = firebase.native.database().ref('tests/issues/521').orderByChild('string').limitToLast(2);
const callback = sinon.spy();
// Test
await new Promise((resolve) => {
ref.on('value', (snapshot) => {
callback(snapshot.val());
resolve();
});
});
callback.should.be.calledWith({
key2: DatabaseContents.ISSUES[521].key2,
key3: DatabaseContents.ISSUES[521].key3,
});
callback.should.be.calledOnce();
const newDataValue = {
name: 'Item 4',
number: 4,
string: 'item4',
};
const newRef = firebase.native.database().ref('tests/issues/521/key4');
await newRef.set(newDataValue);
await new Promise((resolve) => {
setTimeout(() => resolve(), 5);
});
// Assertions
callback.should.be.calledWith({
key3: DatabaseContents.ISSUES[521].key3,
key4: newDataValue,
});
callback.should.be.calledTwice();
return Promise.resolve();
});
});
});
}
export default issueTests;

View File

@@ -297,6 +297,167 @@ function offTests({ describe, it, xcontext, context, firebase }) {
});
});
context('when 2 different child_added callbacks on the same path', () => {
context('that has been added and removed in the same order', () => {
it('must be completely removed', async () => {
// Setup
const spyA = sinon.spy();
let callbackA;
const spyB = sinon.spy();
let callbackB;
const ref = firebase.native.database().ref('tests/types/array');
const arrayLength = DatabaseContents.DEFAULT.array.length;
// Attach callbackA
await new Promise((resolve) => {
callbackA = () => {
spyA();
resolve();
};
ref.on('child_added', callbackA);
});
// Attach callbackB
await new Promise((resolve) => {
callbackB = () => {
spyB();
resolve();
};
ref.on('child_added', callbackB);
});
// Add a delay to ensure that the .on() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
spyA.should.have.callCount(arrayLength);
spyB.should.have.callCount(arrayLength);
// Undo the first callback
const resp = await ref.off('child_added', callbackA);
should(resp, undefined);
// Trigger the event the callback is listening to
await ref.push(DatabaseContents.DEFAULT.number);
// Add a delay to ensure that the .set() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
// CallbackA should have been called zero more times its attachment
// has been removed, and callBackB only one more time becuase it's still attached
spyA.should.have.callCount(arrayLength);
spyB.should.have.callCount(arrayLength + 1);
// Undo the second attachment
const resp2 = await ref.off('child_added', callbackB);
should(resp2, undefined);
// Trigger the event the callback is listening to
await ref.push(DatabaseContents.DEFAULT.number);
// Add a delay to ensure that the .set() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
// Both Callbacks should not have been called any more times
spyA.should.have.callCount(arrayLength);
spyB.should.have.callCount(arrayLength + 1);
});
});
// ******This test is failed*******
context('that has been added and removed in reverse order', () => {
it('must be completely removed', async () => {
// Setup
const spyA = sinon.spy();
let callbackA;
const spyB = sinon.spy();
let callbackB;
const ref = firebase.native.database().ref('tests/types/array');
const arrayLength = DatabaseContents.DEFAULT.array.length;
// Attach callbackA
await new Promise((resolve) => {
callbackA = () => {
spyA();
resolve();
};
ref.on('child_added', callbackA);
});
// Attach callbackB
await new Promise((resolve) => {
callbackB = () => {
spyB();
resolve();
};
ref.on('child_added', callbackB);
});
// Add a delay to ensure that the .on() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
spyA.should.have.callCount(arrayLength);
spyB.should.have.callCount(arrayLength);
// Undo the second callback
const resp = await ref.off('child_added', callbackB);
should(resp, undefined);
// Trigger the event the callback is listening to
await ref.push(DatabaseContents.DEFAULT.number);
// Add a delay to ensure that the .set() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
// CallbackB should have been called zero more times its attachment
// has been removed, and callBackA only one more time becuase it's still attached
spyA.should.have.callCount(arrayLength + 1);
spyB.should.have.callCount(arrayLength);
// Undo the second attachment
const resp2 = await ref.off('child_added', callbackA);
should(resp2, undefined);
// Trigger the event the callback is listening to
await ref.push(DatabaseContents.DEFAULT.number);
// Add a delay to ensure that the .set() has had time to be registered
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 15);
});
// Both Callbacks should not have been called any more times
spyA.should.have.callCount(arrayLength + 1);
spyB.should.have.callCount(arrayLength);
});
});
});
xcontext('when a context', () => {
/**
* @todo Add tests for when a context is passed. Not sure what the intended

View File

@@ -435,6 +435,7 @@ function documentReferenceTests({ describe, it, context, firebase }) {
const doc = await docRef.get();
doc.data().field.should.be.instanceof(Date);
should.equal(doc.data().field.toISOString(), date.toISOString());
should.equal(doc.data().field.getTime(), date.getTime());
});
});

View File

@@ -91,5 +91,28 @@ export default {
uid: 'aNYxLexOb2WsXGOPiEAu47q5bxH3',
},
},
489: {
long1: 1508777379000,
},
// https://github.com/invertase/react-native-firebase/issues/521
521: {
key1: {
name: 'Item 1',
number: 1,
string: 'item1',
},
key3: {
name: 'Item 3',
number: 3,
string: 'item3',
},
key2: {
name: 'Item 2',
number: 2,
string: 'item2',
},
},
},
};