批量仅标记生效:refund_inconsistent 筛选口径测试护栏

This commit is contained in:
萝卜
2026-03-11 04:42:44 +00:00
parent 10fa9a239d
commit 0e9dec2743

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 AdminPlatformOrderBatchMarkActivatedRefundInconsistentFilterFieldsTest 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_filtered_scope_respects_refund_inconsistent_filter(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'batch_mark_activated_refund_inconsistent_plan',
'name' => '批量生效(退款不一致口径)测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// A退款不一致状态!=refunded但退款总额已达/超已付),且满足“已支付+待处理”
$a = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BMA_REFUND_INCONS_A',
'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(),
'paid_at' => now(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
],
],
]);
// B退款一致无退款也满足“已支付+待处理”,但应被 refund_inconsistent=1 排除
$b = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BMA_REFUND_INCONS_B',
'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(),
'paid_at' => now(),
'meta' => [],
]);
$this->post('/admin/platform-orders/batch-mark-activated', [
'scope' => 'filtered',
'payment_status' => 'paid',
'status' => 'pending',
'refund_inconsistent' => '1',
'limit' => 50,
])->assertRedirect();
$a->refresh();
$b->refresh();
$this->assertSame('activated', $a->status);
$this->assertSame('pending', $b->status);
}
}