feat(admin): site subscription show page with related platform orders
This commit is contained in:
119
tests/Feature/AdminSiteSubscriptionShowTest.php
Normal file
119
tests/Feature/AdminSiteSubscriptionShowTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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 AdminSiteSubscriptionShowTest 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_open_site_subscription_show_page(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'sub_show_test',
|
||||
'name' => '订阅详情测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 88,
|
||||
'list_price' => 88,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$sub = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_SHOW_0001',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'amount' => 88,
|
||||
'starts_at' => now()->subDays(2),
|
||||
'ends_at' => now()->addDays(20),
|
||||
'activated_at' => now()->subDays(2),
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'site_subscription_id' => $sub->id,
|
||||
'created_by_admin_id' => 1,
|
||||
'order_no' => 'PO_SUB_SHOW_0001',
|
||||
'order_type' => 'subscription',
|
||||
'status' => 'activated',
|
||||
'payment_status' => 'paid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'list_amount' => 88,
|
||||
'discount_amount' => 0,
|
||||
'payable_amount' => 88,
|
||||
'paid_amount' => 88,
|
||||
'placed_at' => now()->subDay(),
|
||||
'paid_at' => now()->subDay(),
|
||||
'activated_at' => now()->subDay(),
|
||||
'meta' => [
|
||||
'subscription_activation' => [
|
||||
'subscription_id' => $sub->id,
|
||||
'synced_at' => now()->subDay()->toDateTimeString(),
|
||||
'admin_id' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->get('/admin/site-subscriptions/' . $sub->id)
|
||||
->assertOk()
|
||||
->assertSee('订阅详情')
|
||||
->assertSee('SUB_SHOW_0001')
|
||||
->assertSee('关联平台订单')
|
||||
->assertSee('PO_SUB_SHOW_0001');
|
||||
}
|
||||
|
||||
public function test_guest_cannot_open_site_subscription_show_page(): void
|
||||
{
|
||||
$merchant = Merchant::query()->create([
|
||||
'name' => '访客测试站点',
|
||||
'slug' => 'guest-test',
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$sub = SiteSubscription::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'status' => 'activated',
|
||||
'source' => 'manual',
|
||||
'subscription_no' => 'SUB_GUEST_0001',
|
||||
'plan_name' => '访客测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'period_months' => 1,
|
||||
'amount' => 88,
|
||||
'starts_at' => now()->subDay(),
|
||||
'ends_at' => now()->addDays(29),
|
||||
'activated_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$this->get('/admin/site-subscriptions/' . $sub->id)
|
||||
->assertRedirect('/admin/login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user