@@ -206,17 +206,51 @@ describe('Test Pulse', () => {
206206 } ) ;
207207
208208 describe ( 'Test resumeOnRestart' , ( ) => {
209- test ( 'sets the default resumeOnRestart' , ( ) => {
209+ test ( 'should enable resumeOnRestart by default ' , ( ) => {
210210 expect ( globalPulseInstance . _resumeOnRestart ) . toBeTruthy ( ) ;
211211 } ) ;
212212
213- test ( 'sets the custom resumeOnRestart' , ( ) => {
213+ test ( 'should disable resumeOnRestart when set to false ' , ( ) => {
214214 globalPulseInstance . resumeOnRestart ( false ) ;
215215 expect ( globalPulseInstance . _resumeOnRestart ) . toBeFalsy ( ) ;
216216 } ) ;
217217
218- test ( 'returns itself' , ( ) => {
219- expect ( globalPulseInstance . resumeOnRestart ( false ) ) . toEqual ( globalPulseInstance ) ;
218+ test ( 'should resume non-recurring jobs on restart' , async ( ) => {
219+ const job = globalPulseInstance . create ( 'sendEmail' , { to : 'user@example.com' } ) ;
220+ job . attrs . nextRunAt = new Date ( Date . now ( ) - 1000 ) ; // Set nextRunAt in the past
221+ await job . save ( ) ;
222+
223+ await globalPulseInstance . resumeOnRestart ( ) ;
224+
225+ const updatedJob = ( await globalPulseInstance . jobs ( { name : 'sendEmail' } ) ) [ 0 ] ;
226+ const now = Date . now ( ) ;
227+ expect ( updatedJob . attrs . nextRunAt ?. getTime ( ) ) . toBeGreaterThan ( now - 100 ) ; // Allow a 100ms buffer
228+ } ) ;
229+
230+ test ( 'should resume recurring jobs on restart' , async ( ) => {
231+ const job = globalPulseInstance . create ( 'sendEmail' , { to : 'user@example.com' } ) ;
232+ job . attrs . repeatInterval = '5 minutes' ;
233+ job . attrs . nextRunAt = null ;
234+ await job . save ( ) ;
235+
236+ await globalPulseInstance . resumeOnRestart ( ) ;
237+
238+ const updatedJob = ( await globalPulseInstance . jobs ( { name : 'sendEmail' } ) ) [ 0 ] ;
239+ const now = Date . now ( ) ;
240+ expect ( updatedJob . attrs . nextRunAt ) . not . toBeNull ( ) ;
241+ expect ( updatedJob . attrs . nextRunAt ?. getTime ( ) ) . toBeGreaterThan ( now - 100 ) ; // Allow a 100ms buffer
242+ } ) ;
243+
244+ test ( 'should not modify jobs with existing nextRunAt' , async ( ) => {
245+ const futureDate = new Date ( Date . now ( ) + 60 * 60 * 1000 ) ;
246+ const job = globalPulseInstance . create ( 'sendEmail' , { to : 'user@example.com' } ) ;
247+ job . attrs . nextRunAt = futureDate ;
248+ await job . save ( ) ;
249+
250+ await globalPulseInstance . resumeOnRestart ( ) ;
251+
252+ const updatedJob = ( await globalPulseInstance . jobs ( { name : 'sendEmail' } ) ) [ 0 ] ;
253+ expect ( updatedJob . attrs . nextRunAt ?. getTime ( ) ) . toEqual ( futureDate . getTime ( ) ) ;
220254 } ) ;
221255 } ) ;
222256 } ) ;
0 commit comments