test(platform-orders): guard export ledger link on index rows

This commit is contained in:
萝卜
2026-03-17 10:50:41 +08:00
parent 5f775c1e45
commit 353b9347da

View File

@@ -0,0 +1,93 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexExportLedgerLinkShouldRenderWhenReceiptsPresentTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->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);
}
}