feat(checkout): return event purchase summary

This commit is contained in:
2026-09-21 10:59:39 -03:00
parent 6d077647ba
commit fcb8386735
4 changed files with 111 additions and 6 deletions

View File

@@ -2,14 +2,16 @@
namespace Tests\Feature\Purchase;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Commerce\Cart\Models\Cart;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Commerce\Purchase\Services\CheckoutService;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
@@ -117,6 +119,70 @@ class PurchaseCatalogItemTest extends TestCase
]);
}
public function test_multi_event_checkout_returns_only_the_event_image(): void
{
Storage::fake('s3');
Storage::disk('s3')->buildTemporaryUrlsUsing(
fn (string $path): string => "https://snapshots.test/{$path}",
);
StorefrontWebsiteType::query()->create([
'codigo' => 'onticket_multi_event',
'nombre' => 'OnTicket - múltiples eventos',
'header_type' => 'immersive',
'checkout_summary_type' => StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT,
]);
$tenant = $this->createTenant();
$tenant->update(['storefront_website_type_code' => 'onticket_multi_event']);
$user = User::factory()->create();
$eventImage = $this->createAttachment('checkout-event');
$productImage = $this->createAttachment('checkout-product');
Storage::disk('s3')->put($eventImage->path, 'event-image');
Storage::disk('s3')->put($productImage->path, 'product-image');
$event = Event::query()->create([
'tenant_code' => $tenant->codigo,
'title' => 'Festival de prueba',
'published_at' => now(),
'attachment_id' => $eventImage->id,
]);
$inventory = Inventory::query()->create(['real_stock' => 10]);
$catalogItem = CatalogItem::query()->create([
'tenant_code' => $tenant->codigo,
'inventory_id' => $inventory->id,
'slug' => 'entrada-general',
'nombre' => 'Entrada general',
'precio' => 10000,
]);
$catalogItem->event_id = $event->id;
$catalogItem->save();
$catalogItem->attachments()->attach($productImage->id, ['orden' => 0]);
$cart = Cart::query()->create([
'tenant_codigo' => $tenant->codigo,
'user_id' => $user->id,
'status' => 'active',
]);
$cart->addItem($catalogItem->id, null, 1);
$purchase = app(CheckoutService::class)->startCheckout($tenant, $user->id, [
'cart_id' => $cart->id,
'dni' => '12345678',
'telefono' => '123456789',
'nombre_apellido' => 'Test User',
'email' => 'test@example.com',
]);
$this->actingAs($user, 'sanctum')
->getJson("/api/tenants/{$tenant->codigo}/compras/{$purchase->id}")
->assertOk()
->assertJsonMissingPath('data.items.0.item_details.imagen')
->assertJsonPath('data.event.id', $event->id)
->assertJsonPath('data.event.title', 'Festival de prueba')
->assertJsonPath('data.event.image', "https://snapshots.test/{$eventImage->path}");
}
private function createTenant(): Tenant
{
$headerLogo = $this->createAttachment('purchase-header');