build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<?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 GameTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_game_show_requires_authentication(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->get(route('games.show', $game->slug))
|
||||
->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_game_show_can_be_rendered(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('games.show', $game->slug))
|
||||
->assertOk();
|
||||
}
|
||||
|
||||
public function test_game_show_returns_404_for_invalid_slug(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('games.show', 'nonexistent'))
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_game_edit_requires_authentication(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->get(route('games.edit', $game->slug))
|
||||
->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_game_edit_can_be_rendered(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('games.edit', $game->slug))
|
||||
->assertOk();
|
||||
}
|
||||
|
||||
public function test_game_update_requires_authentication(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->put(route('games.update', $game->slug), [
|
||||
'title' => 'Updated Title',
|
||||
])->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_game_can_be_updated(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->put(route('games.update', $game->slug), [
|
||||
'title' => 'Updated Title',
|
||||
'description' => 'Updated description',
|
||||
'release_year' => 1990,
|
||||
'developer' => 'Test Developer',
|
||||
'publisher' => 'Test Publisher',
|
||||
'genre' => 'Action',
|
||||
'rating' => 8.5,
|
||||
])
|
||||
->assertRedirect();
|
||||
|
||||
$game->refresh();
|
||||
$this->assertEquals('Updated Title', $game->title);
|
||||
$this->assertEquals('Updated description', $game->description);
|
||||
$this->assertEquals(1990, $game->release_year);
|
||||
$this->assertEquals('Test Developer', $game->developer);
|
||||
$this->assertEquals('Test Publisher', $game->publisher);
|
||||
$this->assertEquals('Action', $game->genre);
|
||||
$this->assertEquals(8.5, $game->rating);
|
||||
}
|
||||
|
||||
public function test_game_update_validates_required_fields(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->put(route('games.update', $game->slug), [
|
||||
'title' => '',
|
||||
])
|
||||
->assertSessionHasErrors('title');
|
||||
}
|
||||
|
||||
public function test_game_delete_requires_authentication(): void
|
||||
{
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->delete(route('games.destroy', $game->slug))
|
||||
->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_game_can_be_deleted(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$console = Console::factory()->create();
|
||||
$game = Game::factory()->create(['console_id' => $console->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('games.destroy', $game->slug))
|
||||
->assertRedirect();
|
||||
|
||||
$this->assertDatabaseMissing('games', ['id' => $game->id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user