Files
myPostMortem/tests/Feature/SurveyUuidTest.php

61 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\User;
use App\Models\Survey;
use Illuminate\Support\Str;
class SurveyUuidTest extends TestCase
{
use RefreshDatabase;
// Actually, local test setup might use sqlite in memory. Let's assume standard Laravel test setup.
// Given the user is running `php artisan test` successfully, safe to use.
public function test_survey_generates_uuid_on_creation(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'Test Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
$this->assertNotEmpty($survey->uuid);
$this->assertTrue(Str::isUuid($survey->uuid));
}
public function test_public_can_access_survey_via_uuid(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'UUID Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
$response = $this->get(route('surveys.show', $survey)); // Should use UUID
$response->assertStatus(200);
$response->assertSee('UUID Survey');
}
public function test_public_cannot_access_survey_via_id(): void
{
$user = User::factory()->create();
$survey = Survey::create([
'title' => 'ID Survey',
'date' => '2025-01-01',
'user_id' => $user->id,
]);
// Construct URL manually with ID
$response = $this->get('/survey/' . $survey->id);
$response->assertStatus(404);
}
}