88 lines
3.1 KiB
PHP
88 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Livewire\Versions\Index;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* The "check for updates" action. The production image ships no .git, so the latest release
|
|
* must come from the public Git host's tag API — not a local read (which would always be empty
|
|
* in prod and wrongly report "no release tagged"). These tests drive that API with Http::fake.
|
|
*/
|
|
class VersionUpdateCheckTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private const TAGS_URL = 'git.bave.dev/api/v1/repos/boban/clusev/tags*';
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Cache::flush(); // never inherit a cached latest-release between tests
|
|
$this->actingAs(User::factory()->create(['must_change_password' => false]));
|
|
}
|
|
|
|
public function test_reports_update_available_from_the_remote_tag_api(): void
|
|
{
|
|
config()->set('clusev.version', '0.9.4');
|
|
Http::fake([self::TAGS_URL => Http::response([
|
|
['name' => 'v0.9.6'], ['name' => 'v0.9.5'], ['name' => 'v0.9.4'],
|
|
])]);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('checkUpdates')
|
|
->assertSet('updateState', 'update')
|
|
->assertSee('0.9.6');
|
|
}
|
|
|
|
public function test_reports_current_when_installed_is_at_or_above_the_latest_tag(): void
|
|
{
|
|
config()->set('clusev.version', '0.9.9');
|
|
Http::fake([self::TAGS_URL => Http::response([['name' => 'v0.9.6']])]);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('checkUpdates')
|
|
->assertSet('updateState', 'current');
|
|
}
|
|
|
|
public function test_stable_channel_ignores_prereleases_but_beta_sees_them(): void
|
|
{
|
|
config()->set('clusev.version', '0.9.6');
|
|
Http::fake([self::TAGS_URL => Http::response([
|
|
['name' => 'v1.0.0-beta1'], ['name' => 'v0.9.6'],
|
|
])]);
|
|
|
|
// stable: 1.0.0-beta1 is not offered, 0.9.6 == installed → current
|
|
Setting::put('release_channel', 'stable');
|
|
Livewire::test(Index::class)->call('checkUpdates')->assertSet('updateState', 'current');
|
|
|
|
// beta: the prerelease is newer → update available
|
|
Cache::flush();
|
|
Setting::put('release_channel', 'beta');
|
|
Livewire::test(Index::class)
|
|
->call('checkUpdates')
|
|
->assertSet('updateState', 'update')
|
|
->assertSee('1.0.0-beta1');
|
|
}
|
|
|
|
public function test_degrades_gracefully_when_the_remote_api_is_unreachable(): void
|
|
{
|
|
// Installed version above any real local .git tag, so the local fallback can't claim an
|
|
// update — this asserts a failed remote lookup never crashes the action.
|
|
config()->set('clusev.version', '99.0.0');
|
|
Http::fake([self::TAGS_URL => Http::response('upstream down', 500)]);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('checkUpdates')
|
|
->assertSet('updateState', 'current')
|
|
->assertSet('lastChecked', now()->format('H:i'));
|
|
}
|
|
}
|