88 lines
2.8 KiB
PHP
88 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Merchant;
|
|
use App\Models\Plan;
|
|
use App\Models\PlatformOrder;
|
|
use App\Models\SiteSubscription;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdminPlatformOrderAttachSubscriptionShouldWorkTest 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_attach_subscription_should_bind_subscription_for_renewal_missing_subscription_order(): void
|
|
{
|
|
$this->loginAsPlatformAdmin();
|
|
|
|
$merchant = Merchant::query()->firstOrFail();
|
|
|
|
$plan = Plan::query()->create([
|
|
'code' => 'po_attach_sub_plan',
|
|
'name' => '绑定订阅测试套餐',
|
|
'billing_cycle' => 'monthly',
|
|
'price' => 10,
|
|
'list_price' => 10,
|
|
'status' => 'active',
|
|
'sort' => 10,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$sub = SiteSubscription::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'status' => 'active',
|
|
'source' => 'manual',
|
|
'subscription_no' => 'SS_ATTACH_SUB_0001',
|
|
'plan_name' => $plan->name,
|
|
'billing_cycle' => $plan->billing_cycle,
|
|
'period_months' => 1,
|
|
'amount' => 10,
|
|
'starts_at' => now()->subDays(1),
|
|
'ends_at' => now()->addDays(10),
|
|
'snapshot' => [],
|
|
'meta' => [],
|
|
]);
|
|
|
|
$order = PlatformOrder::query()->create([
|
|
'merchant_id' => $merchant->id,
|
|
'plan_id' => $plan->id,
|
|
'order_no' => 'PO_ATTACH_SUB_0001',
|
|
'order_type' => 'renewal',
|
|
'site_subscription_id' => null,
|
|
'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(10),
|
|
'meta' => [],
|
|
]);
|
|
|
|
$this->post('/admin/platform-orders/' . $order->id . '/attach-subscription', [
|
|
'site_subscription_id' => $sub->id,
|
|
])->assertRedirect();
|
|
|
|
$order->refresh();
|
|
|
|
$this->assertSame($sub->id, (int) $order->site_subscription_id);
|
|
$this->assertSame('attach_subscription', (string) data_get($order->meta, 'audit.0.action'));
|
|
$this->assertSame($sub->id, (int) data_get($order->meta, 'audit.0.subscription_id'));
|
|
}
|
|
}
|