Enable guest photo deletion and ownership flags
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-05 22:05:10 +01:00
parent c6aaf859f5
commit 18b4f36fcf
10 changed files with 455 additions and 14 deletions

View File

@@ -44,6 +44,7 @@ class EventPhotosLocaleTest extends TestCase
'tenant_id' => $event->tenant_id,
'task_id' => $task->id,
'emotion_id' => $emotion->id,
'created_by_device_id' => 'device-123',
'created_at' => now(),
'status' => 'approved',
]);
@@ -57,6 +58,7 @@ class EventPhotosLocaleTest extends TestCase
$responseEn->assertJsonPath('data.0.emotion.name', 'Joy');
$responseEn->assertJsonPath('data.0.emotion.icon', '🙂');
$responseEn->assertJsonPath('data.0.emotion.color', '#FF00AA');
$responseEn->assertJsonPath('data.0.is_mine', true);
$etag = $responseEn->headers->get('ETag');
$this->assertNotEmpty($etag);

View File

@@ -0,0 +1,87 @@
<?php
namespace Tests\Feature;
use App\Models\Event;
use App\Models\Photo;
use App\Models\PhotoLike;
use App\Models\PhotoShareLink;
use App\Services\EventJoinTokenService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class EventGuestPhotoDeleteTest extends TestCase
{
use RefreshDatabase;
public function test_guest_can_delete_own_photo(): void
{
$disk = config('filesystems.default', 'local');
Storage::fake($disk);
$event = Event::factory()->create([
'status' => 'published',
]);
$token = app(EventJoinTokenService::class)
->createToken($event, ['label' => 'guest'])
->plain_token;
$photo = Photo::factory()->for($event)->create([
'status' => 'approved',
'guest_name' => 'device-123',
'created_by_device_id' => 'device-123',
'file_path' => "events/{$event->id}/photos/test.jpg",
'thumbnail_path' => "events/{$event->id}/photos/thumbs/test_thumb.jpg",
]);
Storage::disk($disk)->put($photo->file_path, 'file');
Storage::disk($disk)->put($photo->thumbnail_path, 'thumb');
PhotoShareLink::factory()->create([
'photo_id' => $photo->id,
]);
PhotoLike::create([
'photo_id' => $photo->id,
'guest_name' => 'device-123',
'ip_address' => 'device',
]);
$response = $this->withHeaders(['X-Device-Id' => 'device-123'])
->deleteJson("/api/v1/events/{$token}/photos/{$photo->id}");
$response->assertOk();
$response->assertJsonFragment(['photo_id' => $photo->id]);
$this->assertDatabaseMissing('photos', ['id' => $photo->id]);
$this->assertDatabaseMissing('photo_share_links', ['photo_id' => $photo->id]);
$this->assertDatabaseMissing('photo_likes', ['photo_id' => $photo->id]);
Storage::disk($disk)->assertMissing($photo->file_path);
Storage::disk($disk)->assertMissing($photo->thumbnail_path);
}
public function test_guest_cannot_delete_someone_elses_photo(): void
{
$event = Event::factory()->create([
'status' => 'published',
]);
$token = app(EventJoinTokenService::class)
->createToken($event, ['label' => 'guest'])
->plain_token;
$photo = Photo::factory()->for($event)->create([
'status' => 'approved',
'guest_name' => 'device-123',
'created_by_device_id' => 'device-123',
]);
$this->withHeaders(['X-Device-Id' => 'device-999'])
->deleteJson("/api/v1/events/{$token}/photos/{$photo->id}")
->assertForbidden();
$this->assertDatabaseHas('photos', ['id' => $photo->id]);
}
}