@@ -1565,9 +1565,7 @@ describe('Cloud Code', () => {
1565
1565
. then ( async response => {
1566
1566
const jobStatusId = response . headers [ 'x-parse-job-status-id' ] ;
1567
1567
const checkJobStatus = async ( ) => {
1568
- const jobStatus = await new Parse . Query ( '_JobStatus' ) . get ( jobStatusId , {
1569
- useMasterKey : true ,
1570
- } ) ;
1568
+ const jobStatus = await getJobStatus ( jobStatusId ) ;
1571
1569
return jobStatus . get ( 'finishedAt' ) && jobStatus . get ( 'message' ) === 'Hello, world!!!' ;
1572
1570
} ;
1573
1571
while ( ! ( await checkJobStatus ( ) ) ) {
@@ -1610,7 +1608,6 @@ describe('Cloud Code', () => {
1610
1608
expect ( typeof req . jobId ) . toBe ( 'string' ) ;
1611
1609
expect ( typeof req . message ) . toBe ( 'function' ) ;
1612
1610
expect ( typeof res ) . toBe ( 'undefined' ) ;
1613
- done ( ) ;
1614
1611
} ) ;
1615
1612
} ) . not . toThrow ( ) ;
1616
1613
@@ -1621,13 +1618,19 @@ describe('Cloud Code', () => {
1621
1618
'X-Parse-Application-Id' : Parse . applicationId ,
1622
1619
'X-Parse-Master-Key' : Parse . masterKey ,
1623
1620
} ,
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 ) ;
1631
1634
} ) ;
1632
1635
1633
1636
it ( 'should run with master key basic auth' , done => {
@@ -1638,25 +1641,30 @@ describe('Cloud Code', () => {
1638
1641
expect ( typeof req . jobId ) . toBe ( 'string' ) ;
1639
1642
expect ( typeof req . message ) . toBe ( 'function' ) ;
1640
1643
expect ( typeof res ) . toBe ( 'undefined' ) ;
1641
- done ( ) ;
1642
1644
} ) ;
1643
1645
} ) . not . toThrow ( ) ;
1644
1646
1645
1647
request ( {
1646
1648
method : 'POST' ,
1647
1649
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 ) ;
1655
1663
} ) ;
1656
1664
1657
1665
it ( 'should set the message / success on the job' , done => {
1658
1666
Parse . Cloud . job ( 'myJob' , req => {
1659
- const promise = req
1667
+ return req
1660
1668
. message ( 'hello' )
1661
1669
. then ( ( ) => {
1662
1670
return getJobStatus ( req . jobId ) ;
@@ -1665,21 +1673,6 @@ describe('Cloud Code', () => {
1665
1673
expect ( jobStatus . get ( 'message' ) ) . toEqual ( 'hello' ) ;
1666
1674
expect ( jobStatus . get ( 'status' ) ) . toEqual ( 'running' ) ;
1667
1675
} ) ;
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 ;
1683
1676
} ) ;
1684
1677
1685
1678
request ( {
@@ -1689,32 +1682,28 @@ describe('Cloud Code', () => {
1689
1682
'X-Parse-Application-Id' : Parse . applicationId ,
1690
1683
'X-Parse-Master-Key' : Parse . masterKey ,
1691
1684
} ,
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 ) ;
1699
1702
} ) ;
1700
1703
1701
1704
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' ) ;
1718
1707
} ) ;
1719
1708
1720
1709
request ( {
@@ -1724,13 +1713,23 @@ describe('Cloud Code', () => {
1724
1713
'X-Parse-Application-Id' : Parse . applicationId ,
1725
1714
'X-Parse-Master-Key' : Parse . masterKey ,
1726
1715
} ,
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 ) ;
1734
1733
} ) ;
1735
1734
1736
1735
it ( 'should set the failure message on the job error' , async ( ) => {
0 commit comments