修复BUG
This commit is contained in:
@@ -265,6 +265,37 @@ class CartTest extends ProcurementTestCase
|
||||
$this->getJson('/mini/cart')->assertStatus(401);
|
||||
}
|
||||
|
||||
/** 下单成功后自动清空购物车中已下单的商品(未下单商品保留) */
|
||||
public function test_place_order_clears_ordered_items_from_cart(): void
|
||||
{
|
||||
$level = CustomerLevelModel::factory()->create();
|
||||
$store = StoreModel::factory()->create(['level_id' => $level->id]);
|
||||
$p1 = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '5.00']);
|
||||
$p2 = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '3.00']);
|
||||
$this->actingAsMiniStore($store);
|
||||
|
||||
$this->postJson('/mini/cart', ['product_id' => $p1->id, 'quantity' => 2]);
|
||||
$this->postJson('/mini/cart', ['product_id' => $p2->id, 'quantity' => 1]);
|
||||
$this->assertSame(2, CartModel::where('store_id', $store->id)->count());
|
||||
|
||||
// 下单两个商品 → 购物车清空
|
||||
$this->postJson('/mini/order', ['items' => [
|
||||
['product_id' => $p1->id, 'quantity' => 2],
|
||||
['product_id' => $p2->id, 'quantity' => 1],
|
||||
]])->assertOk()->assertJsonPath('success', true);
|
||||
$this->assertSame(0, CartModel::where('store_id', $store->id)->count(), '下单后购物车应自动清空');
|
||||
|
||||
// 部分下单:仅清除已下单商品,未下单商品保留
|
||||
$this->postJson('/mini/cart', ['product_id' => $p1->id, 'quantity' => 2]);
|
||||
$this->postJson('/mini/cart', ['product_id' => $p2->id, 'quantity' => 1]);
|
||||
$this->postJson('/mini/order', ['items' => [['product_id' => $p1->id, 'quantity' => 2]]])
|
||||
->assertOk()->assertJsonPath('success', true);
|
||||
|
||||
$remaining = CartModel::where('store_id', $store->id)->get();
|
||||
$this->assertSame(1, $remaining->count(), '未下单商品应保留在购物车');
|
||||
$this->assertSame($p2->id, $remaining->first()->product_id);
|
||||
}
|
||||
|
||||
/** 跨门店列表隔离:B 店看不到 A 店的购物车 */
|
||||
public function test_cart_isolated_between_stores(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user