Files
RetroHub/tests/Feature/ConsoleTest.php
T

77 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Features\Consoles\Models\Console;
use App\Features\Games\Models\Game;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ConsoleTest extends TestCase
{
use RefreshDatabase;
public function test_consoles_index_requires_authentication(): void
{
$this->get(route('consoles.index'))->assertRedirect(route('login'));
}
public function test_consoles_index_can_be_rendered(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('consoles.index'))
->assertOk();
}
public function test_consoles_index_shows_consoles(): void
{
$user = User::factory()->create();
Console::factory()->count(3)->create();
$this->actingAs($user)
->get(route('consoles.index'))
->assertOk();
}
public function test_console_show_requires_authentication(): void
{
$console = Console::factory()->create();
$this->get(route('consoles.show', $console->slug))
->assertRedirect(route('login'));
}
public function test_console_show_can_be_rendered(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
$this->actingAs($user)
->get(route('consoles.show', $console->slug))
->assertOk();
}
public function test_console_show_with_games(): void
{
$user = User::factory()->create();
$console = Console::factory()->create();
Game::factory()->count(5)->create(['console_id' => $console->id]);
$this->actingAs($user)
->get(route('consoles.show', $console->slug))
->assertOk();
}
public function test_console_show_returns_404_for_invalid_slug(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get(route('consoles.show', 'nonexistent'))
->assertNotFound();
}
}