From c50ea26e5ae30592073ee0a41cc7f8bc68234e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 10 Mar 2026 16:14:53 +0000 Subject: [PATCH] =?UTF-8?q?test(platform-orders):=20=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E6=89=A7=E8=BF=BD=E5=8A=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminPlatformOrderPaymentReceiptTest.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderPaymentReceiptTest.php diff --git a/tests/Feature/AdminPlatformOrderPaymentReceiptTest.php b/tests/Feature/AdminPlatformOrderPaymentReceiptTest.php new file mode 100644 index 0000000..0035dd5 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderPaymentReceiptTest.php @@ -0,0 +1,114 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_admin_can_add_payment_receipt_meta(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'receipt_test', + '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_RECEIPT_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(), + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/add-payment-receipt', [ + 'type' => 'bank_transfer', + 'channel' => 'icbc', + 'amount' => 30, + 'paid_at' => now()->format('Y-m-d H:i:s'), + 'note' => '测试回执', + ])->assertRedirect(); + + $order->refresh(); + + $receipts = (array) data_get($order->meta, 'payment_receipts', []); + $this->assertCount(1, $receipts); + $this->assertSame('bank_transfer', data_get($receipts[0], 'type')); + $this->assertSame('icbc', data_get($receipts[0], 'channel')); + $this->assertSame(30.0, (float) data_get($receipts[0], 'amount')); + $this->assertSame('测试回执', data_get($receipts[0], 'note')); + $this->assertNotEmpty((string) data_get($receipts[0], 'created_at')); + $this->assertNotEmpty((string) data_get($receipts[0], 'admin_id')); + } + + public function test_guest_cannot_add_payment_receipt(): void + { + $this->seed(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'receipt_test_guest', + '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_RECEIPT_0002', + '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(), + ]); + + $this->post('/admin/platform-orders/' . $order->id . '/add-payment-receipt', [ + 'type' => 'bank_transfer', + 'amount' => 30, + ])->assertRedirect('/admin/login'); + } +}