governance: 仅标记为已生效对齐对账/退款安全阀并补齐护栏测试

This commit is contained in:
萝卜
2026-03-18 00:27:18 +08:00
parent decd653ad8
commit 6a3b2f495e
3 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?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 AdminPlatformOrderMarkActivatedShouldBlockWhenReconcileMismatchTest 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_mark_activated_should_be_blocked_when_reconcile_mismatch(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_mark_activated_guard_reconcile_mismatch_plan',
'name' => '仅标记生效阻断(对账不一致)测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_MARK_ACTIVATED_GUARD_RECON_MISMATCH_0001',
'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(10),
'paid_at' => now()->subMinutes(5),
'meta' => [
// 存在回执证据,但与 paid_amount 不一致 => isReconcileMismatch=true
'payment_summary' => [
'count' => 1,
'total_amount' => 1.00,
],
],
]);
$this->assertTrue($order->isReconcileMismatch());
$res = $this->from('/admin/platform-orders/' . $order->id)
->post('/admin/platform-orders/' . $order->id . '/mark-activated');
$res->assertRedirect();
$res->assertSessionHas('warning');
$order->refresh();
$this->assertSame('pending', (string) $order->status);
$this->assertSame('paid', (string) $order->payment_status);
}
}

View File

@@ -0,0 +1,76 @@
<?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 AdminPlatformOrderMarkActivatedShouldBlockWhenRefundExistsTest 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_mark_activated_should_be_blocked_when_refund_exists(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_mark_activated_guard_refund_exists_plan',
'name' => '仅标记生效阻断(存在退款轨迹)测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_MARK_ACTIVATED_GUARD_REFUND_EXISTS_0001',
'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(10),
'paid_at' => now()->subMinutes(5),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 1.00,
],
],
]);
$this->assertGreaterThan(0, (float) $order->refundTotal());
$res = $this->from('/admin/platform-orders/' . $order->id)
->post('/admin/platform-orders/' . $order->id . '/mark-activated');
$res->assertRedirect();
$res->assertSessionHas('warning');
$order->refresh();
$this->assertSame('pending', (string) $order->status);
$this->assertSame('paid', (string) $order->payment_status);
}
}