[ios][database] query modifiers with float values now correctly query - added 2 issue specific tests - fixes #108

This commit is contained in:
Salakar 2017-05-13 02:38:27 +01:00
parent 7a11a8c6f9
commit bb64cae09c
3 changed files with 72 additions and 6 deletions

View File

@ -219,7 +219,7 @@
type:(NSString *) type
{
if ([type isEqualToString:@"number"]) {
return [NSNumber numberWithInteger:value.integerValue];
return [NSNumber numberWithDouble:value.doubleValue];
} else if ([type isEqualToString:@"boolean"]) {
return [NSNumber numberWithBool:value.boolValue];
} else {

View File

@ -1,9 +1,10 @@
import should from 'should';
import DatabaseContents from '../../support/DatabaseContents';
function childTests({ fdescribe, it, context, firebase }) {
function issueTests({ fdescribe, it, context, firebase }) {
fdescribe('issue_100', () => {
context('returned snapshot should match web API', () => {
it('returns correct child ref', async () => {
context('array-like values should', () => {
it('return null in returned array at positions where a key is missing', async() => {
// Setup
const ref = firebase.native.database().ref('tests/issues/100');
@ -12,13 +13,62 @@ function childTests({ fdescribe, it, context, firebase }) {
return ref.once('value').then((snapshot) => {
// Assertion
console.warn(JSON.stringify(snapshot.val()));
// console.warn(JSON.stringify(snapshot.val()));
snapshot.val().should.eql([null, DatabaseContents.ISSUES[100][1], DatabaseContents.ISSUES[100][2], DatabaseContents.ISSUES[100][3]]);
});
});
});
});
fdescribe('issue_108', () => {
context('filters using floats', () => {
it('return correct results', async() => {
// Setup
const ref = firebase.native.database().ref('tests/issues/108');
// Test
return ref
.orderByChild('latitude')
.startAt(34.00867000999119)
.endAt(34.17462960866099)
.once('value')
.then((snapshot) => {
const val = snapshot.val();
// Assertion
val.foobar.should.eql(DatabaseContents.ISSUES[108].foobar);
should.equal(Object.keys(val).length, 1);
return Promise.resolve();
});
});
it('return correct results when not using float values', async() => {
// Setup
const ref = firebase.native.database().ref('tests/issues/108');
// Test
return ref
.orderByChild('latitude')
.equalTo(37)
.once('value')
.then((snapshot) => {
const val = snapshot.val();
// Assertion
val.notAFloat.should.eql(DatabaseContents.ISSUES[108].notAFloat);
should.equal(Object.keys(val).length, 1);
return Promise.resolve();
});
});
});
});
}
export default childTests;
export default issueTests;

View File

@ -39,5 +39,21 @@ export default {
someOtherKey: 'someOtherValue',
},
},
// https://github.com/invertase/react-native-firebase/issues/108
108: {
foobar: {
name: 'Foobar Pizzas',
latitude: 34.1013717,
},
notTheFoobar: {
name: 'Not the pizza you\'re looking for',
latitude: 34.456787,
},
notAFloat: {
name: 'Not a float',
latitude: 37,
},
},
},
};