Admin subscriptions: batch mark expired with safety guards
This commit is contained in:
@@ -54,7 +54,8 @@ class AdminSiteSubscriptionSyncFailedReasonLongDoesNotRenderKeywordLinkTest exte
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$longReason = str_repeat('错', 120);
|
||||
// 超过 config('saasshop.platform_orders.sync_error_keyword_link_max_len', 200)
|
||||
$longReason = str_repeat('错', 220);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\SiteSubscription;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminSiteSubscriptionsBatchMarkExpiredShouldBlockWhenNotExpiredScopeTest 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_batch_mark_expired_should_block_when_expiry_not_expired(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'sub_batch_mark_expired_block_scope_plan',
|
||||
'name' => '订阅批量标记过期阻断(scope)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 1,
|
||||
'list_price' => 1,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$sub = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_BATCH_EXPIRED_BLOCK_SCOPE_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 1,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->addDays(5),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$this->post('/admin/site-subscriptions/batch-mark-expired', [
|
||||
'expiry' => 'expiring_7d',
|
||||
'confirm' => 'YES',
|
||||
])->assertRedirect()->assertSessionHas('warning');
|
||||
|
||||
$sub->refresh();
|
||||
$this->assertSame('activated', (string) $sub->status);
|
||||
}
|
||||
|
||||
public function test_batch_mark_expired_should_block_when_confirm_missing(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'sub_batch_mark_expired_block_confirm_plan',
|
||||
'name' => '订阅批量标记过期阻断(confirm)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 1,
|
||||
'list_price' => 1,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$sub = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_BATCH_EXPIRED_BLOCK_CONFIRM_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 1,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->subDays(1),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$this->post('/admin/site-subscriptions/batch-mark-expired', [
|
||||
'expiry' => 'expired',
|
||||
'confirm' => '',
|
||||
])->assertRedirect()->assertSessionHas('warning');
|
||||
|
||||
$sub->refresh();
|
||||
$this->assertSame('activated', (string) $sub->status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\SiteSubscription;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminSiteSubscriptionsBatchMarkExpiredShouldMarkExpiredOnlyWhenEndsAtPastTest 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_batch_mark_expired_should_only_update_subscriptions_with_ends_at_past(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'sub_batch_mark_expired_success_plan',
|
||||
'name' => '订阅批量标记过期(成功)测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 1,
|
||||
'list_price' => 1,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$expiredA = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_BATCH_EXPIRED_OK_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 1,
|
||||
'starts_at' => now()->subDays(40),
|
||||
'ends_at' => now()->subDays(1),
|
||||
'activated_at' => now()->subDays(40),
|
||||
]);
|
||||
|
||||
$expiredAlready = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'expired',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_BATCH_EXPIRED_ALREADY_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 1,
|
||||
'starts_at' => now()->subDays(70),
|
||||
'ends_at' => now()->subDays(10),
|
||||
'activated_at' => now()->subDays(70),
|
||||
]);
|
||||
|
||||
$notExpired = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_BATCH_EXPIRED_SKIP_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'amount' => 1,
|
||||
'starts_at' => now()->subDays(5),
|
||||
'ends_at' => now()->addDays(5),
|
||||
'activated_at' => now()->subDays(5),
|
||||
]);
|
||||
|
||||
$this->post('/admin/site-subscriptions/batch-mark-expired', [
|
||||
'expiry' => 'expired',
|
||||
'confirm' => 'YES',
|
||||
])->assertRedirect()->assertSessionHas('success');
|
||||
|
||||
$expiredA->refresh();
|
||||
$expiredAlready->refresh();
|
||||
$notExpired->refresh();
|
||||
|
||||
$this->assertSame('expired', (string) $expiredA->status);
|
||||
$this->assertSame('expired', (string) $expiredAlready->status);
|
||||
$this->assertSame('activated', (string) $notExpired->status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user