89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Activity;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ActivityObserverTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $user;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->user = User::factory()->create();
|
|
$this->actingAs($this->user);
|
|
}
|
|
|
|
private function makeActivity(string $status = 'draft'): Activity
|
|
{
|
|
return Activity::create([
|
|
'title' => 'Test Kegiatan',
|
|
'start_date' => now()->toDateString(),
|
|
'end_date' => now()->addDay()->toDateString(),
|
|
'created_by' => $this->user->id,
|
|
'status' => $status,
|
|
]);
|
|
}
|
|
|
|
public function test_draft_can_transition_to_pending(): void
|
|
{
|
|
$activity = $this->makeActivity('draft');
|
|
$activity->update(['status' => 'pending']);
|
|
|
|
$this->assertSame('pending', $activity->fresh()->status);
|
|
}
|
|
|
|
public function test_draft_cannot_skip_to_approved(): void
|
|
{
|
|
$activity = $this->makeActivity('draft');
|
|
$activity->update(['status' => 'approved']);
|
|
|
|
$this->assertSame('draft', $activity->fresh()->status);
|
|
}
|
|
|
|
public function test_pending_can_transition_to_approved(): void
|
|
{
|
|
$activity = $this->makeActivity('pending');
|
|
$activity->update(['status' => 'approved']);
|
|
|
|
$this->assertSame('approved', $activity->fresh()->status);
|
|
}
|
|
|
|
public function test_pending_can_transition_to_rejected(): void
|
|
{
|
|
$activity = $this->makeActivity('pending');
|
|
$activity->update(['status' => 'rejected']);
|
|
|
|
$this->assertSame('rejected', $activity->fresh()->status);
|
|
}
|
|
|
|
public function test_approved_cannot_revert_to_draft(): void
|
|
{
|
|
$activity = $this->makeActivity('approved');
|
|
$activity->update(['status' => 'draft']);
|
|
|
|
$this->assertSame('approved', $activity->fresh()->status);
|
|
}
|
|
|
|
public function test_large_budget_pending_creates_vote(): void
|
|
{
|
|
$activity = $this->makeActivity('draft');
|
|
$activity->budget = 3_000_000;
|
|
$activity->save();
|
|
|
|
$activity->update(['status' => 'pending']);
|
|
|
|
$this->assertDatabaseHas('votes', [
|
|
'related_type' => Activity::class,
|
|
'related_id' => $activity->id,
|
|
'type' => 'finance',
|
|
]);
|
|
}
|
|
}
|