Files
saasshop/tests/Feature/AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest.php

95 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature;
use App\Models\Admin;
use App\Models\Merchant;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
class AdminDashboardBillingWorkbenchQuickLinksShouldShowCountsTest 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_dashboard_billing_workbench_quick_links_should_show_counts(): void
{
Cache::flush();
$this->loginAsPlatformAdmin();
$merchantId = (int) Merchant::query()->value('id');
$platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id');
// 构造三类集合:待支付 / 待生效 / 同步失败
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_DASHBOARD_UNPAID_PENDING',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'payable_amount' => 9,
'paid_amount' => 0,
]);
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_DASHBOARD_PAID_PENDING',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 9,
'paid_amount' => 9,
]);
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => $platformAdminId ?: null,
'order_no' => 'PO_DASHBOARD_SYNC_FAILED',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 9,
'paid_amount' => 9,
'meta' => [
'subscription_activation_error' => [
'message' => 'sync failed',
],
],
]);
Cache::flush();
// Debug确保我们构造的数据在 DB 里
$this->assertSame(1, PlatformOrder::query()->where('payment_status', 'unpaid')->where('status', 'pending')->count());
$this->assertSame(2, PlatformOrder::query()->where('payment_status', 'paid')->where('status', 'pending')->count());
$res = $this->get('/admin');
$res->assertOk();
// 待生效口径paid + pending但排除“同步失败”失败应在同步失败集合处理
$res->assertSee('待支付1');
$res->assertSee('待生效1');
$res->assertSee('同步失败1');
}
}