feat: add checkout editing policy to tenants and update related logic across services and resources

This commit is contained in:
2026-08-20 12:38:22 -03:00
parent c8ce3b0da3
commit 9c46eff880
17 changed files with 306 additions and 8 deletions

View File

@@ -81,6 +81,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
'is_featured' => true,
])
->assertCreated()
->assertJsonPath('data.code', 'food')
->assertJsonPath('data.category_name', 'Food')
->assertJsonPath('data.group_name', 'Food')
->assertJsonPath('data.is_featured', true)
@@ -96,6 +97,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
]);
$this->assertDatabaseHas('featured_groups', [
'tenant_code' => $tenant->codigo,
'code' => 'food',
'source_type' => 'category',
'category_id' => $categoryId,
'product_layout' => 'row',
@@ -130,6 +132,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
'is_featured' => true,
])
->assertOk()
->assertJsonPath('data.code', 'old-name')
->assertJsonPath('data.category_name', 'New name')
->assertJsonPath('data.group_name', 'New name')
->assertJsonPath('data.is_featured', true)
@@ -142,6 +145,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
]);
$this->assertDatabaseHas('featured_groups', [
'id' => $group->id,
'code' => 'old-name',
'group_name' => 'New name',
'product_layout' => 'row',
'group_layout' => 'paginated',

View File

@@ -1118,6 +1118,43 @@ class StorePurchaseTest extends TestCase
->assertSuccessful();
}
public function test_it_continues_expiring_purchases_after_an_inconsistent_reservation(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
$inconsistentPurchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
$validPurchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
$inconsistentPurchase->items()->create([
'source_catalog_item_id' => $variant->catalog_item_id,
'source_variant_id' => $variant->id,
'nombre' => 'Inconsistent item',
'slug' => 'inconsistent-item',
'cantidad' => 1,
'precio_unitario' => '50.00',
'discount_total' => '0.00',
'tax_total' => '0.00',
'total' => '50.00',
]);
$this->travel(31)->minutes();
$this->artisan('reservations:expire')
->expectsOutput('Expired purchases: 1')
->expectsOutput('Expired cart items: 0')
->assertSuccessful();
$this->assertDatabaseHas('compras', [
'id' => $inconsistentPurchase->id,
'status' => Purchase::STATUS_CREATED,
]);
$this->assertDatabaseHas('compras', [
'id' => $validPurchase->id,
'status' => Purchase::STATUS_EXPIRED,
]);
}
public function test_purchase_detail_uses_cart_items_for_created_purchase(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');

View File

@@ -5,6 +5,7 @@ namespace Tests\Feature\Sale;
use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;
use App\Domains\Cart\Models\Cart;
use App\Domains\Cart\Models\CartItem;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Purchase\Events\PurchasePaid;
use App\Domains\Purchase\Models\Purchase;
@@ -71,6 +72,44 @@ class AdminAppSaleControllerTest extends TestCase
->assertJsonPath('data.total', '40000.00');
}
public function test_an_adminapp_user_can_read_cart_items_from_an_unconfirmed_sale(): void
{
$tenant = $this->createTenant('acme');
Sanctum::actingAs($this->createAdminAppUser($tenant));
$catalogItem = CatalogItem::query()->create([
'tenant_code' => $tenant->codigo,
'slug' => 'entrada-general',
'nombre' => 'Entrada general',
'descripcion' => 'Acceso general',
'precio' => '12500.00',
]);
$cart = Cart::query()->create([
'tenant_codigo' => $tenant->codigo,
'status' => 'checkout',
]);
$cartItem = CartItem::query()->create([
'cart_id' => $cart->id,
'catalog_item_id' => $catalogItem->id,
'cantidad' => 2,
]);
$purchase = Purchase::query()->create([
'cart_id' => $cart->id,
'tenant_codigo' => $tenant->codigo,
'status' => Purchase::STATUS_PENDING_PAYMENT,
'total' => '25000.00',
]);
$this->getJson("/api/v1/adminapp/tenant/sales/{$purchase->id}")
->assertOk()
->assertJsonPath('data.items.0.id', $cartItem->id)
->assertJsonPath('data.items.0.product', 'Entrada general')
->assertJsonPath('data.items.0.event_dates', [])
->assertJsonPath('data.items.0.quantity', 2)
->assertJsonPath('data.items.0.unit_price', '12500.00')
->assertJsonPath('data.items.0.total', '25000.00');
}
public function test_an_adminapp_user_cannot_read_a_sale_from_another_tenant(): void
{
$tenant = $this->createTenant('acme');

View File

@@ -59,6 +59,8 @@ class BootstrapTenantControllerTest extends TestCase
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'acme.com',
'address' => 'Calle Test 123, Rosario',
'phone' => '+54 341 555 1234',
'primary_color' => '#ff0000',
'secondary_color' => '#00ff00',
'danger_color' => '#0000ff',
@@ -84,6 +86,8 @@ class BootstrapTenantControllerTest extends TestCase
->assertOk()
->assertJsonPath('data.codigo', 'acme')
->assertJsonPath('data.dominio', 'acme.com')
->assertJsonPath('data.address', 'Calle Test 123, Rosario')
->assertJsonPath('data.phone', '+54 341 555 1234')
->assertJsonPath('data.primary_color', '#ff0000')
->assertJsonPath('data.secondary_color', '#00ff00')
->assertJsonPath('data.danger_color', '#0000ff')