diff --git a/tests/Feature/Cart/CartControllerTest.php b/tests/Feature/Cart/CartControllerTest.php index 38a75af..3534d73 100644 --- a/tests/Feature/Cart/CartControllerTest.php +++ b/tests/Feature/Cart/CartControllerTest.php @@ -227,7 +227,7 @@ class CartControllerTest extends TestCase $this->assertDatabaseHas('carrito_items', ['id' => $cartItemId]); $this->assertDatabaseHas('carritos', [ 'id' => $cartId, - 'status' => 'active', + 'status' => Cart::STATUS_EXPIRED, 'current_stock_reservation_id' => $reservationId, 'deleted_at' => null, ]); @@ -241,6 +241,11 @@ class CartControllerTest extends TestCase 'quantity' => 2, ]); + $this->getJson('/api/tenants/acme/cart') + ->assertOk() + ->assertJsonPath('data.id', $cartId) + ->assertJsonPath('data.status', Cart::STATUS_EXPIRED); + $this->postJson('/api/tenants/acme/cart/items', [ 'catalog_item_id' => $item->id, 'cantidad' => 1, @@ -262,12 +267,12 @@ class CartControllerTest extends TestCase $this->assertNotSame($cartId, $newCartId); $this->assertDatabaseHas('carritos', [ 'id' => $cartId, - 'status' => 'abandoned', + 'status' => Cart::STATUS_ABANDONED, 'current_stock_reservation_id' => $reservationId, ]); $this->assertDatabaseHas('carritos', [ 'id' => $newCartId, - 'status' => 'active', + 'status' => Cart::STATUS_ACTIVE, 'current_stock_reservation_id' => null, ]); diff --git a/tests/Feature/Purchase/StorePurchaseTest.php b/tests/Feature/Purchase/StorePurchaseTest.php index 5ea8732..054221d 100644 --- a/tests/Feature/Purchase/StorePurchaseTest.php +++ b/tests/Feature/Purchase/StorePurchaseTest.php @@ -668,7 +668,7 @@ class StorePurchaseTest extends TestCase $this->assertSame(3, $remaining); } - public function test_it_expires_the_purchase_without_mutating_the_active_cart(): void + public function test_it_expires_the_purchase_and_preserves_the_expired_cart_items(): void { $this->createTenant('sonder', 'Sonder', 'sonder.com.ar'); $user = User::factory()->create(); @@ -694,13 +694,24 @@ class StorePurchaseTest extends TestCase $this->assertDatabaseHas('carritos', [ 'id' => $activeCart->id, 'user_id' => $user->id, - 'status' => 'active', + 'status' => Cart::STATUS_EXPIRED, 'current_purchase_id' => null, + 'current_stock_reservation_id' => $purchase->stock_reservation_id, 'deleted_at' => null, ]); $this->assertPurchaseReservation($purchase->id, $variant->inventory_id, 3, 'expired'); $this->assertSame(1, $activeCart->items()->count()); + $this->actingAs($user, 'sanctum') + ->postJson('/api/tenants/sonder/compras/start-checkout', [ + 'cart_id' => $activeCart->id, + ]) + ->assertUnprocessable() + ->assertExactJson([ + 'code' => 'stock_reservation.expired', + 'message' => __('api.cart.reservation_expired'), + ]); + $this->actingAs($user, 'sanctum') ->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel") ->assertUnprocessable() @@ -1024,7 +1035,7 @@ class StorePurchaseTest extends TestCase ]); } - public function test_it_expires_an_abandoned_purchase_without_mutating_its_active_cart(): void + public function test_it_expires_a_purchase_and_its_associated_cart(): void { $this->createTenant('sonder', 'Sonder', 'sonder.com.ar'); $user = User::factory()->create(); @@ -1066,7 +1077,9 @@ class StorePurchaseTest extends TestCase $this->assertDatabaseHas('carritos', [ 'id' => $activeCart->id, 'user_id' => $user->id, - 'status' => 'active', + 'status' => Cart::STATUS_EXPIRED, + 'current_purchase_id' => null, + 'current_stock_reservation_id' => $purchase->stock_reservation_id, 'deleted_at' => null, ]); $this->assertSame(1, $activeCart->items()->count());