2024-07-26 10:53:47 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\ModVersion;
|
2024-08-22 17:04:07 -04:00
|
|
|
use App\Models\SptVersion;
|
2024-07-26 10:53:47 -04:00
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
2024-07-31 14:40:19 -04:00
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
it('resolves spt versions when mod version is created', function () {
|
2024-08-22 17:04:07 -04:00
|
|
|
SptVersion::factory()->create(['version' => '1.0.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.1']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.2.0']);
|
|
|
|
|
|
|
|
$modVersion = ModVersion::factory()->create(['spt_version_constraint' => '~1.1.0']);
|
|
|
|
|
|
|
|
$modVersion->refresh();
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(2)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1');
|
2024-08-22 17:04:07 -04:00
|
|
|
});
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
it('resolves spt versions when constraint is updated', function () {
|
2024-08-22 17:04:07 -04:00
|
|
|
SptVersion::factory()->create(['version' => '1.0.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.1']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.2.0']);
|
|
|
|
|
|
|
|
$modVersion = ModVersion::factory()->create(['spt_version_constraint' => '~1.1.0']);
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$modVersion->refresh();
|
|
|
|
|
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(2)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1');
|
2024-08-22 17:04:07 -04:00
|
|
|
|
|
|
|
$modVersion->spt_version_constraint = '~1.2.0';
|
|
|
|
$modVersion->save();
|
|
|
|
|
|
|
|
$modVersion->refresh();
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(1)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.2.0');
|
2024-08-22 17:04:07 -04:00
|
|
|
});
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
it('resolves spt versions when spt version is created', function () {
|
2024-08-22 17:04:07 -04:00
|
|
|
SptVersion::factory()->create(['version' => '1.0.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.1']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.2.0']);
|
|
|
|
|
|
|
|
$modVersion = ModVersion::factory()->create(['spt_version_constraint' => '~1.1.0']);
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$modVersion->refresh();
|
|
|
|
|
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(2)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1');
|
2024-08-22 17:04:07 -04:00
|
|
|
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.2']);
|
|
|
|
|
|
|
|
$modVersion->refresh();
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(3)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1', '1.1.2');
|
2024-08-22 17:04:07 -04:00
|
|
|
});
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
it('resolves spt versions when spt version is deleted', function () {
|
2024-08-22 17:04:07 -04:00
|
|
|
SptVersion::factory()->create(['version' => '1.0.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.0']);
|
|
|
|
SptVersion::factory()->create(['version' => '1.1.1']);
|
|
|
|
$sptVersion = SptVersion::factory()->create(['version' => '1.1.2']);
|
|
|
|
|
|
|
|
$modVersion = ModVersion::factory()->create(['spt_version_constraint' => '~1.1.0']);
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
$modVersion->refresh();
|
|
|
|
$sptVersions = $modVersion->sptVersions;
|
|
|
|
|
|
|
|
expect($sptVersions)->toHaveCount(3)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1', '1.1.2');
|
2024-08-22 17:04:07 -04:00
|
|
|
|
|
|
|
$sptVersion->delete();
|
2024-08-29 15:46:10 -04:00
|
|
|
|
2024-08-22 17:04:07 -04:00
|
|
|
$modVersion->refresh();
|
2024-08-29 15:46:10 -04:00
|
|
|
$sptVersions = $modVersion->sptVersions;
|
2024-08-22 17:04:07 -04:00
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
expect($sptVersions)->toHaveCount(2)
|
|
|
|
->and($sptVersions->pluck('version'))->toContain('1.1.0', '1.1.1');
|
2024-08-22 17:04:07 -04:00
|
|
|
});
|
|
|
|
|
2024-07-26 10:53:47 -04:00
|
|
|
it('includes only published mod versions', function () {
|
|
|
|
$publishedMod = ModVersion::factory()->create([
|
|
|
|
'published_at' => Carbon::now()->subDay(),
|
|
|
|
]);
|
|
|
|
$unpublishedMod = ModVersion::factory()->create([
|
|
|
|
'published_at' => Carbon::now()->addDay(),
|
|
|
|
]);
|
|
|
|
$noPublishedDateMod = ModVersion::factory()->create([
|
|
|
|
'published_at' => null,
|
|
|
|
]);
|
|
|
|
|
2024-07-31 14:40:19 -04:00
|
|
|
$all = ModVersion::withoutGlobalScopes()->get();
|
|
|
|
expect($all)->toHaveCount(3);
|
|
|
|
|
2024-07-26 10:53:47 -04:00
|
|
|
$mods = ModVersion::all();
|
|
|
|
|
2024-07-31 20:30:50 -04:00
|
|
|
expect($mods)->toHaveCount(1)
|
|
|
|
->and($mods->contains($publishedMod))->toBeTrue()
|
|
|
|
->and($mods->contains($unpublishedMod))->toBeFalse()
|
|
|
|
->and($mods->contains($noPublishedDateMod))->toBeFalse();
|
2024-07-26 10:53:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles null published_at as not published', function () {
|
|
|
|
$modWithNoPublishDate = ModVersion::factory()->create([
|
|
|
|
'published_at' => null,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$mods = ModVersion::all();
|
|
|
|
|
2024-07-31 14:06:56 -04:00
|
|
|
expect($mods->contains($modWithNoPublishDate))->toBeFalse();
|
2024-07-26 10:53:47 -04:00
|
|
|
});
|