PlatformOrder store: require subscription for renewal orders

This commit is contained in:
萝卜
2026-03-15 02:03:04 +00:00
parent aaf774edbf
commit bdea18c976
3 changed files with 64 additions and 4 deletions

View File

@@ -68,7 +68,8 @@ class AdminPlatformOrderCreateDefaultsPreselectedTest extends TestCase
// 预选 merchant/plan/order_type
$res->assertSee('<option value="' . $merchant->id . '" selected>', false);
$res->assertSee('<option value="' . $plan->id . '" selected>', false);
$res->assertSee('<option value="renewal" selected>', false);
// 兼容不同 Laravel 版本对 @selected 的渲染形式selected 或 selected="selected"
$res->assertSee('value="renewal" selected', false);
// 预填其它字段
$res->assertSee('name="site_subscription_id" value="' . $sub->id . '"', false);

View File

@@ -0,0 +1,54 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderStoreShouldRequireSubscriptionForRenewalTest 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_store_should_reject_renewal_order_when_site_subscription_id_missing(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_store_renewal_requires_sub_plan',
'name' => '续费必须绑定订阅测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->from('/admin/platform-orders/create')->post('/admin/platform-orders', [
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_type' => 'renewal',
'quantity' => 1,
'discount_amount' => 0,
'payment_channel' => 'offline',
'remark' => 'try renewal without sub',
// site_subscription_id 故意不传
]);
$res->assertStatus(302);
$res->assertSessionHasErrors('site_subscription_id');
}
}