Files
dyncoll-dev/backend/tests/Feature/UserPositionControllerTest.php
2026-06-23 12:29:02 +02:00

45 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Lists\UserPosition;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserPositionControllerTest extends TestCase
{
use RefreshDatabase;
// --- Lettura (pubblica, throttle:public) ----------------------------------
public function test_index_lists_positions_for_an_operational_user(): void
{
$this->actingAs($this->operationalUser(), 'sanctum');
UserPosition::factory()->count(2)->create();
$this->getJson('/api/user-positions')
->assertOk()
->assertJsonStructure(['message', 'data' => [['id', 'value']]]);
}
public function test_show_returns_a_single_position(): void
{
$this->actingAs($this->operationalUser(), 'sanctum');
$position = UserPosition::factory()->create();
$this->getJson("/api/user-positions/{$position->id}")
->assertOk()
->assertJsonPath('data.id', $position->id)
->assertJsonPath('data.value', $position->value);
}
// --- Gating ---------------------------------------------------------------
public function test_guests_can_read_positions(): void
{
UserPosition::factory()->create();
$this->getJson('/api/user-positions')->assertOk();
}
}