feat(plans): 空库一键初始化默认套餐(带护栏与测试)
This commit is contained in:
58
tests/Feature/AdminPlanSeedDefaultsTest.php
Normal file
58
tests/Feature/AdminPlanSeedDefaultsTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPlanSeedDefaultsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function loginAsPlatformAdmin(): void
|
||||
{
|
||||
$this->seed();
|
||||
|
||||
$this->post('/admin/login', [
|
||||
'email' => 'platform.admin@demo.local',
|
||||
'password' => 'Platform@123456',
|
||||
])->assertRedirect('/admin');
|
||||
}
|
||||
|
||||
public function test_platform_admin_can_seed_default_plans_when_empty(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
// 清空 seed 带来的默认套餐(测试口径:模拟空库)
|
||||
Plan::query()->delete();
|
||||
$this->assertSame(0, Plan::query()->count());
|
||||
|
||||
$this->post('/admin/plans/seed-defaults')
|
||||
->assertRedirect('/admin/plans');
|
||||
|
||||
$this->assertSame(2, Plan::query()->count());
|
||||
$this->assertNotNull(Plan::query()->where('code', 'starter_monthly')->first());
|
||||
$this->assertNotNull(Plan::query()->where('code', 'pro_yearly')->first());
|
||||
|
||||
$this->get('/admin/plans')
|
||||
->assertOk()
|
||||
->assertSee('基础版(月付)')
|
||||
->assertSee('专业版(年付)');
|
||||
}
|
||||
|
||||
public function test_seed_default_plans_is_blocked_when_plans_exist(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$this->assertTrue(Plan::query()->count() > 0);
|
||||
|
||||
$this->post('/admin/plans/seed-defaults')
|
||||
->assertRedirect();
|
||||
|
||||
// 不应新增到 2 条以上;且仍能打开列表
|
||||
$this->get('/admin/plans')
|
||||
->assertOk()
|
||||
->assertSee('套餐管理');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user