@@ -4,6 +4,16 @@ const assert = require('assert');
4
4
const Parse = require ( '../../node' ) ;
5
5
const sleep = require ( './sleep' ) ;
6
6
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
+
7
17
describe ( 'Parse Cloud' , ( ) => {
8
18
it ( 'run function' , done => {
9
19
const params = { key1 : 'value2' , key2 : 'value1' } ;
@@ -86,14 +96,8 @@ describe('Parse Cloud', () => {
86
96
it ( 'run job' , async ( ) => {
87
97
const params = { startedBy : 'Monty Python' } ;
88
98
const jobStatusId = await Parse . Cloud . startJob ( 'CloudJob1' , params ) ;
99
+ await waitForJobStatus ( jobStatusId , 'succeeded' ) ;
89
100
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
- }
97
101
const jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
98
102
assert . equal ( jobStatus . get ( 'status' ) , 'succeeded' ) ;
99
103
assert . equal ( jobStatus . get ( 'params' ) . startedBy , 'Monty Python' ) ;
@@ -104,14 +108,8 @@ describe('Parse Cloud', () => {
104
108
105
109
let jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
106
110
assert . equal ( jobStatus . get ( 'status' ) , 'running' ) ;
111
+ await waitForJobStatus ( jobStatusId , 'succeeded' ) ;
107
112
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
- }
115
113
jobStatus = await Parse . Cloud . getJobStatus ( jobStatusId ) ;
116
114
assert . equal ( jobStatus . get ( 'status' ) , 'succeeded' ) ;
117
115
} ) ;
@@ -126,16 +124,13 @@ describe('Parse Cloud', () => {
126
124
} ) ;
127
125
} ) ;
128
126
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' ) ;
139
134
} ) ;
140
135
141
136
it ( 'get jobs data' , done => {
0 commit comments