From 353b9347da7722b5f086b4023b1f8dd27751a727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 10:50:41 +0800 Subject: [PATCH] test(platform-orders): guard export ledger link on index rows --- ...inkShouldRenderWhenReceiptsPresentTest.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderIndexExportLedgerLinkShouldRenderWhenReceiptsPresentTest.php diff --git a/tests/Feature/AdminPlatformOrderIndexExportLedgerLinkShouldRenderWhenReceiptsPresentTest.php b/tests/Feature/AdminPlatformOrderIndexExportLedgerLinkShouldRenderWhenReceiptsPresentTest.php new file mode 100644 index 0000000..ff65331 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexExportLedgerLinkShouldRenderWhenReceiptsPresentTest.php @@ -0,0 +1,93 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_index_should_render_export_ledger_link_only_for_orders_with_receipt_or_refund_evidence(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'po_index_export_ledger_link_01', + 'name' => '平台订单列表导出对账明细入口测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $withEvidence = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_INDEX_LEDGER_EVIDENCE_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' => 10, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [ + 'payment_summary' => [ + 'count' => 1, + 'total_amount' => 10, + ], + ], + ]); + + $withoutEvidence = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_INDEX_LEDGER_NO_EVIDENCE_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' => 10, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [], + ]); + + $url = '/admin/platform-orders/' . $withEvidence->id . '/export-ledger?download=1&include_order_snapshot=1'; + + $res = $this->get('/admin/platform-orders'); + $res->assertOk(); + + $res->assertSee($url, false); + $res->assertSee('导出对账明细', false); + $res->assertSee('target="_blank"', false); + + $url2 = '/admin/platform-orders/' . $withoutEvidence->id . '/export-ledger?download=1&include_order_snapshot=1'; + $res->assertDontSee($url2, false); + } +}