fix(models): correct UserSetting import namespace and add test coverage
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Models\Game;
|
||||
use App\Features\Games\Models\RomFile;
|
||||
use App\Features\Settings\Models\SaveFile;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GameTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
#[Test]
|
||||
public function it_belongs_to_a_console(): void
|
||||
{
|
||||
$game = Game::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(Console::class, $game->console);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_has_many_rom_files(): void
|
||||
{
|
||||
$game = Game::factory()->create();
|
||||
RomFile::factory()->count(3)->create(['game_id' => $game->id]);
|
||||
|
||||
$this->assertCount(3, $game->romFiles);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_has_many_save_files(): void
|
||||
{
|
||||
$game = Game::factory()->create();
|
||||
SaveFile::factory()->count(2)->create(['game_id' => $game->id]);
|
||||
|
||||
$this->assertCount(2, $game->saveFiles);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_uses_slug_as_route_key(): void
|
||||
{
|
||||
$game = new Game();
|
||||
|
||||
$this->assertEquals('slug', $game->getRouteKeyName());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_auto_generates_slug_from_title_on_creating(): void
|
||||
{
|
||||
$game = Game::factory()->create([
|
||||
'title' => 'Super Mario Bros',
|
||||
'slug' => null,
|
||||
]);
|
||||
|
||||
$this->assertEquals('super-mario-bros', $game->slug);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_keeps_existing_slug(): void
|
||||
{
|
||||
$game = Game::factory()->create([
|
||||
'title' => 'Super Mario Bros',
|
||||
'slug' => 'custom-slug',
|
||||
]);
|
||||
|
||||
$this->assertEquals('custom-slug', $game->slug);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_casts_rating_to_decimal(): void
|
||||
{
|
||||
$game = Game::factory()->create(['rating' => 8.5]);
|
||||
|
||||
$this->assertEquals('8.5', (string) $game->rating);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_has_fillable_attributes(): void
|
||||
{
|
||||
$game = new Game();
|
||||
|
||||
$this->assertEquals([
|
||||
'console_id',
|
||||
'title',
|
||||
'slug',
|
||||
'igdb_id',
|
||||
'tgdb_id',
|
||||
'description',
|
||||
'release_year',
|
||||
'developer',
|
||||
'publisher',
|
||||
'genre',
|
||||
'rating',
|
||||
'cover_path',
|
||||
'thumbnail_path',
|
||||
], $game->getFillable());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user