feat(admin): 仪表盘收费工作台快捷治理入口显示计数
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?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 的定义是 paid + pending,其中包含 sync_failed 那一条,因此预期为 2
|
||||
$res->assertSee('待支付(1)');
|
||||
$res->assertSee('待生效(2)');
|
||||
$res->assertSee('同步失败(1)');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user