84 lines
3.0 KiB
PHP
84 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Admin;
|
|
|
|
use App\Models\DaerahMengundi;
|
|
use App\Models\Election;
|
|
use App\Models\Position;
|
|
use App\Models\PositionQuota;
|
|
use App\Models\PusatMengundi;
|
|
use App\Models\SaluranMengundi;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class PusatOperationalSetupTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_create_pusat_with_numbered_saluran_and_operational_quotas(): void
|
|
{
|
|
$this->seed();
|
|
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('Admin');
|
|
$election = Election::query()->firstOrFail();
|
|
$daerah = DaerahMengundi::query()->where('election_id', $election->id)->firstOrFail();
|
|
|
|
$response = $this
|
|
->actingAs($admin)
|
|
->post(route('admin.setup.pusat.store'), [
|
|
'election_id' => $election->id,
|
|
'daerah_mengundi_id' => $daerah->id,
|
|
'code' => 'PMAUTO',
|
|
'name' => 'Pusat Mengundi Automatik',
|
|
'address' => 'Alamat ujian',
|
|
'saluran_count' => 2,
|
|
'ktm_count' => 1,
|
|
'polis_iring_count' => 1,
|
|
'kp_count' => 4,
|
|
'ppm_count' => 1,
|
|
'kpdp_count' => 1,
|
|
'papm_count' => 3,
|
|
'jkm_count' => 1,
|
|
'kkm_count' => 1,
|
|
'calon_tambahan_count' => 2,
|
|
]);
|
|
|
|
$response->assertRedirect(route('admin.setup.pusat.index'));
|
|
|
|
$pusat = PusatMengundi::query()->where('code', 'PMAUTO')->firstOrFail();
|
|
$salurans = SaluranMengundi::query()->where('pusat_mengundi_id', $pusat->id)->get();
|
|
$this->assertCount(2, $salurans);
|
|
|
|
$salurans->each(function (SaluranMengundi $saluran): void {
|
|
$this->assertNull($saluran->name);
|
|
|
|
$this->assertQuota($saluran->pusat_mengundi_id, $saluran->id, 'KTM', 1);
|
|
$this->assertQuota($saluran->pusat_mengundi_id, $saluran->id, 'POLIS', 1);
|
|
$this->assertQuota($saluran->pusat_mengundi_id, $saluran->id, 'KP', 4);
|
|
$this->assertQuota($saluran->pusat_mengundi_id, $saluran->id, 'KPDP', 1);
|
|
$this->assertQuota($saluran->pusat_mengundi_id, $saluran->id, 'CALON_TAMBAHAN', 2);
|
|
});
|
|
|
|
$this->assertQuota($pusat->id, null, 'PPM', 1);
|
|
$this->assertQuota($pusat->id, null, 'PAPM', 3);
|
|
$this->assertQuota($pusat->id, null, 'JKM', 1);
|
|
$this->assertQuota($pusat->id, null, 'KKM', 1);
|
|
}
|
|
|
|
private function assertQuota(int $pusatId, ?int $saluranId, string $positionCode, int $quota): void
|
|
{
|
|
$positionId = Position::query()->where('code', $positionCode)->value('id');
|
|
|
|
$this->assertSame(
|
|
$quota,
|
|
PositionQuota::query()
|
|
->where('pusat_mengundi_id', $pusatId)
|
|
->where('saluran_mengundi_id', $saluranId)
|
|
->where('position_id', $positionId)
|
|
->value('quota'),
|
|
);
|
|
}
|
|
}
|