create(['status' => BookingStatus::PendingPayment]); $booking->update(['status' => BookingStatus::Confirmed]); $activity = Activity::where('subject_type', Booking::class) ->where('subject_id', $booking->id) ->where('log_name', 'booking') ->latest('id') ->first(); expect($activity)->not->toBeNull(); expect($activity->attribute_changes->get('attributes'))->toMatchArray(['status' => BookingStatus::Confirmed->value]); }); test('a catalog CRUD write is recorded in the audit log', function () { $company = EvCompany::factory()->create(['name' => 'Original Name']); $company->update(['name' => 'Renamed Company']); $activity = Activity::where('subject_type', EvCompany::class) ->where('subject_id', $company->id) ->where('log_name', 'catalog') ->latest('id') ->first(); expect($activity)->not->toBeNull(); expect($activity->attribute_changes->get('attributes')['name'])->toBe('Renamed Company'); }); test('a user without view_audit_log cannot list the audit log via Filament', function () { Permission::findOrCreate('view_audit_log', 'web'); $role = Role::findOrCreate('support', 'web'); $user = User::factory()->create(); $user->assignRole($role); $this->actingAs($user) ->get('/admin/audit-logs') ->assertForbidden(); }); test('a user with view_audit_log can list the audit log via Filament', function () { Permission::findOrCreate('view_audit_log', 'web'); $role = Role::findOrCreate('support', 'web'); $role->givePermissionTo('view_audit_log'); $user = User::factory()->create(); $user->assignRole($role); $this->actingAs($user) ->get('/admin/audit-logs') ->assertSuccessful(); });