@@ -142,9 +142,13 @@ describe('MutationBatch', function() {
142142 expect ( thirdPromiseResult ) . toBe ( null ) ;
143143 expect ( thirdPromiseError ) . toEqual ( expectedThirdError ) ;
144144 expect ( batchPromiseResolved ) . toBe ( true ) ;
145+
146+ // Once dispatched, the batch cannot be dispatched or aborted anymore.
147+ expect ( function ( ) { batch . dispatch ( ) ; } ) . toThrow ( ) ;
148+ expect ( function ( ) { batch . abort ( ) ; } ) . toThrow ( ) ;
145149 } ) ;
146150
147- it ( 'resolves promises even when request fails' , function ( ) {
151+ it ( 'rejects promises when the entire request fails' , function ( ) {
148152 Parse . XMLHttpRequest = testXHR (
149153 function ( ) { } ,
150154 function ( ) { } ,
@@ -189,6 +193,49 @@ describe('MutationBatch', function() {
189193 expect ( firstPromiseError ) . toBe ( secondPromiseError ) ;
190194 expect ( batchPromiseError ) . toBe ( firstPromiseError ) ;
191195 expect ( batchPromiseSuccess ) . toBe ( false ) ;
196+
197+ // Once dispatched, the batch cannot be dispatched or aborted anymore.
198+ expect ( function ( ) { batch . dispatch ( ) ; } ) . toThrow ( ) ;
199+ expect ( function ( ) { batch . abort ( ) ; } ) . toThrow ( ) ;
200+ } ) ;
201+
202+ it ( 'rejects promises when the mutation is aborted' , function ( ) {
203+ var batch = new MutationBatch ( ) ;
204+ var firstPromise = batch . addRequest ( {
205+ method : 'DELETE' ,
206+ route : 'classes' ,
207+ className : 'MadeUpClassName' ,
208+ objectId : 'randomId' ,
209+ } ) ;
210+ var secondPromise = batch . addRequest ( {
211+ method : 'CREATE' ,
212+ route : 'classes' ,
213+ className : 'MadeUpClassName' ,
214+ data : { some : 'fields' , and : 'stuff' } ,
215+ } ) ;
216+
217+ var firstPromiseResult = null ;
218+ var firstPromiseError = null ;
219+ var secondPromiseResult = null ;
220+ var secondPromiseError = null ;
221+ firstPromise . then (
222+ function ( result ) { firstPromiseResult = result ; } ,
223+ function ( error ) { firstPromiseError = error ; }
224+ ) ;
225+ secondPromise . then (
226+ function ( result ) { secondPromiseResult = result ; } ,
227+ function ( error ) { secondPromiseError = error ; }
228+ ) ;
229+ batch . abort ( )
230+
231+ expect ( firstPromiseResult ) . toBe ( null ) ;
232+ expect ( secondPromiseResult ) . toBe ( null ) ;
233+ expect ( firstPromiseError instanceof Error ) . toBe ( true ) ;
234+ expect ( secondPromiseError instanceof Error ) . toBe ( true ) ;
235+
236+ // Once aborted, the batch cannot be dispatched or aborted anymore.
237+ expect ( function ( ) { batch . dispatch ( ) ; } ) . toThrow ( ) ;
238+ expect ( function ( ) { batch . abort ( ) ; } ) . toThrow ( ) ;
192239 } ) ;
193240
194241} ) ;
0 commit comments