hooks in config/services.php/.env.example, and updated wizard steps/controllers to store session payloads, attach packages, and surface localized success/error states. - Retooled payment handling for both Stripe and PayPal, adding richer status management in CheckoutController/ PayPalController, fallback flows in the wizard’s PaymentStep.tsx, and fresh feature tests for intent creation, webhooks, and the wizard CTA. - Introduced a consent-aware Matomo analytics stack: new consent context, cookie-banner UI, useAnalytics/ useCtaExperiment hooks, and MatomoTracker component, then instrumented marketing pages (Home, Packages, Checkout) with localized copy and experiment tracking. - Polished package presentation across marketing UIs by centralizing formatting in PresentsPackages, surfacing localized description tables/placeholders, tuning badges/layouts, and syncing guest/marketing translations. - Expanded docs & reference material (docs/prp/*, TODOs, public gallery overview) and added a Playwright smoke test for the hero CTA while reconciling outstanding checklist items.
162 lines
4.6 KiB
PHP
162 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\Photo;
|
|
use App\Services\EventJoinTokenService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class GuestJoinTokenFlowTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private EventJoinTokenService $tokenService;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->tokenService = app(EventJoinTokenService::class);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
private function createPublishedEvent(): Event
|
|
{
|
|
return Event::factory()->create([
|
|
'status' => 'published',
|
|
]);
|
|
}
|
|
|
|
public function test_guest_can_access_stats_using_join_token(): void
|
|
{
|
|
$event = $this->createPublishedEvent();
|
|
|
|
Photo::factory()->count(3)->create([
|
|
'event_id' => $event->id,
|
|
'guest_name' => 'device-stats',
|
|
]);
|
|
|
|
$token = $this->tokenService->createToken($event);
|
|
|
|
$response = $this->getJson("/api/v1/events/{$token->token}/stats");
|
|
|
|
$response->assertOk()
|
|
->assertJsonStructure([
|
|
'online_guests',
|
|
'tasks_solved',
|
|
'latest_photo_at',
|
|
]);
|
|
}
|
|
|
|
public function test_guest_can_upload_photo_with_join_token(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$event = $this->createPublishedEvent();
|
|
$token = $this->tokenService->createToken($event);
|
|
|
|
Mockery::mock('alias:App\Support\ImageHelper')
|
|
->shouldReceive('makeThumbnailOnDisk')
|
|
->andReturn("events/{$event->id}/photos/thumbs/generated_thumb.jpg");
|
|
|
|
$file = UploadedFile::fake()->image('example.jpg', 1200, 800);
|
|
|
|
$response = $this->withHeader('X-Device-Id', 'token-device')
|
|
->postJson("/api/v1/events/{$token->token}/upload", [
|
|
'photo' => $file,
|
|
]);
|
|
|
|
$response->assertCreated()
|
|
->assertJsonStructure(['id', 'file_path', 'thumbnail_path']);
|
|
|
|
$this->assertDatabaseCount('photos', 1);
|
|
|
|
$saved = Photo::first();
|
|
$this->assertNotNull($saved);
|
|
$this->assertEquals($event->id, $saved->event_id);
|
|
|
|
$storedPath = $saved->file_path
|
|
? ltrim(str_replace('/storage/', '', $saved->file_path), '/')
|
|
: null;
|
|
|
|
if ($storedPath) {
|
|
$this->assertTrue(
|
|
Storage::disk('public')->exists($storedPath),
|
|
sprintf('Uploaded file [%s] was not stored on the public disk.', $storedPath)
|
|
);
|
|
}
|
|
}
|
|
|
|
public function test_guest_can_like_photo_after_joining_with_token(): void
|
|
{
|
|
$event = $this->createPublishedEvent();
|
|
$token = $this->tokenService->createToken($event);
|
|
|
|
$photo = Photo::factory()->create([
|
|
'event_id' => $event->id,
|
|
'likes_count' => 0,
|
|
]);
|
|
|
|
$this->getJson("/api/v1/events/{$token->token}");
|
|
|
|
$response = $this->withHeader('X-Device-Id', 'device-like')
|
|
->postJson("/api/v1/photos/{$photo->id}/like");
|
|
|
|
$response->assertOk()
|
|
->assertJson([
|
|
'liked' => true,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('photo_likes', [
|
|
'photo_id' => $photo->id,
|
|
'guest_name' => 'device-like',
|
|
]);
|
|
|
|
$this->assertEquals(1, $photo->fresh()->likes_count);
|
|
}
|
|
|
|
public function test_guest_cannot_access_event_with_expired_token(): void
|
|
{
|
|
$event = $this->createPublishedEvent();
|
|
$token = $this->tokenService->createToken($event, [
|
|
'expires_at' => now()->subDay(),
|
|
]);
|
|
|
|
$response = $this->getJson("/api/v1/events/{$token->token}");
|
|
|
|
$response->assertStatus(410)
|
|
->assertJsonPath('error.code', 'token_expired');
|
|
}
|
|
|
|
public function test_slug_access_is_rejected(): void
|
|
{
|
|
$event = $this->createPublishedEvent();
|
|
|
|
$response = $this->getJson("/api/v1/events/{$event->slug}");
|
|
|
|
$response->assertStatus(404)
|
|
->assertJsonPath('error.code', 'invalid_token');
|
|
}
|
|
|
|
public function test_guest_cannot_access_event_with_revoked_token(): void
|
|
{
|
|
$event = $this->createPublishedEvent();
|
|
$token = $this->tokenService->createToken($event);
|
|
$this->tokenService->revoke($token, 'revoked for test');
|
|
|
|
$response = $this->getJson("/api/v1/events/{$token->token}");
|
|
|
|
$response->assertStatus(410)
|
|
->assertJsonPath('error.code', 'token_revoked');
|
|
}
|
|
}
|