feat(purchase): restore in-review transfer lifecycle

This commit is contained in:
2026-08-21 16:15:55 -03:00
parent dc0fbe06b8
commit 5548fe8511
11 changed files with 130 additions and 14 deletions

View File

@@ -51,8 +51,9 @@ class AdminAppSaleFormControllerTest extends TestCase
->assertJsonPath('data.statuses.0.code', Purchase::STATUS_CREATED)
->assertJsonPath('data.statuses.0.name', 'Creada')
->assertJsonPath('data.statuses.1.code', Purchase::STATUS_PENDING_PAYMENT)
->assertJsonPath('data.statuses.2.code', Purchase::STATUS_PAID)
->assertJsonPath('data.statuses.5.code', Purchase::STATUS_EXPIRED);
->assertJsonPath('data.statuses.2.code', Purchase::STATUS_IN_REVIEW)
->assertJsonPath('data.statuses.3.code', Purchase::STATUS_PAID)
->assertJsonPath('data.statuses.6.code', Purchase::STATUS_EXPIRED);
}
public function test_a_customer_cannot_get_the_sale_form(): void

View File

@@ -838,7 +838,7 @@ class StorePurchaseTest extends TestCase
]);
}
public function test_it_keeps_a_submitted_purchase_pending_payment_idempotently(): void
public function test_it_moves_a_submitted_purchase_to_review_idempotently(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
@@ -856,24 +856,66 @@ class StorePurchaseTest extends TestCase
$this->actingAs($user, 'sanctum')
->postJson($url)
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT)
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW)
->assertJsonPath('data.expires_at', null);
$this->assertDatabaseHas('compras', [
'id' => $purchase->id,
'status' => Purchase::STATUS_PENDING_PAYMENT,
'status' => Purchase::STATUS_IN_REVIEW,
'expires_at' => null,
]);
$this->actingAs($user, 'sanctum')
->postJson($url)
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT);
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/complete")
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT);
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/payment-intent", [
'method' => 'qr',
])
->assertUnprocessable()
->assertJsonValidationErrors('purchase');
$this->assertDatabaseHas('compras', [
'id' => $purchase->id,
'status' => Purchase::STATUS_IN_REVIEW,
'payment_method' => 'transfer',
]);
$sourceCartId = $purchase->cart_id;
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
$this->assertDatabaseHas('compras', [
'id' => $purchase->id,
'status' => Purchase::STATUS_IN_REVIEW,
]);
$this->assertDatabaseHas('carritos', [
'id' => $sourceCartId,
'status' => 'checkout',
'current_purchase_id' => $purchase->id,
'deleted_at' => null,
]);
$this->assertDatabaseHas('carritos', [
'tenant_codigo' => 'sonder',
'user_id' => $user->id,
'status' => 'active',
'current_purchase_id' => null,
'deleted_at' => null,
]);
$this->assertDatabaseHas('stock_reservations', [
'purchase_id' => $purchase->id,
'status' => 'active',
]);
}
public function test_it_rejects_review_for_a_purchase_that_is_not_awaiting_payment(): void

View File

@@ -16,6 +16,7 @@ class SaleFormServiceTest extends TestCase
$this->assertSame([
'Creada',
'Esperando pago',
'En revisión',
'Confirmada',
'Cancelada',
'Rechazada',