Skip to content

Commit bc771fa

Browse files
committed
Fix other tests with potential similar problem
1 parent 703c396 commit bc771fa

File tree

1 file changed

+64
-65
lines changed

1 file changed

+64
-65
lines changed

spec/CloudCode.spec.js

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,9 +1565,7 @@ describe('Cloud Code', () => {
15651565
.then(async response => {
15661566
const jobStatusId = response.headers['x-parse-job-status-id'];
15671567
const checkJobStatus = async () => {
1568-
const jobStatus = await new Parse.Query('_JobStatus').get(jobStatusId, {
1569-
useMasterKey: true,
1570-
});
1568+
const jobStatus = await getJobStatus(jobStatusId);
15711569
return jobStatus.get('finishedAt') && jobStatus.get('message') === 'Hello, world!!!';
15721570
};
15731571
while (!(await checkJobStatus())) {
@@ -1610,7 +1608,6 @@ describe('Cloud Code', () => {
16101608
expect(typeof req.jobId).toBe('string');
16111609
expect(typeof req.message).toBe('function');
16121610
expect(typeof res).toBe('undefined');
1613-
done();
16141611
});
16151612
}).not.toThrow();
16161613

@@ -1621,13 +1618,19 @@ describe('Cloud Code', () => {
16211618
'X-Parse-Application-Id': Parse.applicationId,
16221619
'X-Parse-Master-Key': Parse.masterKey,
16231620
},
1624-
}).then(
1625-
() => {},
1626-
err => {
1627-
fail(err);
1628-
done();
1629-
}
1630-
);
1621+
})
1622+
.then(async response => {
1623+
const jobStatusId = response.headers['x-parse-job-status-id'];
1624+
const checkJobStatus = async () => {
1625+
const jobStatus = await getJobStatus(jobStatusId);
1626+
return jobStatus.get('finishedAt');
1627+
};
1628+
while (!(await checkJobStatus())) {
1629+
await new Promise(resolve => setTimeout(resolve, 100));
1630+
}
1631+
})
1632+
.then(done)
1633+
.catch(done.fail);
16311634
});
16321635

16331636
it('should run with master key basic auth', done => {
@@ -1638,25 +1641,30 @@ describe('Cloud Code', () => {
16381641
expect(typeof req.jobId).toBe('string');
16391642
expect(typeof req.message).toBe('function');
16401643
expect(typeof res).toBe('undefined');
1641-
done();
16421644
});
16431645
}).not.toThrow();
16441646

16451647
request({
16461648
method: 'POST',
16471649
url: `http://${Parse.applicationId}:${Parse.masterKey}@localhost:8378/1/jobs/myJob`,
1648-
}).then(
1649-
() => {},
1650-
err => {
1651-
fail(err);
1652-
done();
1653-
}
1654-
);
1650+
})
1651+
.then(async response => {
1652+
const jobStatusId = response.headers['x-parse-job-status-id'];
1653+
const checkJobStatus = async () => {
1654+
const jobStatus = await getJobStatus(jobStatusId);
1655+
return jobStatus.get('finishedAt');
1656+
};
1657+
while (!(await checkJobStatus())) {
1658+
await new Promise(resolve => setTimeout(resolve, 100));
1659+
}
1660+
})
1661+
.then(done)
1662+
.catch(done.fail);
16551663
});
16561664

16571665
it('should set the message / success on the job', done => {
16581666
Parse.Cloud.job('myJob', req => {
1659-
const promise = req
1667+
return req
16601668
.message('hello')
16611669
.then(() => {
16621670
return getJobStatus(req.jobId);
@@ -1665,21 +1673,6 @@ describe('Cloud Code', () => {
16651673
expect(jobStatus.get('message')).toEqual('hello');
16661674
expect(jobStatus.get('status')).toEqual('running');
16671675
});
1668-
promise
1669-
.then(() => {
1670-
return getJobStatus(req.jobId);
1671-
})
1672-
.then(jobStatus => {
1673-
expect(jobStatus.get('message')).toEqual('hello');
1674-
expect(jobStatus.get('status')).toEqual('succeeded');
1675-
done();
1676-
})
1677-
.catch(err => {
1678-
console.error(err);
1679-
jfail(err);
1680-
done();
1681-
});
1682-
return promise;
16831676
});
16841677

16851678
request({
@@ -1689,32 +1682,28 @@ describe('Cloud Code', () => {
16891682
'X-Parse-Application-Id': Parse.applicationId,
16901683
'X-Parse-Master-Key': Parse.masterKey,
16911684
},
1692-
}).then(
1693-
() => {},
1694-
err => {
1695-
fail(err);
1696-
done();
1697-
}
1698-
);
1685+
})
1686+
.then(async response => {
1687+
const jobStatusId = response.headers['x-parse-job-status-id'];
1688+
const checkJobStatus = async () => {
1689+
const jobStatus = await getJobStatus(jobStatusId);
1690+
return (
1691+
jobStatus.get('finishedAt') &&
1692+
jobStatus.get('message') === 'hello' &&
1693+
jobStatus.get('status') === 'succeeded'
1694+
);
1695+
};
1696+
while (!(await checkJobStatus())) {
1697+
await new Promise(resolve => setTimeout(resolve, 100));
1698+
}
1699+
})
1700+
.then(done)
1701+
.catch(done.fail);
16991702
});
17001703

17011704
it('should set the failure on the job', done => {
1702-
Parse.Cloud.job('myJob', req => {
1703-
const promise = Promise.reject('Something went wrong');
1704-
new Promise(resolve => setTimeout(resolve, 200))
1705-
.then(() => {
1706-
return getJobStatus(req.jobId);
1707-
})
1708-
.then(jobStatus => {
1709-
expect(jobStatus.get('message')).toEqual('Something went wrong');
1710-
expect(jobStatus.get('status')).toEqual('failed');
1711-
done();
1712-
})
1713-
.catch(err => {
1714-
jfail(err);
1715-
done();
1716-
});
1717-
return promise;
1705+
Parse.Cloud.job('myJob', () => {
1706+
return Promise.reject('Something went wrong');
17181707
});
17191708

17201709
request({
@@ -1724,13 +1713,23 @@ describe('Cloud Code', () => {
17241713
'X-Parse-Application-Id': Parse.applicationId,
17251714
'X-Parse-Master-Key': Parse.masterKey,
17261715
},
1727-
}).then(
1728-
() => {},
1729-
err => {
1730-
fail(err);
1731-
done();
1732-
}
1733-
);
1716+
})
1717+
.then(async response => {
1718+
const jobStatusId = response.headers['x-parse-job-status-id'];
1719+
const checkJobStatus = async () => {
1720+
const jobStatus = await getJobStatus(jobStatusId);
1721+
return (
1722+
jobStatus.get('finishedAt') &&
1723+
jobStatus.get('message') === 'Something went wrong' &&
1724+
jobStatus.get('status') === 'failed'
1725+
);
1726+
};
1727+
while (!(await checkJobStatus())) {
1728+
await new Promise(resolve => setTimeout(resolve, 100));
1729+
}
1730+
})
1731+
.then(done)
1732+
.catch(done.fail);
17341733
});
17351734

17361735
it('should set the failure message on the job error', async () => {

0 commit comments

Comments
 (0)