feat(addons): finalize event addon catalog and ai styling upgrade flow
This commit is contained in:
@@ -31,6 +31,10 @@ class EventAddonCatalogTest extends TestCase
|
||||
'sort' => 1,
|
||||
'metadata' => [
|
||||
'price_eur' => 12,
|
||||
'scope' => 'feature',
|
||||
'entitlements' => [
|
||||
'features' => ['ai_styling'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -44,5 +48,7 @@ class EventAddonCatalogTest extends TestCase
|
||||
$this->assertSame(200, $addon['increments']['extra_photos']);
|
||||
$this->assertSame(12.0, $addon['price']);
|
||||
$this->assertSame('EUR', $addon['currency']);
|
||||
$this->assertSame('feature', $addon['metadata']['scope'] ?? null);
|
||||
$this->assertSame(['ai_styling'], $addon['metadata']['entitlements']['features'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
108
tests/Unit/Services/EventFeatureEntitlementServiceTest.php
Normal file
108
tests/Unit/Services/EventFeatureEntitlementServiceTest.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPackage;
|
||||
use App\Models\EventPackageAddon;
|
||||
use App\Models\Package;
|
||||
use App\Services\Addons\EventFeatureEntitlementService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventFeatureEntitlementServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_grants_feature_via_package(): void
|
||||
{
|
||||
$service = app(EventFeatureEntitlementService::class);
|
||||
$event = Event::factory()->create();
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'features' => ['basic_uploads', 'ai_styling'],
|
||||
]);
|
||||
|
||||
EventPackage::query()->create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'gallery_expires_at' => now()->addDays(30),
|
||||
]);
|
||||
|
||||
$result = $service->resolveForEvent($event->fresh(), 'ai_styling', ['ai_styling_unlock']);
|
||||
|
||||
$this->assertTrue($result['allowed']);
|
||||
$this->assertSame('package', $result['granted_by']);
|
||||
}
|
||||
|
||||
public function test_it_grants_feature_via_completed_addon_key(): void
|
||||
{
|
||||
$service = app(EventFeatureEntitlementService::class);
|
||||
$event = Event::factory()->create();
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'features' => ['basic_uploads'],
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::query()->create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'gallery_expires_at' => now()->addDays(30),
|
||||
]);
|
||||
|
||||
EventPackageAddon::query()->create([
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'event_id' => $event->id,
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'addon_key' => 'custom_entitlement',
|
||||
'quantity' => 1,
|
||||
'status' => 'completed',
|
||||
'purchased_at' => now(),
|
||||
]);
|
||||
|
||||
$result = $service->resolveForEvent($event->fresh(), 'ai_styling', ['custom_entitlement']);
|
||||
|
||||
$this->assertTrue($result['allowed']);
|
||||
$this->assertSame('addon', $result['granted_by']);
|
||||
}
|
||||
|
||||
public function test_it_denies_feature_when_addon_is_expired(): void
|
||||
{
|
||||
$service = app(EventFeatureEntitlementService::class);
|
||||
$event = Event::factory()->create();
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'features' => ['basic_uploads'],
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::query()->create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'gallery_expires_at' => now()->addDays(30),
|
||||
]);
|
||||
|
||||
EventPackageAddon::query()->create([
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'event_id' => $event->id,
|
||||
'tenant_id' => $event->tenant_id,
|
||||
'addon_key' => 'custom_entitlement',
|
||||
'quantity' => 1,
|
||||
'status' => 'completed',
|
||||
'purchased_at' => now()->subDays(2),
|
||||
'metadata' => [
|
||||
'entitlements' => [
|
||||
'expires_at' => now()->subDay()->toIso8601String(),
|
||||
'features' => ['ai_styling'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$result = $service->resolveForEvent($event->fresh(), 'ai_styling', ['custom_entitlement']);
|
||||
|
||||
$this->assertFalse($result['allowed']);
|
||||
$this->assertNull($result['granted_by']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user