diff --git a/src/database/firebase_list_factory.spec.ts b/src/database/firebase_list_factory.spec.ts index 5fda83fc3..e67bbd7f7 100644 --- a/src/database/firebase_list_factory.spec.ts +++ b/src/database/firebase_list_factory.spec.ts @@ -477,6 +477,63 @@ describe('FirebaseListFactory', () => { }); + it('should support null for equalTo queries', (done: any) => { + + questions.$ref.ref.set({ + val1, + val2: Object.assign({}, val2, { extra: true }), + val3: Object.assign({}, val3, { extra: true }), + }) + .then(() => { + + var query = FirebaseListFactory(questions.$ref.ref, { + query: { + orderByChild: "extra", + equalTo: null + } + }); + + take.call(query, 1).subscribe( + (list) => { + expect(list.length).toEqual(1); + expect(list[0].$key).toEqual("val1"); + done(); + }, + done.fail + ); + }); + }); + + + it('should support null for startAt/endAt queries', (done: any) => { + + questions.$ref.ref.set({ + val1, + val2: Object.assign({}, val2, { extra: true }), + val3: Object.assign({}, val3, { extra: true }), + }) + .then(() => { + + var query = FirebaseListFactory(questions.$ref.ref, { + query: { + orderByChild: "extra", + startAt: null, + endAt: null + } + }); + + take.call(query, 1).subscribe( + (list) => { + expect(list.length).toEqual(1); + expect(list[0].$key).toEqual("val1"); + done(); + }, + done.fail + ); + }); + }); + + it('should call off on all events when disposed', (done: any) => { const questionRef = firebase.database().ref().child('questions'); var firebaseSpy = spyOn(questionRef, 'off').and.callThrough(); diff --git a/src/database/query_observable.spec.ts b/src/database/query_observable.spec.ts index 6859633df..328d9cd38 100644 --- a/src/database/query_observable.spec.ts +++ b/src/database/query_observable.spec.ts @@ -431,6 +431,55 @@ describe('query combinations', () => { }); +describe('null values', () => { + + it('should build an equalTo() query with a null scalar value', (done: any) => { + scalarQueryTest({ + orderByChild: 'height', + equalTo: null + }, done); + }); + + it('should build a startAt() query with a null scalar value', (done: any) => { + scalarQueryTest({ + orderByChild: 'height', + startAt: null + }, done); + }); + + it('should build an endAt() query with a null scalar value', (done: any) => { + scalarQueryTest({ + orderByChild: 'height', + endAt: null + }, done); + }); + + it('should build an equalTo() query with a null observable value', (done: any) => { + const query = { + orderByChild: 'height', + equalTo: new Subject() + }; + observableQueryTest(query, { equalTo: null }, done); + }); + + it('should build a startAt() query with a null observable value', (done: any) => { + const query = { + orderByChild: 'height', + startAt: new Subject() + }; + observableQueryTest(query, { startAt: null }, done); + }); + + it('should build an endAt() query with a null observable value', (done: any) => { + const query = { + orderByChild: 'height', + endAt: new Subject() + }; + observableQueryTest(query, { endAt: null }, done); + }); + +}); + describe('audited queries', () => { it('should immediately emit if not audited', () => { diff --git a/src/database/query_observable.ts b/src/database/query_observable.ts index 71b4e0108..2c542598f 100644 --- a/src/database/query_observable.ts +++ b/src/database/query_observable.ts @@ -15,7 +15,7 @@ import { LimitToSelection, Primitive } from '../interfaces'; -import { isNil } from '../utils'; +import { hasKey, isNil } from '../utils'; export function observeQuery(query: Query, audit: boolean = true): Observable { if (isNil(query)) { @@ -68,15 +68,15 @@ export function observeQuery(query: Query, audit: boolean = true): Observable { if (query.startAt instanceof Observable) { return query.startAt; - } else if (typeof query.startAt !== 'undefined') { + } else if (hasKey(query, 'startAt')) { return new Observable(subscriber => { subscriber.next(query.startAt); }); } else { return new Observable(subscriber => { - subscriber.next(null); + subscriber.next(undefined); }); } } @@ -141,13 +141,13 @@ export function getStartAtObservable(query: Query): Observable { export function getEndAtObservable(query: Query): Observable { if (query.endAt instanceof Observable) { return query.endAt; - } else if (typeof query.endAt !== 'undefined') { + } else if (hasKey(query, 'endAt')) { return new Observable(subscriber => { subscriber.next(query.endAt); }); } else { return new Observable(subscriber => { - subscriber.next(null); + subscriber.next(undefined); }); } } @@ -155,13 +155,13 @@ export function getEndAtObservable(query: Query): Observable { export function getEqualToObservable(query: Query): Observable { if (query.equalTo instanceof Observable) { return query.equalTo; - } else if (typeof query.equalTo !== 'undefined') { + } else if (hasKey(query, 'equalTo')) { return new Observable(subscriber => { subscriber.next(query.equalTo); }); } else { return new Observable(subscriber => { - subscriber.next(null); + subscriber.next(undefined); }); } }