platform orders: batch mark activated guard renewal missing subscription

This commit is contained in:
萝卜
2026-03-15 06:39:22 +00:00
parent efc2a8a423
commit 9afe8c135d
3 changed files with 136 additions and 4 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderBatchMarkActivatedRenewalMissingSubscriptionShouldSkipTest 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_activated_should_skip_renewal_orders_missing_subscription_and_write_error_meta(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'batch_mark_activated_renewal_missing_sub_plan',
'name' => '批量仅标记生效跳过(续费缺订阅)测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$bad = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_MARK_ACT_SKIP_RENEW_NO_SUB_0001',
'order_type' => 'renewal',
'status' => 'pending',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now()->subMinutes(10),
'paid_at' => now()->subMinutes(5),
'meta' => [],
]);
$ok = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_MARK_ACT_SKIP_OK_0002',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now()->subMinutes(9),
'paid_at' => now()->subMinutes(4),
'meta' => [],
]);
$res = $this->post('/admin/platform-orders/batch-mark-activated', [
'scope' => 'filtered',
'payment_status' => 'paid',
'status' => 'pending',
'limit' => 50,
]);
$res->assertRedirect()->assertSessionHas('success');
$bad->refresh();
$ok->refresh();
$this->assertSame('pending', $bad->status);
$this->assertSame('activated', $ok->status);
$this->assertNotEmpty(data_get($bad->meta, 'batch_mark_activated_error.message'));
$msg = (string) $res->getSession()->get('success');
$this->assertStringContainsString('失败', $msg);
$this->assertStringContainsString('失败原因Top', $msg);
$this->assertStringContainsString('续费单未绑定订阅', $msg);
}
}

View File

@@ -42,7 +42,7 @@ class AdminPlatformOrderBatchMarkActivatedTest extends TestCase
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_MARK_0001',
'order_type' => 'renewal',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'plan_name' => $plan->name,
@@ -60,7 +60,7 @@ class AdminPlatformOrderBatchMarkActivatedTest extends TestCase
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_MARK_0002',
'order_type' => 'renewal',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'plan_name' => $plan->name,
@@ -79,7 +79,7 @@ class AdminPlatformOrderBatchMarkActivatedTest extends TestCase
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_MARK_0003',
'order_type' => 'renewal',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,