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