@@ -313,6 +313,50 @@ describe('matchesQuery', function () {
313
313
expect ( matchesQuery ( player , orQuery ) ) . toBe ( true ) ;
314
314
} ) ;
315
315
316
+ it ( 'matches an $and query' , ( ) => {
317
+ const player = {
318
+ id : new Id ( 'Player' , 'P1' ) ,
319
+ name : 'Player 1' ,
320
+ score : 12 ,
321
+ } ;
322
+
323
+ const q = new Parse . Query ( 'Player' ) ;
324
+ q . equalTo ( 'name' , 'Player 1' ) ;
325
+ const q2 = new Parse . Query ( 'Player' ) ;
326
+ q2 . equalTo ( 'score' , 12 ) ;
327
+ const q3 = new Parse . Query ( 'Player' ) ;
328
+ q3 . equalTo ( 'score' , 100 ) ;
329
+ const andQuery1 = Parse . Query . and ( q , q2 ) ;
330
+ const andQuery2 = Parse . Query . and ( q , q3 ) ;
331
+ expect ( matchesQuery ( player , q ) ) . toBe ( true ) ;
332
+ expect ( matchesQuery ( player , q2 ) ) . toBe ( true ) ;
333
+ expect ( matchesQuery ( player , andQuery1 ) ) . toBe ( true ) ;
334
+ expect ( matchesQuery ( player , andQuery2 ) ) . toBe ( false ) ;
335
+ } ) ;
336
+
337
+ it ( 'matches an $nor query' , ( ) => {
338
+ const player = {
339
+ id : new Id ( 'Player' , 'P1' ) ,
340
+ name : 'Player 1' ,
341
+ score : 12 ,
342
+ } ;
343
+
344
+ const q = new Parse . Query ( 'Player' ) ;
345
+ q . equalTo ( 'name' , 'Player 1' ) ;
346
+ const q2 = new Parse . Query ( 'Player' ) ;
347
+ q2 . equalTo ( 'name' , 'Player 2' ) ;
348
+ const q3 = new Parse . Query ( 'Player' ) ;
349
+ q3 . equalTo ( 'name' , 'Player 3' ) ;
350
+
351
+ const norQuery1 = Parse . Query . nor ( q , q2 ) ;
352
+ const norQuery2 = Parse . Query . nor ( q2 , q3 ) ;
353
+ expect ( matchesQuery ( player , q ) ) . toBe ( true ) ;
354
+ expect ( matchesQuery ( player , q2 ) ) . toBe ( false ) ;
355
+ expect ( matchesQuery ( player , q3 ) ) . toBe ( false ) ;
356
+ expect ( matchesQuery ( player , norQuery1 ) ) . toBe ( false ) ;
357
+ expect ( matchesQuery ( player , norQuery2 ) ) . toBe ( true ) ;
358
+ } ) ;
359
+
316
360
it ( 'matches $regex queries' , function ( ) {
317
361
const player = {
318
362
id : new Id ( 'Player' , 'P1' ) ,
@@ -632,4 +676,99 @@ describe('matchesQuery', function () {
632
676
q . greaterThanOrEqualTo ( 'dateJSON' , now ) ;
633
677
expect ( matchesQuery ( Object . assign ( { } , obj ) , q ) ) . toBe ( true ) ;
634
678
} ) ;
679
+
680
+ it ( 'should support containedBy query' , ( ) => {
681
+ const obj1 = {
682
+ id : new Id ( 'Numbers' , 'N1' ) ,
683
+ numbers : [ 0 , 1 , 2 ] ,
684
+ } ;
685
+ const obj2 = {
686
+ id : new Id ( 'Numbers' , 'N2' ) ,
687
+ numbers : [ 2 , 0 ] ,
688
+ } ;
689
+ const obj3 = {
690
+ id : new Id ( 'Numbers' , 'N3' ) ,
691
+ numbers : [ 1 , 2 , 3 , 4 ] ,
692
+ } ;
693
+
694
+ const q = new Parse . Query ( 'Numbers' ) ;
695
+ q . containedBy ( 'numbers' , [ 1 , 2 , 3 , 4 , 5 ] ) ;
696
+ expect ( matchesQuery ( obj1 , q ) ) . toBe ( false ) ;
697
+ expect ( matchesQuery ( obj2 , q ) ) . toBe ( false ) ;
698
+ expect ( matchesQuery ( obj3 , q ) ) . toBe ( true ) ;
699
+ } ) ;
700
+
701
+ it ( 'should support withinPolygon query' , ( ) => {
702
+ const sacramento = {
703
+ id : new Id ( 'Location' , 'L1' ) ,
704
+ location : new Parse . GeoPoint ( 38.52 , - 121.5 ) ,
705
+ name : 'Sacramento' ,
706
+ } ;
707
+ const honolulu = {
708
+ id : new Id ( 'Location' , 'L2' ) ,
709
+ location : new Parse . GeoPoint ( 21.35 , - 157.93 ) ,
710
+ name : 'Honolulu' ,
711
+ } ;
712
+ const sf = {
713
+ id : new Id ( 'Location' , 'L3' ) ,
714
+ location : new Parse . GeoPoint ( 37.75 , - 122.68 ) ,
715
+ name : 'San Francisco' ,
716
+ } ;
717
+
718
+ const points = [
719
+ new Parse . GeoPoint ( 37.85 , - 122.33 ) ,
720
+ new Parse . GeoPoint ( 37.85 , - 122.9 ) ,
721
+ new Parse . GeoPoint ( 37.68 , - 122.9 ) ,
722
+ new Parse . GeoPoint ( 37.68 , - 122.33 ) ,
723
+ ] ;
724
+ const q = new Parse . Query ( 'Location' ) ;
725
+ q . withinPolygon ( 'location' , points ) ;
726
+
727
+ expect ( matchesQuery ( sacramento , q ) ) . toBe ( false ) ;
728
+ expect ( matchesQuery ( honolulu , q ) ) . toBe ( false ) ;
729
+ expect ( matchesQuery ( sf , q ) ) . toBe ( true ) ;
730
+ } ) ;
731
+
732
+ it ( 'should support polygonContains query' , ( ) => {
733
+ const p1 = [
734
+ [ 0 , 0 ] ,
735
+ [ 0 , 1 ] ,
736
+ [ 1 , 1 ] ,
737
+ [ 1 , 0 ] ,
738
+ ] ;
739
+ const p2 = [
740
+ [ 0 , 0 ] ,
741
+ [ 0 , 2 ] ,
742
+ [ 2 , 2 ] ,
743
+ [ 2 , 0 ] ,
744
+ ] ;
745
+ const p3 = [
746
+ [ 10 , 10 ] ,
747
+ [ 10 , 15 ] ,
748
+ [ 15 , 15 ] ,
749
+ [ 15 , 10 ] ,
750
+ [ 10 , 10 ] ,
751
+ ] ;
752
+
753
+ const obj1 = {
754
+ id : new Id ( 'Bounds' , 'B1' ) ,
755
+ polygon : new Parse . Polygon ( p1 ) ,
756
+ } ;
757
+ const obj2 = {
758
+ id : new Id ( 'Bounds' , 'B2' ) ,
759
+ polygon : new Parse . Polygon ( p2 ) ,
760
+ } ;
761
+ const obj3 = {
762
+ id : new Id ( 'Bounds' , 'B3' ) ,
763
+ polygon : new Parse . Polygon ( p3 ) ,
764
+ } ;
765
+
766
+ const point = new Parse . GeoPoint ( 0.5 , 0.5 ) ;
767
+ const q = new Parse . Query ( 'Bounds' ) ;
768
+ q . polygonContains ( 'polygon' , point ) ;
769
+
770
+ expect ( matchesQuery ( obj1 , q ) ) . toBe ( true ) ;
771
+ expect ( matchesQuery ( obj2 , q ) ) . toBe ( true ) ;
772
+ expect ( matchesQuery ( obj3 , q ) ) . toBe ( false ) ;
773
+ } ) ;
635
774
} ) ;
0 commit comments