批量删除
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\ProductModel;
|
||||
|
||||
/**
|
||||
* 商品批量删除(软删除):正常批量删除、空 ids 校验失败、无 delete 权限点拦截
|
||||
*/
|
||||
class ProductBatchDeleteTest extends ProcurementTestCase
|
||||
{
|
||||
/** 批量删除成功:选中商品软删除,未选中的保留 */
|
||||
public function test_batch_delete_soft_deletes_selected_products(): void
|
||||
{
|
||||
$this->actingAsSysUser();
|
||||
$ids = ProductModel::factory()->count(3)->create()->pluck('id')->all();
|
||||
$keep = ProductModel::factory()->create();
|
||||
|
||||
$this->deleteJson('/product/goods/batch', ['ids' => $ids])
|
||||
->assertOk()
|
||||
->assertJsonPath('success', true);
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$this->assertSoftDeleted('product', ['id' => $id]);
|
||||
}
|
||||
$this->assertDatabaseHas('product', ['id' => $keep->id, 'deleted_at' => null]);
|
||||
}
|
||||
|
||||
/** ids 为空数组 → 校验失败,不删除任何商品 */
|
||||
public function test_batch_delete_requires_non_empty_ids(): void
|
||||
{
|
||||
$this->actingAsSysUser();
|
||||
$product = ProductModel::factory()->create();
|
||||
|
||||
$this->deleteJson('/product/goods/batch', ['ids' => []])
|
||||
->assertOk()
|
||||
->assertJsonPath('success', false)
|
||||
->assertJsonPath('msg', '请选择要删除的商品');
|
||||
|
||||
$this->assertDatabaseHas('product', ['id' => $product->id, 'deleted_at' => null]);
|
||||
}
|
||||
|
||||
/** 无 product.goods.delete 权限点 → 拦截 */
|
||||
public function test_batch_delete_forbidden_without_permission(): void
|
||||
{
|
||||
// 先建占位用户:每个测试方法内首个系统用户自增 id=1,超管旁路会绕过 abilities 校验
|
||||
$this->actingAsSysUser();
|
||||
$this->actingAsSysUser(['product.goods.query']);
|
||||
|
||||
$product = ProductModel::factory()->create();
|
||||
|
||||
$this->deleteJson('/product/goods/batch', ['ids' => [$product->id]])
|
||||
->assertOk()
|
||||
->assertJsonPath('success', false)
|
||||
->assertJsonPath('msg', 'No Permission');
|
||||
|
||||
$this->assertDatabaseHas('product', ['id' => $product->id, 'deleted_at' => null]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user