fix(purchase): enhance handling of cart items for created and pending payment purchases
This commit is contained in:
@@ -1244,6 +1244,42 @@ class StorePurchaseTest extends TestCase
|
||||
->assertJsonPath('data.total', '100.00');
|
||||
}
|
||||
|
||||
public function test_created_and_pending_payment_purchase_details_use_the_current_cart_quantity(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create([
|
||||
'email' => 'buyer@example.com',
|
||||
]);
|
||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||
|
||||
foreach ([Purchase::STATUS_CREATED, Purchase::STATUS_PENDING_PAYMENT] as $status) {
|
||||
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
||||
$purchase->items()->create([
|
||||
'source_catalog_item_id' => $variant->catalog_item_id,
|
||||
'source_variant_id' => $variant->id,
|
||||
'item_nombre' => $variant->catalogItem->nombre,
|
||||
'descripcion' => $variant->catalogItem->descripcion,
|
||||
'slug' => $variant->catalogItem->slug,
|
||||
'variant_attributes' => [],
|
||||
'cantidad' => 1,
|
||||
'precio_unitario' => '50.00',
|
||||
'total' => '50.00',
|
||||
]);
|
||||
$purchase->cart->items()->update(['cantidad' => 3]);
|
||||
$purchase->update(['status' => $status]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/sonder/compras/{$purchase->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', $status)
|
||||
->assertJsonPath('data.items_source', 'cart')
|
||||
->assertJsonPath('data.items.0.quantity', 3)
|
||||
->assertJsonPath('data.items.0.line_total', '150.00')
|
||||
->assertJsonPath('data.subtotal', '150.00')
|
||||
->assertJsonPath('data.total', '150.00');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_purchase_detail_uses_purchase_items_for_paid_purchase_even_without_cart(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
|
||||
@@ -31,6 +31,83 @@ class AdminAppSaleControllerTest extends TestCase
|
||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||
}
|
||||
|
||||
public function test_sales_list_uses_cart_quantity_for_created_and_pending_payment_sales(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$catalogItem = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'slug' => 'entrada-general',
|
||||
'nombre' => 'Entrada general',
|
||||
'precio' => '10000.00',
|
||||
]);
|
||||
|
||||
$createdCart = Cart::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => 'checkout',
|
||||
]);
|
||||
CartItem::query()->create([
|
||||
'cart_id' => $createdCart->id,
|
||||
'catalog_item_id' => $catalogItem->id,
|
||||
'cantidad' => 3,
|
||||
]);
|
||||
$createdPurchase = Purchase::query()->create([
|
||||
'cart_id' => $createdCart->id,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => Purchase::STATUS_CREATED,
|
||||
'total' => '30000.00',
|
||||
]);
|
||||
PurchaseItem::query()->create([
|
||||
'compra_id' => $createdPurchase->id,
|
||||
'source_catalog_item_id' => $catalogItem->id,
|
||||
'item_nombre' => $catalogItem->nombre,
|
||||
'cantidad' => 1,
|
||||
'precio_unitario' => '10000.00',
|
||||
'total' => '10000.00',
|
||||
]);
|
||||
|
||||
$pendingCart = Cart::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => 'checkout',
|
||||
]);
|
||||
CartItem::query()->create([
|
||||
'cart_id' => $pendingCart->id,
|
||||
'catalog_item_id' => $catalogItem->id,
|
||||
'cantidad' => 4,
|
||||
]);
|
||||
$pendingPurchase = Purchase::query()->create([
|
||||
'cart_id' => $pendingCart->id,
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'total' => '40000.00',
|
||||
]);
|
||||
|
||||
$paidPurchase = Purchase::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '20000.00',
|
||||
]);
|
||||
PurchaseItem::query()->create([
|
||||
'compra_id' => $paidPurchase->id,
|
||||
'source_catalog_item_id' => $catalogItem->id,
|
||||
'item_nombre' => $catalogItem->nombre,
|
||||
'cantidad' => 2,
|
||||
'precio_unitario' => '10000.00',
|
||||
'total' => '20000.00',
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/sales?sort_by=id&sort_direction=asc')
|
||||
->assertOk()
|
||||
->assertJsonCount(3, 'data')
|
||||
->assertJsonPath('data.0.id', $createdPurchase->id)
|
||||
->assertJsonPath('data.0.quantity', 3)
|
||||
->assertJsonPath('data.1.id', $pendingPurchase->id)
|
||||
->assertJsonPath('data.1.quantity', 4)
|
||||
->assertJsonPath('data.2.id', $paidPurchase->id)
|
||||
->assertJsonPath('data.2.quantity', 2);
|
||||
}
|
||||
|
||||
public function test_authentication_is_required_to_read_a_sale_detail(): void
|
||||
{
|
||||
$this->getJson('/api/v1/adminapp/tenant/sales/1')->assertUnauthorized();
|
||||
|
||||
Reference in New Issue
Block a user