58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\Election;
|
|
use App\Services\RegistrationPeriodService;
|
|
use Database\Seeders\DatabaseSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class RegistrationPeriodServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_registration_period_uses_dates_and_open_flag(): void
|
|
{
|
|
$this->seed(DatabaseSeeder::class);
|
|
|
|
$service = new RegistrationPeriodService;
|
|
$election = Election::query()->where('code', 'PRN2026')->firstOrFail();
|
|
|
|
$this->assertTrue($service->isOpen($election));
|
|
|
|
$election->settings()->update([
|
|
'is_registration_open' => false,
|
|
'is_registration_open_override' => null,
|
|
]);
|
|
$election->refresh()->load('settings');
|
|
|
|
$this->assertFalse($service->isOpen($election));
|
|
}
|
|
|
|
public function test_registration_override_can_explicitly_open_or_close(): void
|
|
{
|
|
$this->seed(DatabaseSeeder::class);
|
|
|
|
$service = new RegistrationPeriodService;
|
|
$election = Election::query()->where('code', 'PRN2026')->firstOrFail();
|
|
|
|
$election->settings()->update([
|
|
'registration_start_date' => now()->subWeeks(4)->toDateString(),
|
|
'registration_end_date' => now()->subDay()->toDateString(),
|
|
'is_registration_open' => true,
|
|
'is_registration_open_override' => true,
|
|
]);
|
|
$election->refresh()->load('settings');
|
|
|
|
$this->assertTrue($service->isOpen($election));
|
|
|
|
$election->settings()->update([
|
|
'is_registration_open_override' => false,
|
|
]);
|
|
$election->refresh()->load('settings');
|
|
|
|
$this->assertFalse($service->isOpen($election));
|
|
}
|
|
}
|