mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-12 12:10:41 -05:00
Resolves Mod Detail Page Version Issue
The latest version on the mod detail page was being selected by created date instead of highest version number. This has been resolved. Also adds a test for this issue.
This commit is contained in:
parent
713ea7e076
commit
593b44150c
@ -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']));
|
||||
}
|
||||
|
@ -80,10 +80,7 @@ class ModResource extends JsonResource
|
||||
->values()
|
||||
),
|
||||
'links' => [
|
||||
'self' => route('mod.show', [
|
||||
'mod' => $this->id,
|
||||
'slug' => $this->slug,
|
||||
]),
|
||||
'self' => $this->detailUrl(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -114,7 +114,7 @@
|
||||
{{ __('Dependencies:') }}
|
||||
@foreach ($version->dependencies as $dependency)
|
||||
@if ($dependency->resolvedVersion?->mod)
|
||||
<a href="{{ route('mod.show', [$dependency->resolvedVersion->mod->id, $dependency->resolvedVersion->mod->slug]) }}">
|
||||
<a href="{{ $dependency->resolvedVersion->mod->detailUrl() }}">
|
||||
{{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }})
|
||||
</a>@if (!$loop->last), @endif
|
||||
@endif
|
||||
@ -184,7 +184,7 @@
|
||||
<h3>{{ __('Latest Version Dependencies') }}</h3>
|
||||
<p class="truncate">
|
||||
@foreach ($latestVersion->dependencies as $dependency)
|
||||
<a href="{{ route('mod.show', [$dependency->resolvedVersion->mod->id, $dependency->resolvedVersion->mod->slug]) }}">
|
||||
<a href="{{ $dependency->resolvedVersion->mod->detailUrl() }}">
|
||||
{{ $dependency->resolvedVersion->mod->name }} ({{ $dependency->resolvedVersion->version }})
|
||||
</a><br />
|
||||
@endforeach
|
||||
|
42
tests/Feature/ModTest.php
Normal file
42
tests/Feature/ModTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Mod;
|
||||
use App\Models\ModVersion;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('shows the latest version on the mod detail page', function () {
|
||||
// Create a mod instance
|
||||
$mod = Mod::factory()->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)");
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user