feat: Add event association to purchases; implement event relationship in models, update migration, and enhance tests

This commit is contained in:
2026-08-04 11:45:03 -03:00
parent 1de08c1ca4
commit 8aa3a26ee7
7 changed files with 83 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Category;
use App\Domains\Catalog\Models\Inventory;
use App\Domains\Catalog\Models\Variant;
use App\Domains\Event\Models\Event;
use App\Domains\Purchase\Models\Purchase;
use App\Domains\Purchase\Services\CheckoutService;
use App\Domains\Tenant\Models\Tenant;
@@ -33,6 +34,12 @@ class StorePurchaseTest extends TestCase
public function test_it_creates_an_independent_purchase_snapshot_from_cart(): void
{
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$event = Event::query()->create([
'tenant_code' => $tenant->codigo,
'name' => 'Sonder Fest',
'address' => 'Test address',
]);
$tenant->update(['active_event_id' => $event->id]);
$user = User::factory()->create([
'email' => 'buyer@example.com',
]);
@@ -85,6 +92,7 @@ class StorePurchaseTest extends TestCase
$response->assertJsonPath('data.nombre_apellido', null);
$response->assertJsonPath('data.email', null);
$response->assertJsonPath('data.tenant_codigo', 'sonder');
$response->assertJsonPath('data.event_id', $event->id);
$response->assertJsonPath('data.status', Purchase::STATUS_CREATED);
$response->assertJsonPath('data.items_source', 'purchase');
$response->assertJsonCount(1, 'data.items');
@@ -97,6 +105,7 @@ class StorePurchaseTest extends TestCase
'id' => $purchaseId,
'cart_id' => $cartId,
'tenant_codigo' => 'sonder',
'event_id' => $event->id,
'user_id' => $user->id,
'dni' => null,
'telefono' => null,