Site subscriptions: add status toggle action on index

This commit is contained in:
萝卜
2026-03-14 23:34:31 +00:00
parent bfd8f7784c
commit 6c5705443d
4 changed files with 100 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminSiteSubscriptionSetStatusTest 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_set_subscription_status(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'status' => 'pending',
'source' => 'manual',
'subscription_no' => 'SUB_STATUS_TOGGLE_0001',
'plan_name' => '测试套餐',
'billing_cycle' => 'monthly',
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addDays(29),
]);
$this->post('/admin/site-subscriptions/' . $sub->id . '/set-status', [
'status' => 'activated',
])->assertRedirect();
$sub->refresh();
$this->assertSame('activated', $sub->status);
}
public function test_guest_cannot_set_subscription_status(): void
{
$this->seed();
$merchant = Merchant::query()->firstOrFail();
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'status' => 'pending',
'source' => 'manual',
'subscription_no' => 'SUB_STATUS_TOGGLE_GUEST_0001',
'plan_name' => '测试套餐',
'billing_cycle' => 'monthly',
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addDays(29),
]);
$this->post('/admin/site-subscriptions/' . $sub->id . '/set-status', [
'status' => 'activated',
])->assertRedirect('/admin/login');
}
}