@@ -117,22 +117,29 @@ describe(' firestore().collection().where(AND Filters)', function () {
117117 . where ( Filter . and ( Filter ( 'foo.bar' , '==' , null ) , Filter ( 'foo.bar' , '!=' , null ) ) ) ;
118118 } ) ;
119119
120- it ( 'throws if multiple inequalities on different paths is provided' , function ( ) {
121- try {
122- firebase
123- . firestore ( )
124- . collection ( COLLECTION )
125- . where ( Filter . and ( Filter ( 'foo.bar' , '>' , 123 ) , Filter ( 'bar' , '>' , 123 ) ) ) ;
120+ it ( 'allows multiple inequalities (excluding `!=`) on different paths provided' , async function ( ) {
121+ const colRef = firebase
122+ . firestore ( )
123+ . collection ( `${ COLLECTION } /filter/different-path-inequality-filter` ) ;
124+ const expected = { foo : { bar : 300 } , bar : 200 } ;
125+ await Promise . all ( [
126+ colRef . add ( { foo : { bar : 1 } , bar : 1 } ) ,
127+ colRef . add ( expected ) ,
128+ colRef . add ( expected ) ,
129+ ] ) ;
126130
127- return Promise . reject ( new Error ( 'Did not throw an Error.' ) ) ;
128- } catch ( error ) {
129- error . message . should . containEql ( 'All where filters with an inequality' ) ;
130- return Promise . resolve ( ) ;
131- }
131+ const snapshot = await colRef
132+ . where ( Filter . and ( Filter ( 'foo.bar' , '>' , 123 ) , Filter ( 'bar' , '>' , 123 ) ) )
133+ . get ( ) ;
134+
135+ snapshot . size . should . eql ( 2 ) ;
136+ snapshot . forEach ( s => {
137+ s . data ( ) . should . eql ( jet . contextify ( expected ) ) ;
138+ } ) ;
132139 } ) ;
133140
134- it ( 'allows inequality on the same path' , function ( ) {
135- firebase
141+ it ( 'allows inequality on the same path' , async function ( ) {
142+ await firebase
136143 . firestore ( )
137144 . collection ( COLLECTION )
138145 . where (
@@ -323,38 +330,24 @@ describe(' firestore().collection().where(AND Filters)', function () {
323330 }
324331 } ) ;
325332
326- it ( "should throw error when combining '!=' operator with any other inequality operator on a different field" , async function ( ) {
327- const ref = firebase . firestore ( ) . collection ( COLLECTION ) ;
328-
329- try {
330- ref . where ( Filter . and ( Filter ( 'foo.bar' , '!=' , 1 ) , Filter ( 'differentField' , '>' , 2 ) ) ) ;
331- return Promise . reject ( new Error ( 'Did not throw an Error on >.' ) ) ;
332- } catch ( error ) {
333- error . message . should . containEql ( 'must be on the same field.' ) ;
334- }
335-
336- try {
337- ref . where ( Filter . and ( Filter ( 'foo.bar' , '!=' , 1 ) , Filter ( 'differentField' , '<' , 2 ) ) ) ;
338- return Promise . reject ( new Error ( 'Did not throw an Error on <.' ) ) ;
339- } catch ( error ) {
340- error . message . should . containEql ( 'must be on the same field.' ) ;
341- }
342-
343- try {
344- ref . where ( Filter . and ( Filter ( 'foo.bar' , '!=' , 1 ) , Filter ( 'differentField' , '<=' , 2 ) ) ) ;
345- return Promise . reject ( new Error ( 'Did not throw an Error <=.' ) ) ;
346- } catch ( error ) {
347- error . message . should . containEql ( 'must be on the same field.' ) ;
348- }
349-
350- try {
351- ref . where ( Filter . and ( Filter ( 'foo.bar' , '!=' , 1 ) , Filter ( 'differentField' , '>=' , 2 ) ) ) ;
352- return Promise . reject ( new Error ( 'Did not throw an Error >=.' ) ) ;
353- } catch ( error ) {
354- error . message . should . containEql ( 'must be on the same field.' ) ;
355- }
333+ it ( "should allow query when combining '!=' operator with any other inequality operator on a different field" , async function ( ) {
334+ const colRef = firebase
335+ . firestore ( )
336+ . collection ( `${ COLLECTION } /filter/inequality-combine-not-equal` ) ;
337+ const expected = { foo : { bar : 300 } , bar : 200 } ;
338+ await Promise . all ( [
339+ colRef . add ( { foo : { bar : 1 } , bar : 1 } ) ,
340+ colRef . add ( expected ) ,
341+ colRef . add ( expected ) ,
342+ ] ) ;
356343
357- return Promise . resolve ( ) ;
344+ const snapshot = await colRef
345+ . where ( Filter . and ( Filter ( 'foo.bar' , '>' , 123 ) , Filter ( 'bar' , '!=' , 123 ) ) )
346+ . get ( ) ;
347+ snapshot . size . should . eql ( 2 ) ;
348+ snapshot . forEach ( s => {
349+ s . data ( ) . should . eql ( jet . contextify ( expected ) ) ;
350+ } ) ;
358351 } ) ;
359352
360353 /* Queries */
@@ -774,19 +767,26 @@ describe(' firestore().collection().where(AND Filters)', function () {
774767 ) ;
775768 } ) ;
776769
777- it ( 'throws if multiple inequalities on different paths is provided' , function ( ) {
770+ it ( 'allows multiple inequalities (excluding `!=`) on different paths provided' , async function ( ) {
778771 const { getFirestore, collection, query, and, where } = firestoreModular ;
779- try {
780- query (
781- collection ( getFirestore ( ) , COLLECTION ) ,
782- and ( where ( 'foo.bar' , '>' , 123 ) , where ( 'bar' , '>' , 123 ) ) ,
783- ) ;
772+ const colRef = collection ( getFirestore ( ) , `${ COLLECTION } /filter/different-path-inequality` ) ;
784773
785- return Promise . reject ( new Error ( 'Did not throw an Error.' ) ) ;
786- } catch ( error ) {
787- error . message . should . containEql ( 'All where filters with an inequality' ) ;
788- return Promise . resolve ( ) ;
789- }
774+ const expected = { foo : { bar : 300 } , bar : 200 } ;
775+ await Promise . all ( [
776+ colRef . add ( { foo : { bar : 1 } , bar : 1 } ) ,
777+ colRef . add ( expected ) ,
778+ colRef . add ( expected ) ,
779+ ] ) ;
780+
781+ const snapshot = await query (
782+ colRef ,
783+ and ( where ( 'foo.bar' , '>' , 123 ) , where ( 'bar' , '>' , 123 ) ) ,
784+ ) . get ( ) ;
785+
786+ snapshot . size . should . eql ( 2 ) ;
787+ snapshot . forEach ( s => {
788+ s . data ( ) . should . eql ( jet . contextify ( expected ) ) ;
789+ } ) ;
790790 } ) ;
791791
792792 it ( 'allows inequality on the same path' , function ( ) {
@@ -979,39 +979,26 @@ describe(' firestore().collection().where(AND Filters)', function () {
979979 }
980980 } ) ;
981981
982- it ( "should throw error when combining '!=' operator with any other inequality operator on a different field" , async function ( ) {
983- const { getFirestore, collection, query, where, and } = firestoreModular ;
984- const ref = collection ( getFirestore ( ) , COLLECTION ) ;
985-
986- try {
987- query ( ref , and ( where ( 'foo.bar' , '!=' , 1 ) , where ( 'differentField' , '>' , 2 ) ) ) ;
988- return Promise . reject ( new Error ( 'Did not throw an Error on >.' ) ) ;
989- } catch ( error ) {
990- error . message . should . containEql ( 'must be on the same field.' ) ;
991- }
992-
993- try {
994- query ( ref , and ( where ( 'foo.bar' , '!=' , 1 ) , where ( 'differentField' , '<' , 2 ) ) ) ;
995- return Promise . reject ( new Error ( 'Did not throw an Error on <.' ) ) ;
996- } catch ( error ) {
997- error . message . should . containEql ( 'must be on the same field.' ) ;
998- }
999-
1000- try {
1001- query ( ref , and ( where ( 'foo.bar' , '!=' , 1 ) , where ( 'differentField' , '<=' , 2 ) ) ) ;
1002- return Promise . reject ( new Error ( 'Did not throw an Error <=.' ) ) ;
1003- } catch ( error ) {
1004- error . message . should . containEql ( 'must be on the same field.' ) ;
1005- }
1006-
1007- try {
1008- query ( ref , and ( where ( 'foo.bar' , '!=' , 1 ) , where ( 'differentField' , '>=' , 2 ) ) ) ;
1009- return Promise . reject ( new Error ( 'Did not throw an Error >=.' ) ) ;
1010- } catch ( error ) {
1011- error . message . should . containEql ( 'must be on the same field.' ) ;
1012- }
982+ it ( "should allow query when combining '!=' operator with any other inequality operator on a different field" , async function ( ) {
983+ const { query, where, and } = firestoreModular ;
984+ const colRef = firebase
985+ . firestore ( )
986+ . collection ( `${ COLLECTION } /filter/inequality-combine-not-equal` ) ;
987+ const expected = { foo : { bar : 300 } , bar : 200 } ;
988+ await Promise . all ( [
989+ colRef . add ( { foo : { bar : 1 } , bar : 1 } ) ,
990+ colRef . add ( expected ) ,
991+ colRef . add ( expected ) ,
992+ ] ) ;
1013993
1014- return Promise . resolve ( ) ;
994+ const snapshot = await query (
995+ colRef ,
996+ and ( where ( 'foo.bar' , '>' , 123 ) , where ( 'bar' , '!=' , 123 ) ) ,
997+ ) . get ( ) ;
998+ snapshot . size . should . eql ( 2 ) ;
999+ snapshot . forEach ( s => {
1000+ s . data ( ) . should . eql ( jet . contextify ( expected ) ) ;
1001+ } ) ;
10151002 } ) ;
10161003
10171004 /* Queries */
0 commit comments