@@ -11,11 +11,16 @@ jest.dontMock('../ParseLiveQuery');
11
11
jest . dontMock ( '../CoreManager' ) ;
12
12
jest . dontMock ( '../ParsePromise' ) ;
13
13
jest . dontMock ( '../LiveQueryClient' ) ;
14
+ jest . dontMock ( '../LiveQuerySubscription' ) ;
14
15
jest . dontMock ( '../ParseObject' ) ;
16
+ jest . dontMock ( '../ParsePromise' ) ;
17
+ jest . dontMock ( '../ParseQuery' ) ;
18
+ jest . dontMock ( '../EventEmitter' ) ;
15
19
16
20
const ParseLiveQuery = require ( '../ParseLiveQuery' ) ;
17
21
const CoreManager = require ( '../CoreManager' ) ;
18
22
const ParsePromise = require ( '../ParsePromise' ) . default ;
23
+ const ParseQuery = require ( '../ParseQuery' ) . default ;
19
24
20
25
describe ( 'ParseLiveQuery' , ( ) => {
21
26
beforeEach ( ( ) => {
@@ -99,4 +104,83 @@ describe('ParseLiveQuery', () => {
99
104
done ( ) ;
100
105
} ) ;
101
106
} ) ;
107
+
108
+ it ( 'subscribes to all subscription events' , ( done ) => {
109
+
110
+ CoreManager . set ( 'UserController' , {
111
+ currentUserAsync ( ) {
112
+ return ParsePromise . as ( {
113
+ getSessionToken ( ) {
114
+ return 'token' ;
115
+ }
116
+ } ) ;
117
+ }
118
+ } ) ;
119
+ CoreManager . set ( 'APPLICATION_ID' , 'appid' ) ;
120
+ CoreManager . set ( 'JAVASCRIPT_KEY' , 'jskey' ) ;
121
+ CoreManager . set ( 'LIVEQUERY_SERVER_URL' , null ) ;
122
+
123
+ const controller = CoreManager . getLiveQueryController ( ) ;
124
+
125
+ controller . getDefaultLiveQueryClient ( ) . then ( ( client ) => {
126
+
127
+ const query = new ParseQuery ( "ObjectType" ) ;
128
+ query . equalTo ( "test" , "value" ) ;
129
+ const ourSubscription = controller . subscribe ( query , "close" ) ;
130
+
131
+ var isCalled = { } ;
132
+ [ "open" ,
133
+ "close" ,
134
+ "error" ,
135
+ "create" ,
136
+ "update" ,
137
+ "enter" ,
138
+ "leave" ,
139
+ "delete" ] . forEach ( ( key ) => {
140
+ ourSubscription . on ( key , ( ) => {
141
+ isCalled [ key ] = true ;
142
+ } ) ;
143
+ } ) ;
144
+
145
+ // controller.subscribe() completes asynchronously,
146
+ // so we need to give it a chance to complete before finishing
147
+ setTimeout ( ( ) => {
148
+ try {
149
+ client . connectPromise . resolve ( ) ;
150
+ var actualSubscription = client . subscriptions . get ( 1 ) ;
151
+
152
+ expect ( actualSubscription ) . toBeDefined ( ) ;
153
+
154
+ actualSubscription . emit ( "open" ) ;
155
+ expect ( isCalled [ "open" ] ) . toBe ( true ) ;
156
+
157
+ actualSubscription . emit ( "close" ) ;
158
+ expect ( isCalled [ "close" ] ) . toBe ( true ) ;
159
+
160
+ actualSubscription . emit ( "error" ) ;
161
+ expect ( isCalled [ "error" ] ) . toBe ( true ) ;
162
+
163
+ actualSubscription . emit ( "create" ) ;
164
+ expect ( isCalled [ "create" ] ) . toBe ( true ) ;
165
+
166
+ actualSubscription . emit ( "update" ) ;
167
+ expect ( isCalled [ "update" ] ) . toBe ( true ) ;
168
+
169
+ actualSubscription . emit ( "enter" ) ;
170
+ expect ( isCalled [ "enter" ] ) . toBe ( true ) ;
171
+
172
+ actualSubscription . emit ( "leave" ) ;
173
+ expect ( isCalled [ "leave" ] ) . toBe ( true ) ;
174
+
175
+ actualSubscription . emit ( "delete" ) ;
176
+ expect ( isCalled [ "delete" ] ) . toBe ( true ) ;
177
+
178
+ done ( ) ;
179
+ } catch ( e ) {
180
+ done . fail ( e ) ;
181
+ }
182
+ } , 1 ) ;
183
+ } ) ;
184
+
185
+ } ) ;
102
186
} ) ;
0 commit comments