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,59 @@
<?php
namespace Tests\Feature\Api;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class HelpControllerTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('local');
$this->artisan('help:sync');
}
public function test_guest_help_listing_is_public(): void
{
$response = $this->getJson('/api/v1/help?audience=guest&locale=en');
$response->assertOk()
->assertJsonStructure(['data' => [['slug', 'title', 'summary']]])
->assertJsonFragment(['slug' => 'getting-started']);
}
public function test_guest_help_detail_returns_article(): void
{
$response = $this->getJson('/api/v1/help/getting-started?audience=guest&locale=en');
$response->assertOk()
->assertJsonPath('data.slug', 'getting-started');
$this->assertStringContainsString('When to read this', $response->json('data.body_html'));
}
public function test_admin_help_requires_authentication(): void
{
$this->getJson('/api/v1/help?audience=admin&locale=en')->assertStatus(401);
}
public function test_admin_help_allows_authenticated_users(): void
{
$user = User::factory()->create([
'role' => 'tenant_admin',
]);
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/help?audience=admin&locale=en');
$response->assertOk()
->assertJsonFragment(['slug' => 'tenant-dashboard-overview']);
}
}

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');
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Tests\Feature\Photobooth;
use App\Models\Event;
use App\Models\PhotoboothSetting;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\Feature\Tenant\TenantTestCase;
class PhotoboothControllerTest extends TenantTestCase
{
protected function setUp(): void
{
parent::setUp();
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',
]);
}
#[Test]
public function it_returns_photobooth_status_for_an_event(): void
{
$event = Event::factory()->for($this->tenant)->create([
'slug' => 'photobooth-demo',
]);
$response = $this->authenticatedRequest('GET', "/api/v1/tenant/events/{$event->slug}/photobooth");
$response->assertOk()
->assertJsonPath('data.enabled', false)
->assertJsonPath('data.username', null)
->assertJsonPath('data.ftp.port', 2121);
}
#[Test]
public function it_can_enable_and_rotate_photobooth_access(): void
{
$event = Event::factory()->for($this->tenant)->create([
'slug' => 'photobooth-event',
'date' => now()->addDay(),
]);
Http::fake([
'https://control.test/*' => Http::response(['ok' => true], 200),
]);
$enable = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/photobooth/enable");
$enable->assertOk()
->assertJsonPath('data.enabled', true)
->assertJsonPath('data.username', fn ($value) => is_string($value) && strlen($value) <= 10);
$event->refresh();
$this->assertTrue($event->photobooth_enabled);
$this->assertNotNull($event->photobooth_username);
$this->assertNotNull($event->photobooth_password);
$username = $event->photobooth_username;
$firstPassword = $event->photobooth_password;
Http::assertSent(fn ($request) => $request->url() === 'https://control.test/users' && $request['username'] === $username);
$rotate = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/photobooth/rotate");
$rotate->assertOk()
->assertJsonPath('data.enabled', true);
$event->refresh();
$this->assertNotSame($firstPassword, $event->photobooth_password);
Http::assertSent(fn ($request) => $request->url() === "https://control.test/users/{$username}/rotate");
}
#[Test]
public function it_can_disable_photobooth_access(): void
{
$event = Event::factory()->for($this->tenant)->create([
'slug' => 'photobooth-disable',
'photobooth_enabled' => true,
'photobooth_username' => 'pb123456',
'photobooth_path' => '/photobooth/demo',
'photobooth_status' => 'active',
'photobooth_expires_at' => now()->subDay(),
]);
$event->photobooth_password = 'SECRET12';
$event->save();
Http::fake([
'https://control.test/*' => Http::response(['ok' => true], 200),
]);
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/photobooth/disable");
$response->assertOk()
->assertJsonPath('data.enabled', false)
->assertJsonPath('data.username', null);
$event->refresh();
$this->assertFalse($event->photobooth_enabled);
$this->assertNull($event->photobooth_username);
Http::assertSent(fn ($request) => $request->url() === 'https://control.test/users/pb123456');
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Tests\Feature\Photobooth;
use App\Models\Event;
use App\Models\Photo;
use App\Models\Tenant;
use App\Services\EventJoinTokenService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class PhotoboothFilterTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function gallery_api_returns_only_photobooth_photos_when_filter_is_active(): void
{
$tenant = Tenant::factory()->create();
$event = Event::factory()
->for($tenant)
->create([
'status' => 'published',
'photobooth_enabled' => true,
]);
Photo::factory()->create([
'event_id' => $event->id,
'ingest_source' => Photo::SOURCE_PHOTOBOOTH,
'guest_name' => Photo::SOURCE_PHOTOBOOTH,
]);
Photo::factory()->create([
'event_id' => $event->id,
'ingest_source' => Photo::SOURCE_GUEST_PWA,
]);
/** @var EventJoinTokenService $tokens */
$tokens = app(EventJoinTokenService::class);
$token = $tokens->createToken($event, ['label' => 'Photobooth'])->getAttribute('plain_token');
$response = $this->getJson("/api/v1/events/{$token}/photos?filter=photobooth");
$response->assertOk();
$this->assertCount(1, $response->json('data'));
$this->assertSame(Photo::SOURCE_PHOTOBOOTH, $response->json('data.0.ingest_source'));
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Tests\Feature\Photobooth;
use App\Jobs\ProcessPhotoSecurityScan;
use App\Models\Emotion;
use App\Models\Event;
use App\Models\EventPackage;
use App\Models\MediaStorageTarget;
use App\Models\Package;
use App\Models\Photo;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class PhotoboothIngestCommandTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function it_ingests_pending_files_and_marks_them_as_photobooth(): void
{
Storage::fake('photobooth');
Storage::fake('public');
config([
'photobooth.import.disk' => 'photobooth',
'photobooth.import.max_files' => 10,
'filesystems.default' => 'public',
]);
MediaStorageTarget::create([
'key' => 'public',
'name' => 'Local Public',
'driver' => 'local',
'config' => [
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'is_hot' => true,
'is_default' => true,
'is_active' => true,
'priority' => 1,
]);
$tenant = Tenant::factory()->create();
$event = Event::factory()
->for($tenant)
->create([
'slug' => 'demo-event',
'status' => 'published',
'photobooth_enabled' => true,
]);
$event->update([
'photobooth_path' => $tenant->slug.'/'.$event->id,
]);
$package = Package::factory()->create(['max_photos' => 5]);
EventPackage::create([
'event_id' => $event->id,
'package_id' => $package->id,
'purchased_price' => 0,
'used_photos' => 0,
]);
Storage::disk('photobooth')->put($event->photobooth_path.'/sample.jpg', $this->sampleImage());
Emotion::factory()->create();
Bus::fake();
$this->artisan('photobooth:ingest', ['--event' => $event->id])
->assertExitCode(0);
$this->assertDatabaseHas('photos', [
'event_id' => $event->id,
'ingest_source' => Photo::SOURCE_PHOTOBOOTH,
]);
Storage::disk('photobooth')->assertMissing($event->photobooth_path.'/sample.jpg');
Bus::assertDispatched(ProcessPhotoSecurityScan::class);
}
private function sampleImage(): string
{
return base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==');
}
}