新增聊天室成就系统与消息保留策略
This commit is contained in:
@@ -854,6 +854,84 @@ class ChatControllerTest extends TestCase
|
||||
Storage::disk('public')->assertMissing('chat-images/2026-04-08/sample_thumb.png');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试消息清理命令会永久保留普通用户聊天,只删除过期游戏/临时通知。
|
||||
*/
|
||||
public function test_purge_command_keeps_user_chat_but_deletes_expired_notices(): void
|
||||
{
|
||||
$userMessage = \App\Models\Message::create([
|
||||
'room_id' => 1,
|
||||
'from_user' => 'normal_user',
|
||||
'to_user' => '大家',
|
||||
'content' => '这条用户聊天需要永久保留',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'message_type' => 'text',
|
||||
'retention_type' => \App\Models\Message::RETENTION_USER_CHAT,
|
||||
'sent_at' => now()->subDays(60),
|
||||
]);
|
||||
$gameNotice = \App\Models\Message::create([
|
||||
'room_id' => 1,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => '过期游戏通知',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'message_type' => 'text',
|
||||
'retention_type' => \App\Models\Message::RETENTION_GAME_NOTICE,
|
||||
'sent_at' => now()->subDays(60),
|
||||
]);
|
||||
$temporaryNotice = \App\Models\Message::create([
|
||||
'room_id' => 1,
|
||||
'from_user' => '进出播报',
|
||||
'to_user' => '大家',
|
||||
'content' => '过期进出播报',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => 'system_welcome',
|
||||
'message_type' => 'text',
|
||||
'retention_type' => \App\Models\Message::RETENTION_EPHEMERAL_NOTICE,
|
||||
'sent_at' => now()->subDays(60),
|
||||
]);
|
||||
|
||||
$this->artisan('messages:purge', [
|
||||
'--days' => 30,
|
||||
'--image-days' => 3,
|
||||
])->assertExitCode(0);
|
||||
|
||||
$this->assertDatabaseHas('messages', ['id' => $userMessage->id]);
|
||||
$this->assertDatabaseMissing('messages', ['id' => $gameNotice->id]);
|
||||
$this->assertDatabaseMissing('messages', ['id' => $temporaryNotice->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试迁移前默认归为 user_chat 的旧游戏通知也会被清理。
|
||||
*/
|
||||
public function test_purge_command_deletes_legacy_game_notice_patterns(): void
|
||||
{
|
||||
$legacyNotice = \App\Models\Message::create([
|
||||
'room_id' => 1,
|
||||
'from_user' => '钓鱼播报',
|
||||
'to_user' => '大家',
|
||||
'content' => '旧钓鱼通知',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => 'fishing_result',
|
||||
'message_type' => 'text',
|
||||
'retention_type' => \App\Models\Message::RETENTION_USER_CHAT,
|
||||
'sent_at' => now()->subDays(60),
|
||||
]);
|
||||
|
||||
$this->artisan('messages:purge', [
|
||||
'--days' => 30,
|
||||
'--image-days' => 3,
|
||||
])->assertExitCode(0);
|
||||
|
||||
$this->assertDatabaseMissing('messages', ['id' => $legacyNotice->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试心跳接口可以正常返回成功响应。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user