feat(addons): finalize event addon catalog and ai styling upgrade flow
This commit is contained in:
@@ -84,6 +84,9 @@ class EventAddonCheckoutTest extends TenantTestCase
|
||||
|
||||
$addon = EventPackageAddon::where('event_package_id', $eventPackage->id)->latest()->first();
|
||||
$this->assertSame(1000, $addon->extra_photos); // increments * quantity
|
||||
$this->assertSame('Extra photos (500)', $addon->metadata['label'] ?? null);
|
||||
$this->assertSame(500, $addon->metadata['increments']['extra_photos'] ?? null);
|
||||
$this->assertNull($addon->metadata['price_eur'] ?? null);
|
||||
}
|
||||
|
||||
public function test_paypal_checkout_creates_pending_addon_record(): void
|
||||
@@ -149,5 +152,114 @@ class EventAddonCheckoutTest extends TenantTestCase
|
||||
|
||||
$addon = EventPackageAddon::where('event_package_id', $eventPackage->id)->latest()->first();
|
||||
$this->assertSame(1000, $addon->extra_photos);
|
||||
$this->assertSame('Extra photos (500)', $addon->metadata['label'] ?? null);
|
||||
$this->assertSame(12.5, $addon->metadata['price_eur'] ?? null);
|
||||
}
|
||||
|
||||
public function test_ai_styling_checkout_persists_feature_entitlement_metadata(): void
|
||||
{
|
||||
Config::set('package-addons.provider', CheckoutSession::PROVIDER_PAYPAL);
|
||||
Config::set('checkout.currency', 'EUR');
|
||||
Config::set('package-addons.ai_styling_unlock', [
|
||||
'label' => 'AI Styling Add-on',
|
||||
'price' => 9.00,
|
||||
'increments' => [],
|
||||
'metadata' => [
|
||||
'scope' => 'feature',
|
||||
],
|
||||
]);
|
||||
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_photos' => 100,
|
||||
'max_guests' => 50,
|
||||
'gallery_days' => 7,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->for($this->tenant)->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
$eventPackage = EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'used_photos' => 0,
|
||||
'used_guests' => 0,
|
||||
'gallery_expires_at' => now()->addDays(7),
|
||||
]);
|
||||
|
||||
$orders = Mockery::mock(PayPalOrderService::class);
|
||||
$orders->shouldReceive('createSimpleOrder')
|
||||
->once()
|
||||
->andReturn([
|
||||
'id' => 'ORDER-AI-1',
|
||||
'links' => [
|
||||
['rel' => 'approve', 'href' => 'https://paypal.test/approve-ai'],
|
||||
],
|
||||
]);
|
||||
$orders->shouldReceive('resolveApproveUrl')
|
||||
->once()
|
||||
->andReturn('https://paypal.test/approve-ai');
|
||||
$this->app->instance(PayPalOrderService::class, $orders);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/addons/checkout", [
|
||||
'addon_key' => 'ai_styling_unlock',
|
||||
'quantity' => 1,
|
||||
'accepted_terms' => true,
|
||||
'accepted_waiver' => true,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('checkout_id', 'ORDER-AI-1');
|
||||
|
||||
$this->assertDatabaseHas('event_package_addons', [
|
||||
'event_package_id' => $eventPackage->id,
|
||||
'addon_key' => 'ai_styling_unlock',
|
||||
'status' => 'pending',
|
||||
'amount' => 9.00,
|
||||
'currency' => 'EUR',
|
||||
]);
|
||||
|
||||
$addon = EventPackageAddon::where('event_package_id', $eventPackage->id)->latest()->first();
|
||||
$this->assertSame('AI Styling Add-on', $addon->metadata['label'] ?? null);
|
||||
$this->assertSame('feature', $addon->metadata['scope'] ?? null);
|
||||
$this->assertSame(['ai_styling'], $addon->metadata['entitlements']['features'] ?? null);
|
||||
$this->assertEquals(9.0, $addon->metadata['price_eur'] ?? null);
|
||||
$this->assertSame(0, $addon->extra_photos);
|
||||
$this->assertSame(0, $addon->extra_guests);
|
||||
$this->assertSame(0, $addon->extra_gallery_days);
|
||||
}
|
||||
|
||||
public function test_checkout_requires_both_legal_consents(): void
|
||||
{
|
||||
$package = Package::factory()->endcustomer()->create([
|
||||
'max_photos' => 100,
|
||||
'max_guests' => 50,
|
||||
'gallery_days' => 7,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->for($this->tenant)->create([
|
||||
'status' => 'published',
|
||||
]);
|
||||
|
||||
EventPackage::create([
|
||||
'event_id' => $event->id,
|
||||
'package_id' => $package->id,
|
||||
'purchased_price' => $package->price,
|
||||
'purchased_at' => now(),
|
||||
'used_photos' => 0,
|
||||
'used_guests' => 0,
|
||||
'gallery_expires_at' => now()->addDays(7),
|
||||
]);
|
||||
|
||||
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/addons/checkout", [
|
||||
'addon_key' => 'extra_photos_small',
|
||||
'quantity' => 1,
|
||||
'accepted_terms' => true,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors(['accepted_waiver']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user