first
This commit is contained in:
66
tests/Feature/CoreDomainSeederTest.php
Normal file
66
tests/Feature/CoreDomainSeederTest.php
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user