Files
alrahma_sunday_school_api/tests/Unit/Services/Security/IpBanCommandServiceTest.php
T
2026-03-11 17:53:15 -04:00

49 lines
1.2 KiB
PHP

<?php
namespace Tests\Unit\Services\Security;
use App\Services\Security\IpBanCommandService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class IpBanCommandServiceTest extends TestCase
{
use RefreshDatabase;
public function test_ban_now_updates_blocked_until(): void
{
DB::table('ip_attempts')->insert([
'ip_address' => '10.0.0.9',
'attempts' => 1,
]);
$service = app(IpBanCommandService::class);
$ban = $service->banNow(null, '10.0.0.9', 2);
$this->assertNotNull($ban);
$this->assertDatabaseHas('ip_attempts', [
'ip_address' => '10.0.0.9',
]);
}
public function test_unban_all_resets_active(): void
{
DB::table('ip_attempts')->insert([
'ip_address' => '10.0.0.10',
'attempts' => 5,
'blocked_until' => now('UTC')->addHours(3),
]);
$service = app(IpBanCommandService::class);
$count = $service->unbanAll();
$this->assertSame(1, $count);
$this->assertDatabaseHas('ip_attempts', [
'ip_address' => '10.0.0.10',
'blocked_until' => null,
'attempts' => 0,
]);
}
}