feat(platform-orders): queue batch activate subscriptions job
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\BatchActivateSubscriptionsJob;
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlatformOrder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPlatformOrderBatchActivateSubscriptionsShouldDispatchJobTest 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_batch_activate_subscriptions_should_dispatch_job_and_not_run_inline(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
Queue::fake();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'batch_activate_dispatch_job_plan',
|
||||
'name' => '批量同步订阅投递队列测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$syncable = PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_BATCH_DISPATCH_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' => 10,
|
||||
'paid_amount' => 10,
|
||||
'placed_at' => now()->subMinutes(10),
|
||||
'paid_at' => now()->subMinutes(9),
|
||||
'activated_at' => now()->subMinutes(8),
|
||||
]);
|
||||
|
||||
$this->post('/admin/platform-orders/batch-activate-subscriptions', [
|
||||
'scope' => 'filtered',
|
||||
'syncable_only' => '1',
|
||||
'limit' => 50,
|
||||
])->assertRedirect();
|
||||
|
||||
Queue::assertPushed(BatchActivateSubscriptionsJob::class, function (BatchActivateSubscriptionsJob $job) use ($syncable) {
|
||||
return in_array($syncable->id, $job->orderIds, true)
|
||||
&& $job->scope === 'filtered'
|
||||
&& $job->limit === 50;
|
||||
});
|
||||
|
||||
// 不应在请求内就完成同步(因为我们已队列化);因此 site_subscription_id 仍应为空
|
||||
$syncable->refresh();
|
||||
$this->assertNull($syncable->site_subscription_id);
|
||||
$this->assertEmpty(data_get($syncable->meta, 'subscription_activation'));
|
||||
}
|
||||
}
|
||||
@@ -168,19 +168,10 @@ class AdminPlatformOrderBatchActivateSubscriptionsTest extends TestCase
|
||||
|
||||
$res->assertRedirect()->assertSessionHas('success');
|
||||
|
||||
$ok->refresh();
|
||||
$bad->refresh();
|
||||
|
||||
$this->assertNotNull($ok->site_subscription_id);
|
||||
$this->assertNotEmpty(data_get($ok->meta, 'subscription_activation.subscription_id'));
|
||||
|
||||
$this->assertNotEmpty(data_get($bad->meta, 'subscription_activation_error.message'));
|
||||
$this->assertNotEmpty(data_get($bad->meta, 'subscription_activation_error.at'));
|
||||
|
||||
// 批量结果摘要应包含失败原因Top
|
||||
// 队列化后:请求内不会立即跑完,不应强行断言订单已同步/失败原因已落库。
|
||||
// 这里仅锁定“已提交到队列”的口径;具体成功/失败应由队列 worker 执行。
|
||||
$msg = (string) $res->getSession()->get('success');
|
||||
$this->assertStringContainsString('失败原因Top', $msg);
|
||||
$this->assertStringContainsString('模拟失败:订阅同步异常', $msg);
|
||||
$this->assertStringContainsString('任务已提交到队列', $msg);
|
||||
}
|
||||
|
||||
public function test_platform_admin_batch_activate_respects_limit(): void
|
||||
|
||||
Reference in New Issue
Block a user