first commit
This commit is contained in:
19
tests/Feature/ExampleTest.php
Normal file
19
tests/Feature/ExampleTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_the_application_returns_a_successful_response(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
}
|
||||
60
tests/Feature/SurveyUuidTest.php
Normal file
60
tests/Feature/SurveyUuidTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user