This commit is contained in:
Saufi
2026-06-03 08:51:22 +08:00
commit a14d43fe34
347 changed files with 38197 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace Tests\Feature;
use App\Models\Election;
use App\Models\Position;
use App\Models\PositionQuota;
use App\Models\PusatMengundi;
use App\Models\StaffAssignment;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CoreDomainSeederTest extends TestCase
{
use RefreshDatabase;
public function test_core_domain_seeders_create_sample_election_hierarchy_and_dual_role_assignment(): void
{
$this->seed(DatabaseSeeder::class);
$this->assertDatabaseCount('positions', 9);
$this->assertDatabaseCount('elections', 1);
$this->assertDatabaseCount('bahagian_pilihanrayas', 1);
$this->assertDatabaseCount('daerah_mengundis', 1);
$this->assertDatabaseCount('pusat_mengundis', 1);
$this->assertDatabaseCount('saluran_mengundis', 3);
$this->assertDatabaseCount('position_quotas', 17);
$this->assertDatabaseCount('staff_assignments', 3);
$election = Election::query()->where('code', 'PRN2026')->firstOrFail();
$pusat = PusatMengundi::query()->where('code', 'PM001')->firstOrFail();
$ppm = User::query()->where('email', 'ppm@prn.local')->firstOrFail();
$this->assertTrue($ppm->hasRole('PPM'));
$this->assertTrue($ppm->hasRole('KTM'));
$this->assertSame($election->id, $pusat->election_id);
$this->assertSame(3, $pusat->saluranMengundis()->count());
$this->assertNotNull($pusat->wheelchairAllocation);
$ppmPosition = Position::query()->where('code', 'PPM')->firstOrFail();
$ktmPosition = Position::query()->where('code', 'KTM')->firstOrFail();
$this->assertTrue(PositionQuota::query()
->where('election_id', $election->id)
->where('pusat_mengundi_id', $pusat->id)
->where('position_id', $ppmPosition->id)
->whereNull('saluran_mengundi_id')
->exists());
$this->assertTrue(StaffAssignment::query()
->where('election_id', $election->id)
->where('user_id', $ppm->id)
->where('position_id', $ppmPosition->id)
->whereNull('saluran_mengundi_id')
->exists());
$this->assertTrue(StaffAssignment::query()
->where('election_id', $election->id)
->where('user_id', $ppm->id)
->where('position_id', $ktmPosition->id)
->whereNotNull('saluran_mengundi_id')
->exists());
}
}