mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
Reviewed the download count PR work and made some changes: - Updated the download link route to include the mod's slug for easier identification. - Moved rate limiter from the route middleware (the entire controller) to just the show method in the controller. - Created a ModVersionPolicy that the controller can check against. - Moves download increment logic into the model. - Defers the call to the download increment logic (now run in the background) - Updated the route to have a name, and the downloadUrl methods to build the URL dynamically using the route name. - Wrote some tests to check URL building, download counting, and rate limiting. # Conflicts: # app/Http/Controllers/ModVersionController.php # app/Providers/AppServiceProvider.php
62 lines
2.5 KiB
PHP
62 lines
2.5 KiB
PHP
<?php
|
|
|
|
use App\Models\Mod;
|
|
use App\Models\ModVersion;
|
|
use App\Models\SptVersion;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('displays homepage mod cards with the latest supported spt version number', function () {
|
|
$sptVersion1 = SptVersion::factory()->create(['version' => '1.0.0']);
|
|
$sptVersion2 = SptVersion::factory()->create(['version' => '2.0.0']);
|
|
$sptVersion3 = SptVersion::factory()->create(['version' => '3.0.0']);
|
|
|
|
$mod1 = Mod::factory()->create();
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion1->version]);
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion1->version]);
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion2->version]);
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion2->version]);
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion3->version]);
|
|
ModVersion::factory()->recycle($mod1)->create(['spt_version_constraint' => $sptVersion3->version]);
|
|
|
|
$response = $this->get(route('home'));
|
|
|
|
$response->assertSeeInOrder(explode(' ', "$mod1->name $sptVersion3->version_formatted"));
|
|
});
|
|
|
|
it('displays the latest version on the mod detail page', function () {
|
|
$versions = [
|
|
'1.0.0',
|
|
'1.1.0',
|
|
'1.2.0',
|
|
'2.0.0',
|
|
'2.1.0',
|
|
];
|
|
$latestVersion = max($versions);
|
|
|
|
$mod = Mod::factory()->create();
|
|
foreach ($versions as $version) {
|
|
ModVersion::factory()->recycle($mod)->create(['version' => $version]);
|
|
}
|
|
|
|
$response = $this->get($mod->detailUrl());
|
|
|
|
expect($latestVersion)->toBe('2.1.0');
|
|
|
|
// 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)");
|
|
});
|
|
|
|
it('builds download links using the latest mod version', function () {
|
|
$mod = Mod::factory()->create(['id' => 1, 'slug' => 'test-mod']);
|
|
ModVersion::factory()->recycle($mod)->create(['version' => '1.2.3']);
|
|
ModVersion::factory()->recycle($mod)->create(['version' => '1.3.0']);
|
|
$modVersion = ModVersion::factory()->recycle($mod)->create(['version' => '1.3.4']);
|
|
|
|
expect($mod->downloadUrl())->toEqual("/mod/download/$mod->id/$mod->slug/$modVersion->version");
|
|
});
|