Implement deleted log

This commit is contained in:
Marcus Moore 2024-10-30 14:05:27 -07:00
parent 59e6874a4a
commit 0cc3031864
No known key found for this signature in database
2 changed files with 34 additions and 1 deletions

View file

@ -72,6 +72,16 @@ class ReportTemplate extends Model
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
});
static::deleted(function (ReportTemplate $reportTemplate) {
$logAction = new Actionlog([
'item_type' => ReportTemplate::class,
'item_id' => $reportTemplate->id,
'created_by' => auth()->id(),
]);
$logAction->logaction('delete');
});
}
/**

View file

@ -144,7 +144,30 @@ class ReportTemplateActivityLoggingTest extends TestCase
public function testDeletingReportTemplateIsLogged()
{
$this->markTestIncomplete();
$user = User::factory()->create();
[$reportTemplateA, $reportTemplateB] = ReportTemplate::factory()->count(2)->create();
$reportTemplateA->delete();
$this->actingAs($user);
$reportTemplateB->delete();
$this->assertDatabaseHas('action_logs', [
'created_by' => null,
'action_type' => 'delete',
'target_id' => null,
'target_type' => null,
'item_type' => ReportTemplate::class,
'item_id' => $reportTemplateA->id,
]);
$this->assertDatabaseHas('action_logs', [
'created_by' => $user->id,
'action_type' => 'delete',
'target_id' => null,
'target_type' => null,
'item_type' => ReportTemplate::class,
'item_id' => $reportTemplateB->id,
]);
}
public function testLogEntryForDeletingReportTemplateCanBeDisplayedCorrectly()