Limit-Status im Upload-Flow anzeigen (Warnbanner + Sperrzustände).
Upload-Fehlercodes auswerten und freundliche Dialoge zeigen.
This commit is contained in:
31
tests/Feature/Api/Event/PublicEventErrorResponseTest.php
Normal file
31
tests/Feature/Api/Event/PublicEventErrorResponseTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Event;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PublicEventErrorResponseTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_invalid_join_token_returns_structured_error(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/events/not-a-token/stats');
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertJsonStructure([
|
||||
'error' => ['code', 'title', 'message', 'meta'],
|
||||
]);
|
||||
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'code' => 'invalid_token',
|
||||
'title' => 'Invalid Join Token',
|
||||
'message' => 'The provided join token is invalid.',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame('not-a-token', $response->json('error.meta.token'));
|
||||
}
|
||||
}
|
||||
@@ -131,4 +131,40 @@ class EventGuestUploadLimitTest extends TestCase
|
||||
$this->assertGreaterThanOrEqual(2, $thresholdJobs->count());
|
||||
Bus::assertDispatched(SendEventPackagePhotoLimitNotification::class);
|
||||
}
|
||||
|
||||
public function test_guest_package_endpoint_returns_limits_summary(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create();
|
||||
$event = Event::factory()->for($tenant)->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_photos' => 10,
|
||||
'max_guests' => 20,
|
||||
'gallery_days' => 7,
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now()->subDay(),
|
||||
'used_photos' => 8,
|
||||
'used_guests' => 5,
|
||||
'gallery_expires_at' => now()->addDays(3),
|
||||
]);
|
||||
|
||||
$token = app(EventJoinTokenService::class)->createToken($event)->plain_token;
|
||||
|
||||
$response = $this->getJson("/api/v1/events/{$token}/package");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('id', $eventPackage->id);
|
||||
$response->assertJsonPath('limits.photos.limit', 10);
|
||||
$response->assertJsonPath('limits.photos.used', 8);
|
||||
$response->assertJsonPath('limits.photos.state', 'warning');
|
||||
$response->assertJsonPath('limits.gallery.state', 'warning');
|
||||
$response->assertJsonPath('limits.can_upload_photos', true);
|
||||
}
|
||||
}
|
||||
|
||||
26
tests/Feature/Api/Tenant/TenantTokenGuardTest.php
Normal file
26
tests/Feature/Api/Tenant/TenantTokenGuardTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Tenant;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class TenantTokenGuardTest extends TestCase
|
||||
{
|
||||
public function test_missing_token_returns_structured_error(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/tenant/events');
|
||||
|
||||
$response->assertStatus(401);
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'code' => 'token_missing',
|
||||
'title' => 'Token Missing',
|
||||
'message' => 'Authentication token not provided.',
|
||||
],
|
||||
]);
|
||||
|
||||
$error = $response->json('error');
|
||||
$this->assertIsArray($error);
|
||||
$this->assertArrayNotHasKey('meta', $error);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,6 @@ class EventControllerTest extends TestCase
|
||||
]);
|
||||
|
||||
$response->assertStatus(402)
|
||||
->assertJson(['error' => 'Upload limit reached for this event']);
|
||||
->assertJsonPath('error.code', 'photo_limit_exceeded');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Tenant;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Services\Packages\PackageLimitEvaluator;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PackageLimitEvaluatorTest extends TestCase
|
||||
@@ -125,4 +126,43 @@ class PackageLimitEvaluatorTest extends TestCase
|
||||
|
||||
$this->assertNull($violation);
|
||||
}
|
||||
|
||||
public function test_summarize_event_package_returns_expected_structure(): void
|
||||
{
|
||||
Config::set('package-limits.photo_thresholds', [0.5, 0.9]);
|
||||
Config::set('package-limits.guest_thresholds', [0.5]);
|
||||
Config::set('package-limits.gallery_warning_days', [7, 1]);
|
||||
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_photos' => 10,
|
||||
'max_guests' => 20,
|
||||
'gallery_days' => 7,
|
||||
]);
|
||||
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
$event = Event::factory()->for($tenant)->create();
|
||||
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now()->subDay(),
|
||||
'used_photos' => 5,
|
||||
'used_guests' => 10,
|
||||
'gallery_expires_at' => now()->addDays(3),
|
||||
])->fresh(['package']);
|
||||
|
||||
$summary = $this->evaluator->summarizeEventPackage($eventPackage);
|
||||
|
||||
$this->assertSame(10, $summary['photos']['limit']);
|
||||
$this->assertSame(5, $summary['photos']['used']);
|
||||
$this->assertSame('warning', $summary['photos']['state']);
|
||||
$this->assertSame(20, $summary['guests']['limit']);
|
||||
$this->assertSame(10, $summary['guests']['used']);
|
||||
$this->assertSame('warning', $summary['guests']['state']);
|
||||
$this->assertSame('warning', $summary['gallery']['state']);
|
||||
$this->assertTrue($summary['can_upload_photos']);
|
||||
$this->assertTrue($summary['can_add_guests']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user