@@ -4,6 +4,16 @@ const assert = require('assert');
44const Parse = require ( '../../node' ) ;
55const sleep = require ( './sleep' ) ;
66
7+ const waitForJobStatus = async ( jobStatusId , status ) => {
8+ const checkJobStatus = async ( ) => {
9+ const result = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
10+ return result && result . get ( 'status' ) === status ;
11+ } ;
12+ while ( ! ( await checkJobStatus ( ) ) ) {
13+ await sleep ( 100 ) ;
14+ }
15+ } ;
16+
717describe ( 'Parse Cloud' , ( ) => {
818 it ( 'run function' , done => {
919 const params = { key1 : 'value2' , key2 : 'value1' } ;
@@ -86,14 +96,8 @@ describe('Parse Cloud', () => {
8696 it ( 'run job' , async ( ) => {
8797 const params = { startedBy : 'Monty Python' } ;
8898 const jobStatusId = await Parse . Cloud . startJob ( 'CloudJob1' , params ) ;
99+ await waitForJobStatus ( jobStatusId , 'succeeded' ) ;
89100
90- const checkJobStatus = async ( ) => {
91- const result = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
92- return result && result . get ( 'status' ) === 'succeeded' ;
93- } ;
94- while ( ! ( await checkJobStatus ( ) ) ) {
95- await sleep ( 100 ) ;
96- }
97101 const jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
98102 assert . equal ( jobStatus . get ( 'status' ) , 'succeeded' ) ;
99103 assert . equal ( jobStatus . get ( 'params' ) . startedBy , 'Monty Python' ) ;
@@ -104,14 +108,8 @@ describe('Parse Cloud', () => {
104108
105109 let jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
106110 assert . equal ( jobStatus . get ( 'status' ) , 'running' ) ;
111+ await waitForJobStatus ( jobStatusId , 'succeeded' ) ;
107112
108- const checkJobStatus = async ( ) => {
109- const result = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
110- return result && result . get ( 'status' ) === 'succeeded' ;
111- } ;
112- while ( ! ( await checkJobStatus ( ) ) ) {
113- await sleep ( 100 ) ;
114- }
115113 jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
116114 assert . equal ( jobStatus . get ( 'status' ) , 'succeeded' ) ;
117115 } ) ;
@@ -126,16 +124,13 @@ describe('Parse Cloud', () => {
126124 } ) ;
127125 } ) ;
128126
129- it ( 'run failing job' , done => {
130- Parse . Cloud . startJob ( 'CloudJobFailing' )
131- . then ( jobStatusId => {
132- return Parse . Cloud . getJobStatus ( jobStatusId ) ;
133- } )
134- . then ( jobStatus => {
135- assert . equal ( jobStatus . get ( 'status' ) , 'failed' ) ;
136- assert . equal ( jobStatus . get ( 'message' ) , 'cloud job failed' ) ;
137- done ( ) ;
138- } ) ;
127+ it ( 'run failing job' , async ( ) => {
128+ const jobStatusId = await Parse . Cloud . startJob ( 'CloudJobFailing' ) ;
129+ await waitForJobStatus ( jobStatusId , 'failed' ) ;
130+
131+ const jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
132+ assert . equal ( jobStatus . get ( 'status' ) , 'failed' ) ;
133+ assert . equal ( jobStatus . get ( 'message' ) , 'cloud job failed' ) ;
139134 } ) ;
140135
141136 it ( 'get jobs data' , done => {
0 commit comments