@@ -754,6 +754,109 @@ describe('Parse.Query testing', () => {
754
754
} ) ;
755
755
} ) ;
756
756
757
+ it ( 'containedBy pointer array' , ( done ) => {
758
+ const objects = Array . from ( Array ( 10 ) . keys ( ) ) . map ( ( idx ) => {
759
+ const obj = new Parse . Object ( 'Object' ) ;
760
+ obj . set ( 'key' , idx ) ;
761
+ return obj ;
762
+ } ) ;
763
+
764
+ const parent = new Parse . Object ( 'Parent' ) ;
765
+ const parent2 = new Parse . Object ( 'Parent' ) ;
766
+ const parent3 = new Parse . Object ( 'Parent' ) ;
767
+
768
+ Parse . Object . saveAll ( objects ) . then ( ( ) => {
769
+ // [0, 1, 2]
770
+ parent . set ( 'objects' , objects . slice ( 0 , 3 ) ) ;
771
+
772
+ const shift = objects . shift ( ) ;
773
+ // [2, 0]
774
+ parent2 . set ( 'objects' , [ objects [ 1 ] , shift ] ) ;
775
+
776
+ // [1, 2, 3, 4]
777
+ parent3 . set ( 'objects' , objects . slice ( 1 , 4 ) ) ;
778
+
779
+ return Parse . Object . saveAll ( [ parent , parent2 , parent3 ] ) ;
780
+ } ) . then ( ( ) => {
781
+ // [1, 2, 3, 4, 5, 6, 7, 8, 9]
782
+ const pointers = objects . map ( object => object . toPointer ( ) ) ;
783
+
784
+ // Return all Parent where all parent.objects are contained in objects
785
+ return rp . get ( {
786
+ url : Parse . serverURL + "/classes/Parent" ,
787
+ json : {
788
+ where : {
789
+ objects : {
790
+ $containedBy : pointers
791
+ }
792
+ }
793
+ } ,
794
+ headers : {
795
+ 'X-Parse-Application-Id' : Parse . applicationId ,
796
+ 'X-Parse-Javascript-Key' : Parse . javaScriptKey
797
+ }
798
+ } ) ;
799
+ } ) . then ( ( results ) => {
800
+ expect ( results . results [ 0 ] . objectId ) . not . toBeUndefined ( ) ;
801
+ expect ( results . results [ 0 ] . objectId ) . toBe ( parent3 . id ) ;
802
+ expect ( results . results . length ) . toBe ( 1 ) ;
803
+ done ( ) ;
804
+ } ) ;
805
+ } ) ;
806
+
807
+
808
+ it ( 'containedBy number array' , ( done ) => {
809
+ const options = Object . assign ( { } , masterKeyOptions , {
810
+ body : {
811
+ where : { numbers : { $containedBy : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] } } ,
812
+ }
813
+ } ) ;
814
+ const obj1 = new TestObject ( { numbers : [ 0 , 1 , 2 ] } ) ;
815
+ const obj2 = new TestObject ( { numbers : [ 2 , 0 ] } ) ;
816
+ const obj3 = new TestObject ( { numbers : [ 1 , 2 , 3 , 4 ] } ) ;
817
+ Parse . Object . saveAll ( [ obj1 , obj2 , obj3 ] ) . then ( ( ) => {
818
+ return rp . get ( Parse . serverURL + "/classes/TestObject" , options ) ;
819
+ } ) . then ( ( results ) => {
820
+ expect ( results . results [ 0 ] . objectId ) . not . toBeUndefined ( ) ;
821
+ expect ( results . results [ 0 ] . objectId ) . toBe ( obj3 . id ) ;
822
+ expect ( results . results . length ) . toBe ( 1 ) ;
823
+ done ( ) ;
824
+ } ) ;
825
+ } ) ;
826
+
827
+ it ( 'containedBy empty array' , ( done ) => {
828
+ const options = Object . assign ( { } , masterKeyOptions , {
829
+ body : {
830
+ where : { numbers : { $containedBy : [ ] } } ,
831
+ }
832
+ } ) ;
833
+ const obj1 = new TestObject ( { numbers : [ 0 , 1 , 2 ] } ) ;
834
+ const obj2 = new TestObject ( { numbers : [ 2 , 0 ] } ) ;
835
+ const obj3 = new TestObject ( { numbers : [ 1 , 2 , 3 , 4 ] } ) ;
836
+ Parse . Object . saveAll ( [ obj1 , obj2 , obj3 ] ) . then ( ( ) => {
837
+ return rp . get ( Parse . serverURL + "/classes/TestObject" , options ) ;
838
+ } ) . then ( ( results ) => {
839
+ expect ( results . results . length ) . toBe ( 0 ) ;
840
+ done ( ) ;
841
+ } ) ;
842
+ } ) ;
843
+
844
+ it ( 'containedBy invalid query' , ( done ) => {
845
+ const options = Object . assign ( { } , masterKeyOptions , {
846
+ body : {
847
+ where : { objects : { $containedBy : 1234 } } ,
848
+ }
849
+ } ) ;
850
+ const obj = new TestObject ( ) ;
851
+ obj . save ( ) . then ( ( ) => {
852
+ return rp . get ( Parse . serverURL + "/classes/TestObject" , options ) ;
853
+ } ) . then ( done . fail ) . catch ( ( error ) => {
854
+ equal ( error . error . code , Parse . Error . INVALID_JSON ) ;
855
+ equal ( error . error . error , 'bad $containedBy: should be an array' ) ;
856
+ done ( ) ;
857
+ } ) ;
858
+ } ) ;
859
+
757
860
const BoxedNumber = Parse . Object . extend ( {
758
861
className : "BoxedNumber"
759
862
} ) ;
0 commit comments