Chronologisches Protokoll der Systemereignisse als neue Admin-Seite (/admin/reports/activity) mit Filter nach Ereignistyp, Zeitraum und Suche. Erfasst ab jetzt fortlaufend: - Registrierungen inkl. Weg (Formular, Google, Magic-Link) - Anmeldungen inkl. Weg (Passwort, Google, Magic-Link, Impersonation) - PM-Statuswechsel mit Ergebnis/Begründung (zentral im Status-Log-Hook; KI-/Scheduler-Wechsel erscheinen als „System") - Zahlungseingänge (Rechnungsspiegelung) und Credit-Aufladungen - Formular-Eingänge: Kontakt, Rechtsanfrage, Widerruf, Kündigung, Newsletter-Anmeldung (Observer auf den Modellen) Schreiben ist Best-Effort über den ActivityLog-Service — ein fehlgeschlagener Verlaufseintrag bricht nie den fachlichen Ablauf. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
113 lines
4 KiB
PHP
113 lines
4 KiB
PHP
<?php
|
|
|
|
use App\Enums\ActivityType;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Listeners\RecordAuthActivity;
|
|
use App\Models\ActivityEvent;
|
|
use App\Models\ContactMessage;
|
|
use App\Models\PressRelease;
|
|
use App\Models\User;
|
|
use App\Models\WithdrawalRequest;
|
|
use App\Services\PressRelease\PressReleaseService;
|
|
use Database\Seeders\RolesAndPermissionsSeeder;
|
|
use Illuminate\Auth\Events\Login;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Livewire\Volt\Volt;
|
|
use Tests\TestCase;
|
|
|
|
test('a self registration is recorded in the activity log', function () {
|
|
/** @var TestCase $this */
|
|
Notification::fake();
|
|
|
|
Volt::test('auth.register')
|
|
->set('name', 'Verlauf Tester')
|
|
->set('email', 'verlauf@example.com')
|
|
->set('password', 'password')
|
|
->set('password_confirmation', 'password')
|
|
->set('terms_accepted', true)
|
|
->call('register');
|
|
|
|
$event = ActivityEvent::query()->where('type', ActivityType::UserRegistered->value)->sole();
|
|
|
|
expect($event->meta['way'])->toBe('form')
|
|
->and($event->description)->toContain('verlauf@example.com')
|
|
->and($event->user_id)->not->toBeNull();
|
|
});
|
|
|
|
test('a login is recorded with its method', function () {
|
|
$user = User::factory()->create(['is_active' => true]);
|
|
|
|
request()->attributes->set(RecordAuthActivity::AUTH_METHOD_ATTRIBUTE, 'magic-link');
|
|
event(new Login('web', $user, false));
|
|
|
|
$event = ActivityEvent::query()->where('type', ActivityType::UserLoggedIn->value)->sole();
|
|
|
|
expect($event->meta['method'])->toBe('magic-link')
|
|
->and($event->description)->toContain('Magic-Link')
|
|
->and($event->user_id)->toBe($user->id);
|
|
});
|
|
|
|
test('a press release status change is recorded', function () {
|
|
Queue::fake();
|
|
|
|
$pressRelease = PressRelease::factory()->create(['status' => PressReleaseStatus::Draft]);
|
|
|
|
app(PressReleaseService::class)->submitForReview($pressRelease);
|
|
|
|
$event = ActivityEvent::query()->where('type', ActivityType::PressReleaseStatus->value)->first();
|
|
|
|
expect($event)->not->toBeNull()
|
|
->and($event->description)->toContain($pressRelease->title)
|
|
->and($event->subject_id)->toBe($pressRelease->id)
|
|
->and($event->actor_label)->toBe('System');
|
|
});
|
|
|
|
test('form submissions are recorded via the observer', function () {
|
|
ContactMessage::factory()->create([
|
|
'name' => 'Max Beispiel',
|
|
'email' => 'max@example.com',
|
|
]);
|
|
WithdrawalRequest::factory()->create([
|
|
'name' => 'Erika Beispiel',
|
|
'email' => 'erika@example.com',
|
|
]);
|
|
|
|
expect(ActivityEvent::query()->where('type', ActivityType::ContactRequest->value)->sole()->description)
|
|
->toContain('max@example.com');
|
|
expect(ActivityEvent::query()->where('type', ActivityType::WithdrawalRequest->value)->sole()->description)
|
|
->toContain('erika@example.com');
|
|
});
|
|
|
|
test('the activity report page lists events and filters by type', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(RolesAndPermissionsSeeder::class);
|
|
|
|
$admin = User::factory()->create(['is_active' => true]);
|
|
$admin->assignRole('admin');
|
|
|
|
ActivityEvent::query()->create([
|
|
'type' => ActivityType::ContactRequest->value,
|
|
'occurred_at' => now(),
|
|
'actor_label' => 'Gast',
|
|
'description' => 'Kontaktanfrage „Testthema“ von Gast (gast@example.com).',
|
|
]);
|
|
ActivityEvent::query()->create([
|
|
'type' => ActivityType::UserLoggedIn->value,
|
|
'occurred_at' => now(),
|
|
'user_id' => $admin->id,
|
|
'actor_label' => $admin->name,
|
|
'description' => 'Admin hat sich angemeldet — Passwort.',
|
|
]);
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$this->get(route('admin.reports.activity'))->assertOk();
|
|
|
|
Volt::test('admin.reports.activity')
|
|
->assertSee('Kontaktanfrage „Testthema“')
|
|
->assertSee('hat sich angemeldet')
|
|
->set('typeFilter', ActivityType::ContactRequest->value)
|
|
->assertSee('Kontaktanfrage „Testthema“')
|
|
->assertDontSee('hat sich angemeldet');
|
|
});
|