From 23bec0c2dca2ac5557318afc99d030f4c40ca963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 16:19:04 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=9B=BA=E9=80=80=E6=AC=BE=E6=B2=BB?= =?UTF-8?q?=E7=90=86=E5=8C=BA=E5=9D=97=EF=BC=9A=E9=AA=8C=E8=AF=81=20amount?= =?UTF-8?q?s.tolerance=20=E9=85=8D=E7=BD=AE=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...howRefundGovernanceToleranceConfigTest.php | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderShowRefundGovernanceToleranceConfigTest.php diff --git a/tests/Feature/AdminPlatformOrderShowRefundGovernanceToleranceConfigTest.php b/tests/Feature/AdminPlatformOrderShowRefundGovernanceToleranceConfigTest.php new file mode 100644 index 0000000..460adc0 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderShowRefundGovernanceToleranceConfigTest.php @@ -0,0 +1,180 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_refund_governance_block_respects_configured_tolerance_for_non_refunded_orders(): void + { + $this->loginAsPlatformAdmin(); + + config(['saasshop.amounts.tolerance' => 0.05]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_gov_tol_cfg_01', + 'name' => '退款治理区块容差配置测试', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // A:非 refunded,但退款=已付+0.02(在 tol=0.05 内)=> 不应出现治理区块 + $orderA = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_GOV_TOL_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.02, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $orderA->id) + ->assertOk() + ->assertDontSee('退款状态治理'); + + // B:非 refunded,但退款=已付+0.06(超出 tol=0.05)=> 应出现治理区块 + $orderB = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_GOV_TOL_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' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 10.06, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $orderB->id) + ->assertOk() + ->assertSee('退款状态治理'); + } + + public function test_refund_governance_block_respects_configured_tolerance_for_refunded_orders(): void + { + $this->loginAsPlatformAdmin(); + + config(['saasshop.amounts.tolerance' => 0.05]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_gov_tol_cfg_02', + 'name' => '退款治理区块容差配置测试2', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // C:refunded,但只差 0.02(在 tol=0.05 内)=> 不应出现治理区块 + $orderC = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_GOV_TOL_C', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'refunded', + '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(), + 'refunded_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 9.98, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $orderC->id) + ->assertOk() + ->assertDontSee('退款状态治理'); + + // D:refunded,但差 0.10(超出 tol=0.05)=> 应出现治理区块 + $orderD = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_GOV_TOL_D', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'refunded', + '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(), + 'refunded_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 9.90, + ], + ], + ]); + + $this->get('/admin/platform-orders/' . $orderD->id) + ->assertOk() + ->assertSee('退款状态治理'); + } +}