@@ -335,21 +335,34 @@ public function testItDoesNotRunForTemplates()
335335 // Create a template process
336336 $ process = Process::factory ()->create ([
337337 'is_template ' => 1 ,
338+ 'properties ' => [
339+ 'retention_period ' => self ::RETENTION_PERIOD ,
340+ ],
338341 ]);
339342 $ process ->save ();
340343 $ process ->refresh ();
341344
342- // Dispatch the job
343- EvaluateProcessRetentionJob::dispatchSync ($ process ->id );
344-
345- // The case should NOT be deleted because the process is a template
346- $ this ->assertDatabaseCount ('case_numbers ' , 0 );
347-
348345 // Create a process request
349346 $ processRequest = ProcessRequest::factory ()->create ();
350347 $ processRequest ->process_id = $ process ->id ;
351348 $ processRequest ->save ();
352349 $ processRequest ->refresh ();
350+
351+ // Create an old case that should be deleted if this wasn't a template
352+ // 13 months ago is older than 1 year retention period
353+ $ oldCaseDate = Carbon::now ()->subMonths (13 );
354+ $ oldCase = CaseNumber::factory ()->create ([
355+ 'process_request_id ' => $ processRequest ->id ,
356+ ]);
357+ $ oldCase ->created_at = $ oldCaseDate ;
358+ $ oldCase ->save ();
359+
360+ // Dispatch the job
361+ EvaluateProcessRetentionJob::dispatchSync ($ process ->id );
362+
363+ // The case should NOT be deleted because the process is a template
364+ $ this ->assertNotNull (CaseNumber::find ($ oldCase ->id ), 'The case should NOT be deleted because the process is a template ' );
365+ $ this ->assertDatabaseCount ('case_numbers ' , 2 );
353366 }
354367
355368 public function testItDoesNotRunForProcessesInSystemCategories ()
@@ -360,14 +373,33 @@ public function testItDoesNotRunForProcessesInSystemCategories()
360373 // Create a process in a system category
361374 $ process = Process::factory ()->create ([
362375 'process_category_id ' => $ category ->id ,
376+ 'properties ' => [
377+ 'retention_period ' => self ::RETENTION_PERIOD ,
378+ ],
363379 ]);
364380 $ process ->save ();
365381 $ process ->refresh ();
366382
383+ // Create a process request
384+ $ processRequest = ProcessRequest::factory ()->create ();
385+ $ processRequest ->process_id = $ process ->id ;
386+ $ processRequest ->save ();
387+ $ processRequest ->refresh ();
388+
389+ // Create an old case that should be deleted if this wasn't in a system category
390+ // 13 months ago is older than 1 year retention period
391+ $ oldCaseDate = Carbon::now ()->subMonths (13 );
392+ $ oldCase = CaseNumber::factory ()->create ([
393+ 'process_request_id ' => $ processRequest ->id ,
394+ ]);
395+ $ oldCase ->created_at = $ oldCaseDate ;
396+ $ oldCase ->save ();
397+
367398 // Dispatch the job
368399 EvaluateProcessRetentionJob::dispatchSync ($ process ->id );
369400
370401 // The case should NOT be deleted because the process is in a system category
371- $ this ->assertDatabaseCount ('case_numbers ' , 0 );
402+ $ this ->assertNotNull (CaseNumber::find ($ oldCase ->id ), 'The case should NOT be deleted because the process is in a system category ' );
403+ $ this ->assertDatabaseCount ('case_numbers ' , 2 );
372404 }
373405}
0 commit comments