购物车悬浮
This commit is contained in:
@@ -265,6 +265,43 @@ class CartTest extends ProcurementTestCase
|
||||
$this->getJson('/mini/cart')->assertStatus(401);
|
||||
}
|
||||
|
||||
/** 悬浮球汇总:种数/总数量/总金额(下架商品不计入数量与金额但仍计种数) */
|
||||
public function test_cart_summary_endpoint(): 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->getJson('/mini/cart/summary')->assertOk()
|
||||
->assertJsonPath('data.total_count', 0)
|
||||
->assertJsonPath('data.total_quantity', '0.00')
|
||||
->assertJsonPath('data.total_amount', '0.00');
|
||||
|
||||
$this->postJson('/mini/cart', ['product_id' => $p1->id, 'quantity' => 2]);
|
||||
$this->postJson('/mini/cart', ['product_id' => $p2->id, 'quantity' => 1]);
|
||||
|
||||
$this->getJson('/mini/cart/summary')->assertOk()
|
||||
->assertJsonPath('data.total_count', 2)
|
||||
->assertJsonPath('data.total_quantity', '3.00')
|
||||
->assertJsonPath('data.total_amount', '13.00');
|
||||
|
||||
// 下架商品:数量/金额不计入(与购物车列表口径一致),种数仍计
|
||||
$p2->update(['status' => ProductModel::STATUS_OFF]);
|
||||
$this->getJson('/mini/cart/summary')->assertOk()
|
||||
->assertJsonPath('data.total_count', 2)
|
||||
->assertJsonPath('data.total_quantity', '2.00')
|
||||
->assertJsonPath('data.total_amount', '10.00');
|
||||
}
|
||||
|
||||
/** 未登录访问悬浮球汇总 → 401 */
|
||||
public function test_cart_summary_requires_login(): void
|
||||
{
|
||||
$this->getJson('/mini/cart/summary')->assertStatus(401);
|
||||
}
|
||||
|
||||
/** 下单成功后自动清空购物车中已下单的商品(未下单商品保留) */
|
||||
public function test_place_order_clears_ordered_items_from_cart(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user