feat(platform-orders): 支持批量仅标记为已生效(待生效集合)
This commit is contained in:
139
tests/Feature/AdminPlatformOrderBatchMarkActivatedTest.php
Normal file
139
tests/Feature/AdminPlatformOrderBatchMarkActivatedTest.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?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 AdminPlatformOrderBatchMarkActivatedTest 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_platform_admin_can_batch_mark_activated_for_paid_pending_orders_in_filtered_scope(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'batch_mark_activated_plan',
|
||||
'name' => '批量生效测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$o1 = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_MARK_0001',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(10),
|
||||
'paid_at' => now()->subMinutes(5),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
$o2 = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_MARK_0002',
|
||||
'order_type' => 'renewal',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(9),
|
||||
'paid_at' => now()->subMinutes(4),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
// 不应被处理:未支付
|
||||
$o3 = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_MARK_0003',
|
||||
'order_type' => 'renewal',
|
||||
'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()->subMinutes(8),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
// scope=filtered 且要求 payment_status=paid + status=pending
|
||||
$this->post('/admin/platform-orders/batch-mark-activated', [
|
||||
'scope' => 'filtered',
|
||||
'payment_status' => 'paid',
|
||||
'status' => 'pending',
|
||||
'limit' => 50,
|
||||
])->assertRedirect();
|
||||
|
||||
$o1->refresh();
|
||||
$o2->refresh();
|
||||
$o3->refresh();
|
||||
|
||||
$this->assertSame('activated', $o1->status);
|
||||
$this->assertSame('activated', $o2->status);
|
||||
$this->assertSame('pending', $o3->status);
|
||||
|
||||
$audit1 = (array) (data_get($o1->meta, 'audit', []) ?? []);
|
||||
$this->assertNotEmpty($audit1);
|
||||
$this->assertSame('batch_mark_activated', (string) data_get(end($audit1), 'action'));
|
||||
}
|
||||
|
||||
public function test_batch_mark_activated_requires_paid_pending_filters_in_filtered_scope(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$this->post('/admin/platform-orders/batch-mark-activated', [
|
||||
'scope' => 'filtered',
|
||||
'payment_status' => 'paid',
|
||||
'status' => 'activated',
|
||||
'limit' => 50,
|
||||
])->assertRedirect();
|
||||
}
|
||||
|
||||
public function test_guest_cannot_batch_mark_activated(): void
|
||||
{
|
||||
$this->seed();
|
||||
|
||||
$this->post('/admin/platform-orders/batch-mark-activated', [
|
||||
'scope' => 'filtered',
|
||||
'payment_status' => 'paid',
|
||||
'status' => 'pending',
|
||||
'limit' => 50,
|
||||
])->assertRedirect('/admin/login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user