From 1c01d177c09bf5dfbbf7600653d841c4333344e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 16:01:09 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=9B=BArefund=5Finconsistent?= =?UTF-8?q?=E7=AD=9B=E9=80=89=EF=BC=9A=E9=AA=8C=E8=AF=81=20amounts.toleran?= =?UTF-8?q?ce=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 --- ...dInconsistentToleranceConfigFilterTest.php | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderRefundInconsistentToleranceConfigFilterTest.php diff --git a/tests/Feature/AdminPlatformOrderRefundInconsistentToleranceConfigFilterTest.php b/tests/Feature/AdminPlatformOrderRefundInconsistentToleranceConfigFilterTest.php new file mode 100644 index 0000000..2989fb7 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderRefundInconsistentToleranceConfigFilterTest.php @@ -0,0 +1,152 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_orders_page_refund_inconsistent_filter_respects_configured_tolerance(): void + { + $this->loginAsPlatformAdmin(); + + config(['saasshop.amounts.tolerance' => 0.05]); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_inconsistent_tol_filter_test', + 'name' => '退款不一致容差筛选测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // A:refunded,但只差 0.02(在 tol=0.05 内)=> 不应命中不一致筛选 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_INCONS_TOL_A', + '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, + ], + ], + ]); + + // B:refunded,差 0.10(超出 tol=0.05)=> 应命中 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_INCONS_TOL_B', + '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, + ], + ], + ]); + + // C:非 refunded,但只多 0.02(在 tol=0.05 内)=> 不应命中 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_INCONS_TOL_C', + '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, + ], + ], + ]); + + // D:非 refunded,多 0.06(超出 tol=0.05)=> 应命中 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_INCONS_TOL_D', + '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?refund_inconsistent=1') + ->assertOk() + ->assertDontSee('PO_REFUND_INCONS_TOL_A') + ->assertSee('PO_REFUND_INCONS_TOL_B') + ->assertDontSee('PO_REFUND_INCONS_TOL_C') + ->assertSee('PO_REFUND_INCONS_TOL_D'); + } +}