2024-08-09 12:35:46 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\Mod;
|
|
|
|
use App\Models\ModVersion;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
it('can retrieve all unresolved versions', function () {
|
2024-08-09 12:35:46 -04:00
|
|
|
// Create a mod instance
|
|
|
|
$mod = Mod::factory()->create();
|
2024-08-22 17:04:07 -04:00
|
|
|
ModVersion::factory(5)->recycle($mod)->create();
|
|
|
|
|
|
|
|
ModVersion::all()->each(function (ModVersion $modVersion) {
|
|
|
|
$modVersion->resolved_spt_version_id = null;
|
|
|
|
$modVersion->saveQuietly();
|
|
|
|
});
|
|
|
|
|
|
|
|
$unresolvedMix = $mod->versions(resolvedOnly: false);
|
2024-08-09 12:35:46 -04:00
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
$unresolvedMix->each(function (ModVersion $modVersion) {
|
|
|
|
expect($modVersion)->toBeInstanceOf(ModVersion::class)
|
|
|
|
->and($modVersion->resolved_spt_version_id)->toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
expect($unresolvedMix->count())->toBe(5)
|
|
|
|
->and($mod->versions->count())->toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the latest version on the mod detail page', function () {
|
2024-08-09 12:35:46 -04:00
|
|
|
$versions = [
|
|
|
|
'1.0.0',
|
|
|
|
'1.1.0',
|
|
|
|
'1.2.0',
|
|
|
|
'2.0.0',
|
|
|
|
'2.1.0',
|
|
|
|
];
|
|
|
|
$latestVersion = max($versions);
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
$mod = Mod::factory()->create();
|
2024-08-09 12:35:46 -04:00
|
|
|
foreach ($versions as $version) {
|
2024-08-22 17:04:07 -04:00
|
|
|
ModVersion::factory()->sptVersionResolved()->recycle($mod)->create(['version' => $version]);
|
2024-08-09 12:35:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->get($mod->detailUrl());
|
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
expect($latestVersion)->toBe('2.1.0');
|
2024-08-09 12:35:46 -04:00
|
|
|
|
|
|
|
// 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)");
|
|
|
|
});
|