File tree Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ describe('Parse LiveQuery', () => {
12
12
beforeEach ( ( done ) => {
13
13
Parse . initialize ( 'integration' ) ;
14
14
Parse . CoreManager . set ( 'SERVER_URL' , 'http://localhost:1337/parse' ) ;
15
+ Parse . User . enableUnsafeCurrentUser ( ) ;
15
16
Parse . Storage . _clear ( ) ;
16
17
clear ( ) . then ( done ) . catch ( done . fail ) ;
17
18
} ) ;
@@ -135,4 +136,23 @@ describe('Parse LiveQuery', () => {
135
136
await sleep ( 1000 ) ;
136
137
assert . equal ( count , 1 ) ;
137
138
} ) ;
139
+
140
+ it ( 'can subscribe to ACL' , async ( done ) => {
141
+ const user = await Parse . User . signUp ( 'ooo' , 'password' ) ;
142
+ const ACL = new Parse . ACL ( user ) ;
143
+
144
+ const object = new TestObject ( ) ;
145
+ object . setACL ( ACL ) ;
146
+ await object . save ( ) ;
147
+
148
+ const query = new Parse . Query ( TestObject ) ;
149
+ query . equalTo ( 'objectId' , object . id ) ;
150
+ const subscription = await query . subscribe ( user . getSessionToken ( ) ) ;
151
+ subscription . on ( 'update' , async ( object ) => {
152
+ assert . equal ( object . get ( 'foo' ) , 'bar' ) ;
153
+ await Parse . User . logOut ( ) ;
154
+ done ( ) ;
155
+ } )
156
+ await object . save ( { foo : 'bar' } ) ;
157
+ } ) ;
138
158
} ) ;
Original file line number Diff line number Diff line change @@ -1483,13 +1483,15 @@ class ParseQuery {
1483
1483
/**
1484
1484
* Subscribe this query to get liveQuery updates
1485
1485
*
1486
+ * @param {String } sessionToken (optional) Defaults to the currentUser
1486
1487
* @return {Promise<LiveQuerySubscription> } Returns the liveQuerySubscription, it's an event emitter
1487
1488
* which can be used to get liveQuery updates.
1488
1489
*/
1489
- async subscribe ( ) : Promise < LiveQuerySubscription > {
1490
+ async subscribe ( sessionToken ?: string ) : Promise < LiveQuerySubscription > {
1490
1491
const currentUser = await CoreManager . getUserController ( ) . currentUserAsync ( ) ;
1491
- const sessionToken = currentUser ? currentUser . getSessionToken ( ) : undefined ;
1492
-
1492
+ if ( ! sessionToken ) {
1493
+ sessionToken = currentUser ? currentUser . getSessionToken ( ) : undefined ;
1494
+ }
1493
1495
const liveQueryClient = await CoreManager . getLiveQueryController ( ) . getDefaultLiveQueryClient ( ) ;
1494
1496
if ( liveQueryClient . shouldOpen ( ) ) {
1495
1497
liveQueryClient . open ( ) ;
Original file line number Diff line number Diff line change @@ -2718,4 +2718,31 @@ describe('ParseQuery LocalDatastore', () => {
2718
2718
expect ( subscription . sessionToken ) . toBeUndefined ( ) ;
2719
2719
expect ( subscription . query ) . toEqual ( query ) ;
2720
2720
} ) ;
2721
+
2722
+ it ( 'can subscribe to query with sessionToken parameter' , async ( ) => {
2723
+ const mockLiveQueryClient = {
2724
+ shouldOpen : function ( ) {
2725
+ return true ;
2726
+ } ,
2727
+ open : function ( ) { } ,
2728
+ subscribe : function ( query , sessionToken ) {
2729
+ return new LiveQuerySubscription ( '0' , query , sessionToken ) ;
2730
+ } ,
2731
+ } ;
2732
+ CoreManager . set ( 'UserController' , {
2733
+ currentUserAsync ( ) {
2734
+ return Promise . resolve ( null ) ;
2735
+ }
2736
+ } ) ;
2737
+ CoreManager . set ( 'LiveQueryController' , {
2738
+ getDefaultLiveQueryClient ( ) {
2739
+ return Promise . resolve ( mockLiveQueryClient ) ;
2740
+ }
2741
+ } ) ;
2742
+ const query = new ParseQuery ( 'TestObject' ) ;
2743
+ const subscription = await query . subscribe ( 'r:test' ) ;
2744
+ expect ( subscription . id ) . toBe ( '0' ) ;
2745
+ expect ( subscription . sessionToken ) . toBe ( 'r:test' ) ;
2746
+ expect ( subscription . query ) . toEqual ( query ) ;
2747
+ } ) ;
2721
2748
} ) ;
You can’t perform that action at this time.
0 commit comments