修复座驾与会员入场重复展示

This commit is contained in:
pllx
2026-04-30 11:03:09 +08:00
parent 221f629ec2
commit 3eaf37a648
3 changed files with 82 additions and 3 deletions
+73
View File
@@ -1142,6 +1142,79 @@ class ChatControllerTest extends TestCase
], $response->viewData('initialRideEffectOptions'));
}
/**
* 测试会员用户有座驾时优先播放座驾,并在座驾播报中展示完整身份摘要。
*/
public function test_ride_presence_takes_priority_over_vip_presence_and_includes_identity_summary(): void
{
$room = Room::create(['room_name' => 'rvip']);
$vipLevel = VipLevel::factory()->create([
'name' => '至尊会员',
'icon' => '👑',
'join_effect' => 'lightning',
'join_banner_style' => 'storm',
'allow_custom_messages' => true,
]);
$user = User::factory()->create([
'vip_level_id' => $vipLevel->id,
'hy_time' => now()->addDays(30),
'custom_join_message' => '{username} 带着风暴王座闪耀降临',
'has_received_new_gift' => true,
]);
$department = Department::create([
'name' => '战备部',
'rank' => 90,
'color' => '#0f766e',
'sort_order' => 1,
]);
$position = Position::create([
'department_id' => $department->id,
'name' => '试飞官',
'icon' => '🛡️',
'rank' => 90,
'level' => 90,
'sort_order' => 1,
]);
UserPosition::create([
'user_id' => $user->id,
'position_id' => $position->id,
'appointed_at' => now(),
'is_active' => true,
]);
$ride = Ride::query()->updateOrCreate(['slug' => 'ride_99a'], [
'name' => '99A测试座驾',
'effect_key' => '99a',
'description' => '测试座驾',
'icon' => '🛡️',
'price' => 28888,
'duration_days' => 7,
'sort_order' => 90,
'is_active' => true,
'welcome_message' => '【{name}】乘坐【{ride}】闪亮登场',
]);
UserRidePurchase::create([
'user_id' => $user->id,
'ride_id' => $ride->id,
'status' => 'active',
'price_paid' => 28888,
'expires_at' => now()->addDays(3),
]);
$response = $this->actingAs($user)->get(route('chat.room', $room->id));
$response->assertOk();
$history = collect($response->viewData('historyMessages'));
$rideMessage = $history->first(fn (array $message): bool => ($message['welcome_kind'] ?? '') === 'ride_presence');
$vipPresenceMessage = $history->first(fn (array $message): bool => ($message['action'] ?? '') === 'vip_presence');
$this->assertNotNull($rideMessage);
$this->assertNull($vipPresenceMessage);
$this->assertStringContainsString('部门 战备部 · 职务 🛡️ 试飞官 · 会员 👑 至尊会员', $rideMessage['content']);
$this->assertStringContainsString($user->username, $rideMessage['content']);
$this->assertSame('99a', $response->viewData('initialRideEffect'));
$this->assertNull($response->viewData('initialPresenceTheme'));
}
/**
* 测试过期座驾用户进房时不会触发座驾播报。
*/