Files
saasshop/tests/Feature/AdminDashboardPaidNoReceiptCountShouldExcludeUnpaidOrdersTest.php

76 lines
2.2 KiB
PHP
Raw Permalink 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\Merchant;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
class AdminDashboardPaidNoReceiptCountShouldExcludeUnpaidOrdersTest 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_paid_no_receipt_count_should_exclude_unpaid_orders(): void
{
Cache::flush();
$this->loginAsPlatformAdmin();
// 清理 seed 中的订单数据,避免 seed 口径变化影响该用例
PlatformOrder::query()->delete();
$merchantId = (int) Merchant::query()->value('id');
// A已付 + 无回执(应计入)
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => null,
'order_no' => 'PO_DASH_PAID_NO_RECEIPT_CNT_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'paid',
'payable_amount' => 9,
'paid_amount' => 9,
'meta' => [],
]);
// B未付 + 无回执(不应计入)
PlatformOrder::query()->create([
'merchant_id' => $merchantId,
'plan_id' => null,
'site_subscription_id' => null,
'created_by_admin_id' => null,
'order_no' => 'PO_DASH_PAID_NO_RECEIPT_CNT_0002',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'payable_amount' => 9,
'paid_amount' => 0,
'meta' => [],
]);
Cache::flush();
$res = $this->get('/admin');
$res->assertOk();
// 只统计已付无回执
$res->assertSee('已付无回执1', false);
$res->assertDontSee('已付无回执2', false);
}
}