56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Audit;
|
|
|
|
use App\Events\HouseholdVerified;
|
|
use App\Models\Household;
|
|
use App\Models\QrCodeBatch;
|
|
use App\Models\User;
|
|
use App\Services\Qr\BatchGenerator;
|
|
use App\States\QrCode\Voided;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
use Tests\TestCase;
|
|
|
|
class ActivityLogTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
}
|
|
|
|
public function test_household_verification_writes_activity_log(): void
|
|
{
|
|
$admin = User::factory()->create(['role' => User::ROLE_ADMIN, 'status' => 'active']);
|
|
$h = Household::factory()->create(['verification_status' => 'pending', 'proof_of_residency_path' => 'p.jpg']);
|
|
|
|
$h->markVerified($admin);
|
|
HouseholdVerified::dispatch($h->fresh(), $admin);
|
|
|
|
$log = Activity::where('log_name', 'household')
|
|
->where('event', 'updated')
|
|
->where('subject_id', $h->id)
|
|
->orderByDesc('id')
|
|
->first();
|
|
$this->assertNotNull($log);
|
|
$this->assertSame(Household::class, $log->subject_type);
|
|
$this->assertEquals('approved', $log->properties['attributes']['verification_status']);
|
|
}
|
|
|
|
public function test_qr_code_void_writes_activity_log(): void
|
|
{
|
|
$batch = app(BatchGenerator::class)->generate(1, QrCodeBatch::PURPOSE_FREE);
|
|
$code = $batch->codes()->first();
|
|
|
|
$code->status->transitionTo(Voided::class);
|
|
|
|
$log = Activity::where('log_name', 'qr_code')->latest()->first();
|
|
$this->assertNotNull($log);
|
|
$this->assertSame('voided', $log->properties['attributes']['status']);
|
|
}
|
|
}
|