修复聊天室字号偏好和游戏通知显示
This commit is contained in:
@@ -8,10 +8,16 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 类功能:覆盖钓鱼小游戏抛竿、收竿和令牌校验流程。
|
||||
*/
|
||||
class FishingControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 初始化钓鱼配置并清理 Redis 状态。
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -32,7 +38,10 @@ class FishingControllerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_can_cast_rod()
|
||||
/**
|
||||
* 方法功能:验证用户金币足够时可以正常抛竿并扣除费用。
|
||||
*/
|
||||
public function test_can_cast_rod(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 10]);
|
||||
@@ -48,7 +57,10 @@ class FishingControllerTest extends TestCase
|
||||
$this->assertEquals(5, $user->fresh()->jjb);
|
||||
}
|
||||
|
||||
public function test_cannot_cast_when_on_cooldown()
|
||||
/**
|
||||
* 方法功能:验证冷却期间不能重复抛竿。
|
||||
*/
|
||||
public function test_cannot_cast_when_on_cooldown(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 10]);
|
||||
@@ -62,7 +74,10 @@ class FishingControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_cast_without_enough_gold()
|
||||
/**
|
||||
* 方法功能:验证金币不足时不能抛竿。
|
||||
*/
|
||||
public function test_cannot_cast_without_enough_gold(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 2]);
|
||||
@@ -75,13 +90,15 @@ class FishingControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_can_reel_after_waiting()
|
||||
/**
|
||||
* 方法功能:验证等待完成后携带正确令牌可以成功收竿。
|
||||
*/
|
||||
public function test_can_reel_after_waiting(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 10]);
|
||||
|
||||
$token = 'test-token';
|
||||
$waitTime = 0; // Set to 0 so we can test immediately
|
||||
|
||||
Redis::set("fishing:token:{$user->id}", json_encode([
|
||||
'token' => $token,
|
||||
@@ -102,7 +119,10 @@ class FishingControllerTest extends TestCase
|
||||
$this->assertTrue((bool) Redis::exists("fishing:cd:{$user->id}"));
|
||||
}
|
||||
|
||||
public function test_cannot_reel_with_invalid_token()
|
||||
/**
|
||||
* 方法功能:验证错误令牌不能收竿。
|
||||
*/
|
||||
public function test_cannot_reel_with_invalid_token(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 10]);
|
||||
@@ -122,4 +142,34 @@ class FishingControllerTest extends TestCase
|
||||
'status' => 'error',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:验证已有未收竿令牌时再次抛竿会恢复原会话且不会重复扣金币。
|
||||
*/
|
||||
public function test_cast_restores_active_token_without_charging_again(): void
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 10]);
|
||||
$tokenKey = "fishing:token:{$user->id}";
|
||||
$payload = json_encode([
|
||||
'token' => 'active-token',
|
||||
'cast_at' => time(),
|
||||
'wait_time' => 10,
|
||||
]);
|
||||
|
||||
Redis::setex($tokenKey, 20, $payload);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('fishing.cast', ['id' => 1]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson([
|
||||
'status' => 'success',
|
||||
'token' => 'active-token',
|
||||
'cost' => 0,
|
||||
'restored' => true,
|
||||
]);
|
||||
|
||||
$this->assertSame(10, $user->fresh()->jjb);
|
||||
$this->assertSame($payload, Redis::get($tokenKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ class UserControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试可以保存聊天室屏蔽与禁音偏好。
|
||||
* 测试可以保存聊天室屏蔽、禁音与字号偏好。
|
||||
*/
|
||||
public function test_can_update_chat_preferences(): void
|
||||
{
|
||||
@@ -428,6 +428,7 @@ class UserControllerTest extends TestCase
|
||||
$response = $this->actingAs($user)->putJson('/user/chat-preferences', [
|
||||
'blocked_system_senders' => ['钓鱼播报', '神秘箱子', '跑马'],
|
||||
'sound_muted' => true,
|
||||
'font_size' => 22,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
@@ -435,15 +436,59 @@ class UserControllerTest extends TestCase
|
||||
->assertJsonPath('data.blocked_system_senders.0', '钓鱼播报')
|
||||
->assertJsonPath('data.blocked_system_senders.1', '神秘箱子')
|
||||
->assertJsonPath('data.blocked_system_senders.2', '跑马')
|
||||
->assertJsonPath('data.sound_muted', true);
|
||||
->assertJsonPath('data.sound_muted', true)
|
||||
->assertJsonPath('data.font_size', 22);
|
||||
|
||||
$user->refresh();
|
||||
$this->assertEquals([
|
||||
'blocked_system_senders' => ['钓鱼播报', '神秘箱子', '跑马'],
|
||||
'sound_muted' => true,
|
||||
'font_size' => 22,
|
||||
], $user->chat_preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试保存屏蔽偏好时未提交字号不会清空已有字号。
|
||||
*/
|
||||
public function test_chat_preferences_keep_existing_font_size_when_missing_from_payload(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'chat_preferences' => [
|
||||
'blocked_system_senders' => [],
|
||||
'sound_muted' => false,
|
||||
'font_size' => 18,
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->putJson('/user/chat-preferences', [
|
||||
'blocked_system_senders' => ['钓鱼播报'],
|
||||
'sound_muted' => false,
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.font_size', 18);
|
||||
|
||||
$user->refresh();
|
||||
$this->assertSame(18, $user->chat_preferences['font_size']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试非法聊天室字号会返回校验错误。
|
||||
*/
|
||||
public function test_invalid_chat_font_size_returns_validation_error(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->putJson('/user/chat-preferences', [
|
||||
'blocked_system_senders' => [],
|
||||
'sound_muted' => false,
|
||||
'font_size' => 31,
|
||||
]);
|
||||
|
||||
$response->assertStatus(422)
|
||||
->assertJsonValidationErrors('font_size');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试猜谜活动新文案会兼容落回旧的屏蔽键。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user