From fea5bb33b4eeb230622736d85403819916f8ff3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 08:08:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=AE=A2=E5=8D=95=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=B7=A5=E5=85=B7=EF=BC=9A=E9=80=80=E6=AC=BE=E7=AD=9B?= =?UTF-8?q?=E9=80=89=E5=AD=97=E6=AE=B5=E9=80=8F=E4=BC=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8A=A4=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SyncErrorsRefundStatusFilterFieldsTest.php | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderClearSyncErrorsRefundStatusFilterFieldsTest.php diff --git a/tests/Feature/AdminPlatformOrderClearSyncErrorsRefundStatusFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderClearSyncErrorsRefundStatusFilterFieldsTest.php new file mode 100644 index 0000000..f7ac07f --- /dev/null +++ b/tests/Feature/AdminPlatformOrderClearSyncErrorsRefundStatusFilterFieldsTest.php @@ -0,0 +1,112 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_clear_sync_errors_filtered_scope_respects_refund_status_filter_fields(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'clear_sync_errors_refund_status_filter_fields_test', + 'name' => '清理失败标记退款筛选字段测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 1, + 'list_price' => 1, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 无退款 + 有失败标记:应被 refund_status=none 命中并清理 + $noRefund = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_CLEAR_SYNC_ERRORS_REFUND_NONE_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' => 1, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'subscription_activation_error' => [ + 'message' => '模拟失败原因NONE', + 'at' => now()->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + // 有退款 + 有失败标记:不应被 refund_status=none 的清理误命中 + $hasRefund = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_CLEAR_SYNC_ERRORS_REFUND_HAS_0002', + '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' => 1, + 'paid_amount' => 1, + 'placed_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 0.50, + ], + 'subscription_activation_error' => [ + 'message' => '模拟失败原因HAS', + 'at' => now()->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ]); + + // 访问列表页:确保清理失败标记表单透传 refund_status + $page = $this->get('/admin/platform-orders?refund_status=none'); + $page->assertOk(); + $page->assertSee('name="refund_status"', false); + $page->assertSee('value="none"', false); + + // 执行清理(filtered scope) + $res = $this->post('/admin/platform-orders/clear-sync-errors', [ + 'scope' => 'filtered', + 'refund_status' => 'none', + ]); + $res->assertRedirect(); + + $noRefund->refresh(); + $hasRefund->refresh(); + + $this->assertEmpty(data_get($noRefund->meta, 'subscription_activation_error')); + $this->assertNotEmpty(data_get($hasRefund->meta, 'subscription_activation_error.message')); + } +}