修复聊天室字号偏好和游戏通知显示
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user