@@ -3,7 +3,7 @@ import { getBuildJobDef, getBuildJobPlain } from '../../data/jobDef';
33import { DBRepositoryHelper } from '../../utils/repositoryHelper' ;
44import { TestDataProvider } from '../../data/data' ;
55import { ObjectId } from 'mongodb' ;
6- import { Job } from '../../../src/entities/job' ;
6+ import { Job , JobStatus } from '../../../src/entities/job' ;
77
88describe ( 'Job Repository Tests' , ( ) => {
99 let job : Job ;
@@ -19,15 +19,17 @@ describe('Job Repository Tests', () => {
1919 expect ( new JobRepository ( dbRepoHelper . db , dbRepoHelper . config , dbRepoHelper . logger ) ) . toBeDefined ( ) ;
2020 } ) ;
2121
22- describe ( 'Job Repository updateWithCompletionStatus Tests' , ( ) => {
22+ describe ( 'Job Repository updateWithStatus Tests' , ( ) => {
2323 test ( 'Update with completion status throws DB Error as result is undefined' , async ( ) => {
2424 const testData = TestDataProvider . getStatusUpdateQueryAndUpdateObject (
2525 '64ad959b423952aeb9341fad' ,
2626 'completed' ,
2727 'All good' ,
2828 new Date ( )
2929 ) ;
30- await expect ( jobRepo . updateWithCompletionStatus ( '64ad959b423952aeb9341fad' , 'All good' ) ) . rejects . toThrow (
30+ await expect (
31+ jobRepo . updateWithStatus ( '64ad959b423952aeb9341fad' , 'All good' , JobStatus . completed )
32+ ) . rejects . toThrow (
3133 `Failed to update job (${ JSON . stringify ( testData . query ) } ) for ${ JSON . stringify ( testData . update ) } `
3234 ) ;
3335 } ) ;
@@ -40,15 +42,19 @@ describe('Job Repository Tests', () => {
4042 new Date ( )
4143 ) ;
4244 dbRepoHelper . collection . findOneAndUpdate . mockReturnValue ( undefined ) ;
43- await expect ( jobRepo . updateWithCompletionStatus ( '64ad959b423952aeb9341fad' , 'All good' ) ) . rejects . toThrow (
45+ await expect (
46+ jobRepo . updateWithStatus ( '64ad959b423952aeb9341fad' , 'All good' , JobStatus . completed )
47+ ) . rejects . toThrow (
4448 `Failed to update job (${ JSON . stringify ( testData . query ) } ) for ${ JSON . stringify ( testData . update ) } `
4549 ) ;
4650 expect ( dbRepoHelper . collection . findOneAndUpdate ) . toBeCalledTimes ( 1 ) ;
4751 } ) ;
4852
4953 test ( 'Update with completion status succeeds' , async ( ) => {
5054 setupForFindOneAndUpdateSuccess ( ) ;
51- await expect ( jobRepo . updateWithCompletionStatus ( '64ad959b423952aeb9341fad' , 'All good' ) ) . resolves . toEqual ( job ) ;
55+ await expect (
56+ jobRepo . updateWithStatus ( '64ad959b423952aeb9341fad' , 'All good' , JobStatus . completed )
57+ ) . resolves . toEqual ( job ) ;
5258 expect ( dbRepoHelper . collection . findOneAndUpdate ) . toBeCalledTimes ( 1 ) ;
5359 expect ( dbRepoHelper . logger . error ) . toBeCalledTimes ( 0 ) ;
5460 } ) ;
@@ -61,10 +67,10 @@ describe('Job Repository Tests', () => {
6167 } ) ;
6268 } ) ;
6369 try {
64- jobRepo . updateWithCompletionStatus ( '64ad959b423952aeb9341fad' , 'All good' ) . catch ( ( error ) => {
70+ jobRepo . updateWithStatus ( '64ad959b423952aeb9341fad' , 'All good' , JobStatus . completed ) . catch ( ( error ) => {
6571 expect ( dbRepoHelper . logger . error ) . toBeCalledTimes ( 1 ) ;
6672 expect ( error . message ) . toContain (
67- `Mongo Timeout Error: Timed out while updating success status for jobId: 64ad959b423952aeb9341fad`
73+ `Mongo Timeout Error: Timed out while updating job status to " ${ JobStatus . completed } " for jobId: 64ad959b423952aeb9341fad`
6874 ) ;
6975 } ) ;
7076 jest . runAllTimers ( ) ;
0 commit comments