From aee8633021c0af85f5d53f9ae7ef76b01b85efa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 10 Mar 2026 23:58:45 +0000 Subject: [PATCH] =?UTF-8?q?test(platform-orders):=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=AE=A2=E9=98=85=E5=8A=A8=E4=BD=9C=E8=A1=A5?= =?UTF-8?q?=E5=85=85=20refund=5Fstatus=20=E5=8F=A3=E5=BE=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8A=A4=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...scriptionsRefundStatusFilterFieldsTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundStatusFilterFieldsTest.php diff --git a/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundStatusFilterFieldsTest.php b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundStatusFilterFieldsTest.php new file mode 100644 index 0000000..bb00e0c --- /dev/null +++ b/tests/Feature/AdminPlatformOrderBatchActivateSubscriptionsRefundStatusFilterFieldsTest.php @@ -0,0 +1,103 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_batch_activate_subscriptions_filtered_scope_respects_refund_status_filter(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'batch_activate_subscriptions_refund_status_plan', + 'name' => '批量同步订阅(退款筛选口径)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // A:无退款,可同步 + $a = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_REFUND_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' => [], + ]); + + // B:有退款(refund_summary),仍满足“已支付+已生效+未同步”,但应被 refund_status=none 排除 + $b = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_BAS_REFUND_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' => 1.00, + ], + ], + ]); + + // 批量同步订阅:filtered scope 必须带 syncable_only=1;并附加 refund_status=none + $this->post('/admin/platform-orders/batch-activate-subscriptions', [ + 'scope' => 'filtered', + 'syncable_only' => '1', + 'refund_status' => 'none', + 'limit' => 50, + ])->assertRedirect(); + + $a->refresh(); + $b->refresh(); + + // A 应被同步(meta.subscription_activation.subscription_id 存在) + $this->assertNotNull(data_get($a->meta, 'subscription_activation.subscription_id')); + + // B 不应被同步 + $this->assertNull(data_get($b->meta, 'subscription_activation.subscription_id')); + } +}