100 lines
3.4 KiB
PHP
100 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\Event;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\EventPackage;
|
|
use App\Models\EventPackageAddon;
|
|
use App\Models\Package;
|
|
use App\Services\EventJoinTokenService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class EventPublicCapabilitiesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_event_response_hides_ai_capability_when_not_entitled(): void
|
|
{
|
|
$event = Event::factory()->create([
|
|
'status' => 'published',
|
|
]);
|
|
$this->attachPackage($event, ['basic_uploads', 'custom_tasks']);
|
|
$token = app(EventJoinTokenService::class)
|
|
->createToken($event, ['label' => 'public-ai-capability-locked'])
|
|
->token;
|
|
|
|
$response = $this->withHeader('X-Device-Id', 'public-ai-capability-locked-device')
|
|
->getJson("/api/v1/events/{$token}");
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('capabilities.ai_styling', false)
|
|
->assertJsonPath('capabilities.ai_styling_granted_by', null);
|
|
}
|
|
|
|
public function test_event_response_exposes_ai_capability_when_package_includes_feature(): void
|
|
{
|
|
$event = Event::factory()->create([
|
|
'status' => 'published',
|
|
]);
|
|
$this->attachPackage($event, ['basic_uploads', 'ai_styling']);
|
|
$token = app(EventJoinTokenService::class)
|
|
->createToken($event, ['label' => 'public-ai-capability-package'])
|
|
->token;
|
|
|
|
$response = $this->withHeader('X-Device-Id', 'public-ai-capability-package-device')
|
|
->getJson("/api/v1/events/{$token}");
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('capabilities.ai_styling', true)
|
|
->assertJsonPath('capabilities.ai_styling_granted_by', 'package');
|
|
}
|
|
|
|
public function test_event_response_exposes_ai_capability_when_addon_unlock_is_completed(): void
|
|
{
|
|
$event = Event::factory()->create([
|
|
'status' => 'published',
|
|
]);
|
|
$eventPackage = $this->attachPackage($event, ['basic_uploads', 'custom_tasks']);
|
|
EventPackageAddon::query()->create([
|
|
'event_package_id' => $eventPackage->id,
|
|
'event_id' => $event->id,
|
|
'tenant_id' => $event->tenant_id,
|
|
'addon_key' => 'ai_styling_unlock',
|
|
'quantity' => 1,
|
|
'status' => 'completed',
|
|
'purchased_at' => now(),
|
|
]);
|
|
$token = app(EventJoinTokenService::class)
|
|
->createToken($event, ['label' => 'public-ai-capability-addon'])
|
|
->token;
|
|
|
|
$response = $this->withHeader('X-Device-Id', 'public-ai-capability-addon-device')
|
|
->getJson("/api/v1/events/{$token}");
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('capabilities.ai_styling', true)
|
|
->assertJsonPath('capabilities.ai_styling_granted_by', 'addon');
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $features
|
|
*/
|
|
private function attachPackage(Event $event, array $features): EventPackage
|
|
{
|
|
$package = Package::factory()->endcustomer()->create([
|
|
'features' => $features,
|
|
]);
|
|
|
|
return EventPackage::query()->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(30),
|
|
]);
|
|
}
|
|
}
|