From 6b21b28b93a4d442a04b04a121c13c1c23a2e3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 23:13:39 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=9C=AA=E6=94=AF=E4=BB=98=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=BF=BD=E5=8A=A0=E9=80=80=E6=AC=BE=E5=9B=9E=E6=89=A7?= =?UTF-8?q?=E4=B8=8D=E5=BA=94=E8=87=AA=E5=8A=A8=E6=8E=A8=E8=BF=9B=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ChangePaymentStatusWhenOrderUnpaidTest.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderAddRefundReceiptShouldNotChangePaymentStatusWhenOrderUnpaidTest.php diff --git a/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldNotChangePaymentStatusWhenOrderUnpaidTest.php b/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldNotChangePaymentStatusWhenOrderUnpaidTest.php new file mode 100644 index 0000000..cdff7ab --- /dev/null +++ b/tests/Feature/AdminPlatformOrderAddRefundReceiptShouldNotChangePaymentStatusWhenOrderUnpaidTest.php @@ -0,0 +1,77 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_add_refund_receipt_should_not_change_payment_status_when_order_is_unpaid(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_add_refund_receipt_unpaid_should_not_change_status', + 'name' => '追加退款回执不改变未支付状态测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_ADD_REFUND_RECEIPT_UNPAID_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' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [], + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/add-refund-receipt', [ + 'type' => 'refund', + 'channel' => 'offline', + 'amount' => 1, + 'refunded_at' => now()->format('Y-m-d H:i:s'), + 'note' => '未支付订单的退款留痕', + ]) + ->assertRedirect('/admin/platform-orders/' . $order->id . '#add-refund-receipt') + ->assertSessionHas('success'); + + $order->refresh(); + + // 口径:未支付订单追加退款回执仅留痕,不自动推进支付状态(避免出现未付却部分退款/已退款的脏状态)。 + $this->assertSame('unpaid', (string) $order->payment_status); + $this->assertNull($order->refunded_at); + + $this->assertSame(1, (int) data_get($order->meta, 'refund_summary.count')); + $this->assertSame(1.0, (float) data_get($order->meta, 'refund_summary.total_amount')); + } +}