批量同步订阅:refund_inconsistent 筛选口径测试护栏
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?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 AdminPlatformOrderBatchActivateSubscriptionsRefundInconsistentFilterFieldsTest 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_activate_subscriptions_filtered_scope_respects_refund_inconsistent_filter(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'batch_activate_subscriptions_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_BAS_REFUND_INCONS_A',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'activated',
|
||||
'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(),
|
||||
'activated_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_BAS_REFUND_INCONS_B',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'activated',
|
||||
'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(),
|
||||
'activated_at' => now(),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
// 批量同步订阅:filtered scope 必须带 syncable_only=1;并附加 refund_inconsistent=1
|
||||
$this->post('/admin/platform-orders/batch-activate-subscriptions', [
|
||||
'scope' => 'filtered',
|
||||
'syncable_only' => '1',
|
||||
'refund_inconsistent' => '1',
|
||||
'limit' => 50,
|
||||
])->assertRedirect();
|
||||
|
||||
$a->refresh();
|
||||
$b->refresh();
|
||||
|
||||
// A 应被同步(meta.subscription_activation.subscription_id 存在)
|
||||
$this->assertNotNull(data_get($a->meta, 'subscription_activation.subscription_id'));
|
||||
|
||||
// B 不应被同步
|
||||
$this->assertNull(data_get($b->meta, 'subscription_activation.subscription_id'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user