Files
saasshop/tests/Feature/AdminPlatformOrderIndexRowActivateSubscriptionButtonShouldDisableWhenRefundInconsistentTest.php

82 lines
2.8 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\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexRowActivateSubscriptionButtonShouldDisableWhenRefundInconsistentTest 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_row_activate_subscription_button_should_be_disabled_when_refund_inconsistent(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_index_row_sync_disable_refund_inconsistent_plan',
'name' => '平台订单列表行级同步订阅禁用(退款不一致)测试套餐',
'billing_cycle' => 'monthly',
'price' => 30,
'list_price' => 30,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 制造退款不一致payment_status=paid + refund_summary.total_amount >= paid + tol
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_INDEX_ROW_SYNC_DISABLE_REFUND_INCONS_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 30,
'paid_amount' => 30,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 30.01,
],
],
]);
$this->assertTrue($order->isRefundInconsistent());
$res = $this->get('/admin/platform-orders');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString($order->order_no, $html);
// 断言:该订单所在行的“同步订阅”按钮应被禁用(避免运营在列表页误触)
$pattern = '#/admin/platform-orders/' . $order->id . '/activate-subscription.*?<button[^>]*disabled#s';
$this->assertMatchesRegularExpression($pattern, $html);
// 并且仍应存在最短治理入口(退款:去追加退款记录)
$this->assertStringContainsString('#add-refund-receipt', $html);
}
}