From e9593757b7b9022bb9ed1fdb311db2b1c7cb1408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 12:20:41 +0800 Subject: [PATCH] test(billing): SOP branch to block BMPA when refund trail exists --- ...haseSopRefundExistsShouldBlockBmpaTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/Feature/AdminBillingClosedLoopNewPurchaseSopRefundExistsShouldBlockBmpaTest.php diff --git a/tests/Feature/AdminBillingClosedLoopNewPurchaseSopRefundExistsShouldBlockBmpaTest.php b/tests/Feature/AdminBillingClosedLoopNewPurchaseSopRefundExistsShouldBlockBmpaTest.php new file mode 100644 index 0000000..163ce15 --- /dev/null +++ b/tests/Feature/AdminBillingClosedLoopNewPurchaseSopRefundExistsShouldBlockBmpaTest.php @@ -0,0 +1,82 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_sop_new_purchase_refund_exists_should_block_bmpa(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'sop_new_purchase_refund_guard_monthly', + 'name' => 'SOP新购(退款阻断 BMPA)月付', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 1) 创建平台订单(新购) + $this->post('/admin/platform-orders', [ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_type' => 'new_purchase', + 'quantity' => 1, + 'discount_amount' => 0, + 'payment_channel' => 'bank_transfer', + 'remark' => 'SOP 新购(退款阻断 BMPA)', + ])->assertRedirect(); + + /** @var PlatformOrder $order */ + $order = PlatformOrder::query()->latest('id')->firstOrFail(); + + // 2) 构造“退款轨迹”但订单仍为 unpaid/pending(模拟脏数据/误操作场景) + $meta = (array) ($order->meta ?? []); + data_set($meta, 'refund_summary', [ + 'count' => 1, + 'total_amount' => 10.0, + ]); + $order->meta = $meta; + $order->save(); + + // 3) BMPA 必须阻断 + $res = $this->from('/admin/platform-orders/' . $order->id) + ->post('/admin/platform-orders/' . $order->id . '/mark-paid-and-activate'); + + $res->assertRedirect('/admin/platform-orders/' . $order->id); + $res->assertSessionHas('warning'); + + $order->refresh(); + $this->assertSame('unpaid', (string) $order->payment_status); + $this->assertSame('pending', (string) $order->status); + $this->assertNull($order->site_subscription_id); + } +}