test: 订单详情BMPA按钮在回执差额时禁用护栏

This commit is contained in:
萝卜
2026-03-14 00:06:42 +00:00
parent 807cd159dc
commit bd3d98de57

View File

@@ -0,0 +1,86 @@
<?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 AdminPlatformOrderShowMarkPaidAndActivateButtonDisabledWhenReceiptMismatchTest 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_paid_and_activate_button_should_be_disabled_when_receipt_total_mismatched(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_disable_bmpa_receipt_mismatch_plan',
'name' => '订单详情禁用BMPA-回执差额测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// payable=10但回执总额=9且 >0会命中 markPaidBlockedByReceiptMismatch
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_SHOW_DISABLE_BMPA_RCPT_MIS_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [
'payment_receipts' => [
[
'type' => 'bank_transfer',
'channel' => 'offline',
'amount' => 9,
'paid_at' => now()->toDateTimeString(),
'note' => 'test-pay',
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
'payment_summary' => [
'count' => 1,
'total_amount' => 9,
'last_at' => now()->toDateTimeString(),
'last_amount' => 9,
'last_channel' => 'offline',
],
],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
$res->assertSee('action="/admin/platform-orders/' . $order->id . '/mark-paid-and-activate"', false);
$res->assertSee('标记支付并生效', false);
$res->assertSee('disabled', false);
$res->assertSee('回执总额与订单金额不一致', false);
}
}