@@ -15,15 +15,22 @@ jest.dontMock('../ParseError');
15
15
jest . dontMock ( '../ParseObject' ) ;
16
16
jest . dontMock ( '../ParseQuery' ) ;
17
17
jest . dontMock ( '../Push' ) ;
18
+ jest . dontMock ( '../parseDate' ) ;
19
+ jest . dontMock ( '../ObjectStateMutations' ) ;
20
+ jest . dontMock ( '../SingleInstanceStateController' ) ;
21
+ jest . dontMock ( '../UniqueInstanceStateController' ) ;
18
22
19
23
const Cloud = require ( '../Cloud' ) ;
20
24
const CoreManager = require ( '../CoreManager' ) ;
21
25
const Push = require ( '../Push' ) ;
26
+ const ParseObject = require ( '../ParseObject' ) . default ;
22
27
23
28
const defaultController = CoreManager . getCloudController ( ) ;
24
29
25
30
describe ( 'Cloud' , ( ) => {
26
31
beforeEach ( ( ) => {
32
+ ParseObject . enableSingleInstance ( ) ;
33
+
27
34
const run = jest . fn ( ) ;
28
35
const getJobsData = jest . fn ( ) ;
29
36
const startJob = jest . fn ( ) ;
@@ -216,6 +223,48 @@ describe('CloudController', () => {
216
223
} ) ;
217
224
} ) ;
218
225
226
+ it ( 'run same function twice with different responses' , async ( ) => {
227
+ const request = jest . fn ( ) ;
228
+ request . mockReturnValue (
229
+ Promise . resolve ( {
230
+ success : true ,
231
+ result : {
232
+ objectId : 'abc123' ,
233
+ className : 'Item' ,
234
+ __type : 'Object' ,
235
+ createdAt : '2015-01-01T00:00:00.000Z' ,
236
+ updatedAt : '2015-01-01T00:00:00.000Z' ,
237
+ label : 'foobar' ,
238
+ } ,
239
+ } )
240
+ ) ;
241
+
242
+ const ajax = jest . fn ( ) ;
243
+ CoreManager . setRESTController ( { request : request , ajax : ajax } ) ;
244
+
245
+ const response1 = await Cloud . run ( 'myfunction' ) ;
246
+ expect ( response1 . get ( 'label' ) ) . toBe ( 'foobar' ) ;
247
+
248
+ request . mockReturnValue (
249
+ Promise . resolve ( {
250
+ success : true ,
251
+ result : {
252
+ objectId : 'abc123' ,
253
+ className : 'Item' ,
254
+ __type : 'Object' ,
255
+ createdAt : '2015-01-01T00:00:00.000Z' ,
256
+ updatedAt : '2015-01-01T00:00:00.000Z' ,
257
+ label2 : 'control to confirm correct mock usage' ,
258
+ // Note that 'label' is not returned
259
+ } ,
260
+ } )
261
+ ) ;
262
+
263
+ const response2 = await Cloud . run ( 'myfunction' ) ;
264
+ expect ( response2 . get ( 'label2' ) ) . toBe ( 'control to confirm correct mock usage' ) ;
265
+ expect ( response2 . get ( 'label' ) ) . toBe ( undefined ) ; // Failing test PR #1442
266
+ } ) ;
267
+
219
268
it ( 'startJob passes encoded requests' , ( ) => {
220
269
Cloud . startJob ( 'myJob' , {
221
270
value : 12 ,
0 commit comments