@@ -139,15 +139,11 @@ function runTest(controller) {
139
139
assert . equal ( pinnedObject . _localId , undefined ) ;
140
140
} ) ;
141
141
142
- it ( `${ controller . name } cannot pin unsaved pointer` , async ( ) => {
143
- try {
144
- const object = new TestObject ( ) ;
145
- const pointer = new Item ( ) ;
146
- object . set ( 'child' , pointer ) ;
147
- await object . pin ( ) ;
148
- } catch ( e ) {
149
- assert . equal ( e . message , 'Cannot create a pointer to an unsaved ParseObject' ) ;
150
- }
142
+ it ( `${ controller . name } can pin unsaved pointer` , async ( ) => {
143
+ const object = new TestObject ( ) ;
144
+ const pointer = new Item ( ) ;
145
+ object . set ( 'child' , pointer ) ;
146
+ await object . pin ( ) ;
151
147
} ) ;
152
148
153
149
it ( `${ controller . name } can pin user (unsaved)` , async ( ) => {
@@ -2681,6 +2677,54 @@ function runTest(controller) {
2681
2677
const results = await query . find ( ) ;
2682
2678
assert . equal ( results . length , 2 ) ;
2683
2679
} ) ;
2680
+
2681
+ it ( `${ controller . name } can query from pin subclass` , async ( ) => {
2682
+ class ClassA extends Parse . Object {
2683
+ constructor ( ) {
2684
+ super ( 'ClassA' ) ;
2685
+ }
2686
+ get name ( ) { return this . get ( 'name' ) ; }
2687
+ set name ( value ) { this . set ( 'name' , value ) ; }
2688
+ }
2689
+ Parse . Object . registerSubclass ( 'ClassA' , ClassA ) ;
2690
+
2691
+ class ClassB extends Parse . Object {
2692
+ constructor ( ) {
2693
+ super ( 'ClassB' ) ;
2694
+ }
2695
+ get name ( ) { return this . get ( 'name' ) ; }
2696
+ set name ( value ) { this . set ( 'name' , value ) ; }
2697
+
2698
+ get classA ( ) { return this . get ( 'classA' ) ; }
2699
+ set classA ( value ) { this . set ( 'classA' , value ) ; }
2700
+ }
2701
+ Parse . Object . registerSubclass ( 'ClassB' , ClassB ) ;
2702
+
2703
+ const testClassA = new ClassA ( ) ;
2704
+ testClassA . name = 'ABC' ;
2705
+ await testClassA . pin ( ) ;
2706
+
2707
+ const query = new Parse . Query ( ClassA ) ;
2708
+ query . fromLocalDatastore ( ) ;
2709
+ query . equalTo ( 'name' , 'ABC' ) ;
2710
+ const result = await query . first ( ) ;
2711
+ expect ( result . get ( 'name' ) ) . toBe ( 'ABC' ) ;
2712
+
2713
+ const testClassB = new ClassB ( ) ;
2714
+ testClassB . name = 'XYZ' ;
2715
+ testClassB . classA = testClassA ;
2716
+ await testClassB . pin ( ) ;
2717
+
2718
+ let localDatastore = await Parse . LocalDatastore . _getAllContents ( ) ;
2719
+ expect ( localDatastore [ LDS_KEY ( testClassB ) ] [ 0 ] . classA ) . toEqual ( testClassA . toOfflinePointer ( ) ) ;
2720
+
2721
+ await testClassB . save ( ) ;
2722
+ expect ( testClassB . classA ) . toBe ( testClassA ) ;
2723
+ expect ( testClassA . id ) . toBeDefined ( ) ;
2724
+
2725
+ localDatastore = await Parse . LocalDatastore . _getAllContents ( ) ;
2726
+ expect ( localDatastore [ LDS_KEY ( testClassB ) ] [ 0 ] . classA . objectId ) . toEqual ( testClassA . id ) ;
2727
+ } ) ;
2684
2728
} ) ;
2685
2729
}
2686
2730
0 commit comments