diff --git a/app/Http/Controllers/ModController.php b/app/Http/Controllers/ModController.php index 5ca42a4..2091d97 100644 --- a/app/Http/Controllers/ModController.php +++ b/app/Http/Controllers/ModController.php @@ -45,7 +45,7 @@ class ModController extends Controller $this->authorize('view', $mod); - $latestVersion = $mod->versions->sortByDesc('created_at')->first(); + $latestVersion = $mod->versions->sortByDesc('version')->first(); return view('mod.show', compact(['mod', 'latestVersion'])); } diff --git a/app/Http/Resources/Api/V0/ModResource.php b/app/Http/Resources/Api/V0/ModResource.php index d02762d..23ed9cc 100644 --- a/app/Http/Resources/Api/V0/ModResource.php +++ b/app/Http/Resources/Api/V0/ModResource.php @@ -80,10 +80,7 @@ class ModResource extends JsonResource ->values() ), 'links' => [ - 'self' => route('mod.show', [ - 'mod' => $this->id, - 'slug' => $this->slug, - ]), + 'self' => $this->detailUrl(), ], ]; } diff --git a/app/Models/Mod.php b/app/Models/Mod.php index 193cc17..2388390 100644 --- a/app/Models/Mod.php +++ b/app/Models/Mod.php @@ -154,6 +154,14 @@ class Mod extends Model return $filters->apply($builder); } + /** + * Build the URL to the mod's detail page. + */ + public function detailUrl(): string + { + return route('mod.show', [$this->id, $this->slug]); + } + /** * The attributes that should be cast to native types. */ diff --git a/resources/views/mod/show.blade.php b/resources/views/mod/show.blade.php index ef5ab29..dc39d60 100644 --- a/resources/views/mod/show.blade.php +++ b/resources/views/mod/show.blade.php @@ -114,7 +114,7 @@ {{ __('Dependencies:') }} @foreach ($version->dependencies as $dependency) @if ($dependency->resolvedVersion?->mod) - + {{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }}) @if (!$loop->last), @endif @endif @@ -184,7 +184,7 @@

{{ __('Latest Version Dependencies') }}

@foreach ($latestVersion->dependencies as $dependency) - + {{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }})
@endforeach diff --git a/tests/Feature/ModTest.php b/tests/Feature/ModTest.php new file mode 100644 index 0000000..a76dff6 --- /dev/null +++ b/tests/Feature/ModTest.php @@ -0,0 +1,42 @@ +create(); + + // Create 5 mod versions with specified versions + $versions = [ + '1.0.0', + '1.1.0', + '1.2.0', + '2.0.0', + '2.1.0', + ]; + + // get the highest version in the array + $latestVersion = max($versions); + + foreach ($versions as $version) { + ModVersion::factory()->create([ + 'mod_id' => $mod->id, + 'version' => $version, + ]); + } + + // Make a request to the mod's detail URL + $response = $this->get($mod->detailUrl()); + + $this->assertEquals('2.1.0', $latestVersion); + + // Assert the latest version is next to the mod's name + $response->assertSeeInOrder(explode(' ', "$mod->name $latestVersion")); + + // Assert the latest version is in the latest download button + $response->assertSeeText(__('Download Latest Version')." ($latestVersion)"); +});