fix(purchase): handle cancellation of expired purchases and update test cases
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\StockReservation;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Services\CheckoutService;
|
||||
@@ -714,11 +715,11 @@ class StorePurchaseTest extends TestCase
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
||||
->assertUnprocessable()
|
||||
->assertJsonPath('code', 'purchase.expired');
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_EXPIRED);
|
||||
}
|
||||
|
||||
public function test_an_overdue_purchase_cannot_be_cancelled_before_the_expiration_job_runs(): void
|
||||
public function test_leaving_an_overdue_purchase_expires_it_before_the_expiration_job_runs(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
@@ -728,20 +729,17 @@ class StorePurchaseTest extends TestCase
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
|
||||
->assertUnprocessable()
|
||||
->assertExactJson([
|
||||
'code' => 'stock_reservation.expired',
|
||||
'message' => __('api.cart.reservation_expired'),
|
||||
]);
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_EXPIRED);
|
||||
|
||||
$this->assertDatabaseHas('compras', [
|
||||
'id' => $purchase->id,
|
||||
'status' => Purchase::STATUS_CREATED,
|
||||
'status' => Purchase::STATUS_EXPIRED,
|
||||
'stock_reservation_id' => $purchase->stock_reservation_id,
|
||||
]);
|
||||
$this->assertDatabaseHas('stock_reservations', [
|
||||
'id' => $purchase->stock_reservation_id,
|
||||
'status' => 'active',
|
||||
'status' => StockReservation::STATUS_EXPIRED,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user