Skip to content

Commit 343b1f0

Browse files
Cursor Bot Fix: Fix ineffective system categories/templates test
1 parent 4148e83 commit 343b1f0

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

ProcessMaker/Jobs/EvaluateProcessRetentionJob.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ public function handle(): void
5151
return;
5252
}
5353

54+
// Skip template processes
55+
if ($process->is_template) {
56+
Log::info('EvaluateProcessRetentionJob: Skipping template process', [
57+
'process_id' => $this->processId,
58+
]);
59+
60+
return;
61+
}
62+
63+
// Skip processes in system categories
64+
if ($process->categories()->where('is_system', true)->exists()) {
65+
Log::info('EvaluateProcessRetentionJob: Skipping process in system category', [
66+
'process_id' => $this->processId,
67+
]);
68+
69+
return;
70+
}
71+
5472
// Default to 1_year if retention_period is not set
5573
$retentionPeriod = $process->properties['retention_period'] ?? '1_year';
5674
$retentionMonths = match ($retentionPeriod) {

tests/Jobs/EvaluateProcessRetentionJobTest.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)