added a help system, replaced the words "tenant" and "Pwa" with better alternatives. corrected and implemented cron jobs. prepared going live on a coolify-powered system.

This commit is contained in:
Codex Agent
2025-11-10 16:23:09 +01:00
parent ba9e64dfcb
commit 447a90a742
123 changed files with 6398 additions and 153 deletions

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature\Console;
use App\Models\Event;
use App\Models\EventMediaAsset;
use App\Models\MediaStorageTarget;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Mockery;
use Tests\TestCase;
class CheckUploadQueuesCommandTest extends TestCase
{
use RefreshDatabase;
public function test_queue_health_snapshot_detects_alerts(): void
{
config()->set('storage-monitor.queue_health.thresholds', [
'media-storage' => ['warning' => 10, 'critical' => 20],
]);
config()->set('storage-monitor.queue_health.stalled_minutes', 5);
config()->set('storage-monitor.queue_health.cache_minutes', 5);
$manager = Mockery::mock(QueueManager::class);
$connection = Mockery::mock(\Illuminate\Contracts\Queue\Queue::class);
$manager->shouldReceive('connection')->with(config('queue.default'))->andReturn($connection);
$connection->shouldReceive('size')->with('media-storage')->andReturn(25);
$this->app->instance(QueueManager::class, $manager);
DB::table('failed_jobs')->insert([
'uuid' => (string) Str::uuid(),
'connection' => 'sync',
'queue' => 'media-storage',
'payload' => '{}',
'exception' => 'Test failure',
'failed_at' => now(),
]);
$target = MediaStorageTarget::create([
'key' => 'local-hot',
'name' => 'Local Hot',
'driver' => 'local',
'config' => ['monitor_path' => storage_path('app')],
'is_hot' => true,
'is_default' => true,
'is_active' => true,
'priority' => 100,
]);
$event = Event::factory()->create();
$asset = EventMediaAsset::create([
'event_id' => $event->id,
'media_storage_target_id' => $target->id,
'variant' => 'original',
'disk' => 'local-hot',
'path' => 'events/'.$event->id.'/pending.jpg',
'size_bytes' => 512,
'status' => 'pending',
]);
EventMediaAsset::whereKey($asset->id)->update([
'created_at' => now()->subMinutes(10),
'updated_at' => now()->subMinutes(10),
]);
$this->artisan('storage:check-upload-queues')
->expectsOutput('Checked 1 queue(s); 3 alert(s).')
->assertExitCode(0);
$snapshot = Cache::get('storage:queue-health:last');
$this->assertNotNull($snapshot);
$this->assertSame('critical', $snapshot['queues'][0]['severity']);
$this->assertGreaterThanOrEqual(1, count($snapshot['alerts']));
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace Tests\Feature\Console;
use App\Jobs\ArchiveEventMediaAssets;
use App\Models\Event;
use App\Models\EventMediaAsset;
use App\Models\EventPackage;
use App\Models\MediaStorageTarget;
use App\Models\Package;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class DispatchStorageArchiveCommandTest extends TestCase
{
use RefreshDatabase;
public function test_dispatches_archive_jobs_for_expired_events(): void
{
$target = MediaStorageTarget::create([
'key' => 'local-hot',
'name' => 'Local Hot',
'driver' => 'local',
'config' => ['monitor_path' => storage_path('app')],
'is_hot' => true,
'is_default' => true,
'is_active' => true,
'priority' => 100,
]);
$event = Event::factory()->create(['status' => 'published']);
$package = Package::factory()->create(['gallery_days' => 1]);
EventPackage::create([
'event_id' => $event->id,
'package_id' => $package->id,
'purchased_price' => 0,
'purchased_at' => now()->subDays(10),
'used_photos' => 0,
'used_guests' => 0,
'gallery_expires_at' => now()->subDays(5),
]);
EventMediaAsset::create([
'event_id' => $event->id,
'media_storage_target_id' => $target->id,
'variant' => 'original',
'disk' => 'local-hot',
'path' => 'events/'.$event->id.'/photo.jpg',
'size_bytes' => 1024,
'status' => 'hot',
]);
Queue::fake();
$this->artisan('storage:archive-pending')
->expectsOutput('Dispatched 1 archive job(s).')
->assertExitCode(0);
Queue::assertPushed(ArchiveEventMediaAssets::class, fn ($job) => $job->eventId === $event->id);
}
public function test_skips_events_without_pending_assets(): void
{
$target = MediaStorageTarget::create([
'key' => 'archive-only',
'name' => 'Archive Only',
'driver' => 'local',
'config' => ['monitor_path' => storage_path('app')],
'is_hot' => false,
'is_default' => false,
'is_active' => true,
'priority' => 50,
]);
$event = Event::factory()->create(['status' => 'archived']);
EventMediaAsset::create([
'event_id' => $event->id,
'media_storage_target_id' => $target->id,
'variant' => 'original',
'disk' => 'archive-only',
'path' => 'events/'.$event->id.'/archived.jpg',
'size_bytes' => 1024,
'status' => 'archived',
]);
Queue::fake();
$this->artisan('storage:archive-pending')
->expectsOutput('Dispatched 0 archive job(s).')
->assertExitCode(0);
Queue::assertNothingPushed();
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Tests\Feature\Console;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class HelpSyncCommandTest extends TestCase
{
public function test_it_builds_help_cache(): void
{
Storage::fake('local');
$this->artisan('help:sync')->assertExitCode(0);
Storage::disk('local')->assertExists('help/guest/en/articles.json');
$payload = json_decode(Storage::disk('local')->get('help/guest/en/articles.json'), true);
$this->assertNotEmpty($payload);
$this->assertContains('getting-started', array_column($payload, 'slug'));
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature\Console;
use App\Models\Event;
use App\Models\EventMediaAsset;
use App\Models\MediaStorageTarget;
use App\Services\Storage\StorageHealthService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Mockery;
use Tests\TestCase;
class MonitorStorageCommandTest extends TestCase
{
use RefreshDatabase;
public function test_monitor_command_caches_capacity_snapshot(): void
{
$target = MediaStorageTarget::create([
'key' => 'local-ssd',
'name' => 'Local SSD',
'driver' => 'local',
'config' => ['monitor_path' => storage_path('app')],
'is_hot' => true,
'is_default' => true,
'is_active' => true,
'priority' => 100,
]);
$event = Event::factory()->create();
EventMediaAsset::create([
'event_id' => $event->id,
'media_storage_target_id' => $target->id,
'photo_id' => null,
'variant' => 'original',
'disk' => 'local-ssd',
'path' => 'events/'.$event->id.'/photo.jpg',
'size_bytes' => 2048,
'status' => 'hot',
]);
EventMediaAsset::create([
'event_id' => $event->id,
'media_storage_target_id' => $target->id,
'photo_id' => null,
'variant' => 'thumbnail',
'disk' => 'local-ssd',
'path' => 'events/'.$event->id.'/thumb.jpg',
'size_bytes' => 512,
'status' => 'failed',
]);
$health = Mockery::mock(StorageHealthService::class);
$health->shouldReceive('getCapacity')->andReturn([
'status' => 'ok',
'total' => 100,
'free' => 10,
'used' => 90,
'percentage' => 90,
'path' => storage_path('app'),
]);
$this->app->instance(StorageHealthService::class, $health);
$this->artisan('storage:monitor')
->expectsOutput('Storage monitor finished: 1 targets, 2 alerts.')
->assertExitCode(0);
$snapshot = Cache::get('storage:monitor:last');
$this->assertNotNull($snapshot);
$this->assertCount(1, $snapshot['targets']);
$this->assertSame('local-ssd', $snapshot['targets'][0]['key']);
$this->assertSame(2, $snapshot['targets'][0]['assets']['total']);
$this->assertGreaterThanOrEqual(1, count($snapshot['alerts']));
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature\Console;
use App\Models\Event;
use App\Models\PhotoboothSetting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class PhotoboothCleanupCommandTest extends TestCase
{
use RefreshDatabase;
public function test_command_disables_expired_accounts(): void
{
config([
'photobooth.control_service.base_url' => 'https://control.test',
'photobooth.control_service.token' => 'secret-token',
]);
PhotoboothSetting::current()->update([
'control_service_base_url' => 'https://control.test',
]);
$event = Event::factory()->create([
'photobooth_enabled' => true,
'photobooth_username' => 'pbcleanup',
'photobooth_status' => 'active',
'photobooth_path' => '/photobooth/demo',
'photobooth_expires_at' => now()->subDay(),
]);
$event->photobooth_password = 'CLEANUP';
$event->save();
Http::fake([
'https://control.test/*' => Http::response(['ok' => true], 200),
]);
$this->artisan('photobooth:cleanup-expired')
->assertExitCode(0);
$event->refresh();
$this->assertFalse($event->photobooth_enabled);
$this->assertNull($event->photobooth_username);
$this->assertNotNull($event->photobooth_last_deprovisioned_at);
Http::assertSent(fn ($request) => $request->url() === 'https://control.test/users/pbcleanup');
}
}