优化用户资料卡成就摘要查询

This commit is contained in:
pllx
2026-04-30 16:45:46 +08:00
parent ffd8789e67
commit 82dbc19319
3 changed files with 45 additions and 8 deletions
+26
View File
@@ -13,6 +13,7 @@ use App\Models\Position;
use App\Models\Room;
use App\Models\Sysparam;
use App\Models\User;
use App\Models\UserAchievement;
use App\Models\UserCurrencyLog;
use App\Models\UserPosition;
use App\Services\ChatUserPresenceService;
@@ -65,6 +66,31 @@ class UserControllerTest extends TestCase
->assertJsonPath('data.user_level', 10);
}
/**
* 测试用户资料卡只读取已缓存的成就摘要,避免打开名片时触发全量扫描。
*/
public function test_user_profile_uses_cached_achievement_summary(): void
{
$viewer = User::factory()->create();
$target = User::factory()->create([
'username' => 'achievement-target',
]);
UserAchievement::factory()->create([
'user_id' => $target->id,
'achievement_key' => 'chat_first_message',
'progress_value' => 1,
'achieved_at' => now(),
]);
$response = $this->actingAs($viewer)->getJson("/user/{$target->username}");
$response->assertOk()
->assertJsonPath('data.achievements.unlocked_count', 1)
->assertJsonPath('data.achievements.recent.0.key', 'chat_first_message')
->assertJsonMissingPath('data.achievements.achievements');
}
/**
* 测试普通用户查看别人名片时银行存款默认显示星号。
*/