优化vip

This commit is contained in:
2026-04-12 23:25:38 +08:00
parent 353aaaf6ce
commit dca43a2d0d
9 changed files with 346 additions and 100 deletions
@@ -13,12 +13,26 @@ use App\Models\VipLevel;
use App\Models\VipPaymentOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Redis;
use Tests\TestCase;
/**
* VIP 支付集成功能测试
* 覆盖创建订单、异步开通会员以及聊天室内购买成功喜报等关键链路。
*/
class VipPaymentIntegrationTest extends TestCase
{
use RefreshDatabase;
/**
* 每个测试前清空 Redis,避免聊天室在线状态与消息缓存互相污染。
*/
protected function setUp(): void
{
parent::setUp();
Redis::flushall();
}
/**
* 测试用户可以发起 VIP 支付并跳转到支付中心页面
*/
@@ -140,30 +154,19 @@ class VipPaymentIntegrationTest extends TestCase
*/
public function test_vip_center_only_shows_current_user_records(): void
{
$currentUser = User::factory()->create(['username' => 'current-user']);
$otherUser = User::factory()->create(['username' => 'other-user']);
$vipLevel = VipLevel::factory()->create([
'name' => '星耀会员',
'price' => 66,
'duration_days' => 30,
]);
$this->seedVipPaymentConfig();
$currentUser = User::factory()->create();
$otherUser = User::factory()->create();
VipPaymentOrder::factory()->create([
'user_id' => $currentUser->id,
'vip_level_id' => $vipLevel->id,
'vip_name' => $vipLevel->name,
'status' => 'paid',
'order_no' => 'VPO_CURRENT_001',
'merchant_order_no' => 'MER_CURRENT_001',
]);
VipPaymentOrder::factory()->create([
'user_id' => $otherUser->id,
'vip_level_id' => $vipLevel->id,
'vip_name' => $vipLevel->name,
'status' => 'paid',
'order_no' => 'VPO_OTHER_001',
'merchant_order_no' => 'MER_OTHER_001',
]);
$response = $this->actingAs($currentUser)->get(route('vip.center'));
@@ -179,6 +182,8 @@ class VipPaymentIntegrationTest extends TestCase
*/
public function test_vip_member_can_update_custom_presence_messages(): void
{
$this->seedVipPaymentConfig();
$vipLevel = VipLevel::factory()->create([
'allow_custom_messages' => true,
]);
@@ -201,10 +206,12 @@ class VipPaymentIntegrationTest extends TestCase
}
/**
* 测试未开通该权限的用户不能保存自定义欢迎语和离开语
* 测试普通用户或不允许自定义的会员无法保存专属语句
*/
public function test_non_customizable_vip_member_cannot_update_custom_presence_messages(): void
{
$this->seedVipPaymentConfig();
$vipLevel = VipLevel::factory()->create([
'allow_custom_messages' => false,
]);
@@ -226,15 +233,15 @@ class VipPaymentIntegrationTest extends TestCase
}
/**
* 写入测试所需的支付中心配置
* 初始化支付中心模拟配置
*/
private function seedVipPaymentConfig(): void
{
// 这些配置与聊天室后台保存的数据结构保持一致,方便直接复用真实业务代码。
Sysparam::query()->updateOrCreate(['alias' => 'vip_payment_enabled'], ['body' => '1']);
Sysparam::query()->updateOrCreate(['alias' => 'vip_payment_base_url'], ['body' => 'https://novalink.test']);
Sysparam::query()->updateOrCreate(['alias' => 'vip_payment_app_key'], ['body' => 'chatroom-app']);
Sysparam::query()->updateOrCreate(['alias' => 'vip_payment_app_secret'], ['body' => 'chatroom-secret']);
Sysparam::query()->updateOrCreate(['alias' => 'vip_payment_timeout'], ['body' => '10']);
Sysparam::updateOrCreate(['alias' => 'vip_payment_enabled'], ['body' => '1']);
Sysparam::clearCache('vip_payment_enabled');
config(['services.novalink_payment_center.client_id' => 'chatroom-app']);
config(['services.novalink_payment_center.client_secret' => 'chatroom-secret']);
config(['services.novalink_payment_center.base_url' => 'https://novalink.test/api/open/v1']);
}
}