create([ 'jjb' => 0, 'exp_num' => 0, ]); $response = $this->actingAs($user)->postJson(route('earn.video_reward'), [ 'room_id' => 1, ]); $response->assertStatus(200); $response->assertJson([ 'success' => true, ]); $this->assertDatabaseHas('users', [ 'id' => $user->id, 'jjb' => 5000, // Reward is hardcoded to 5000 'exp_num' => 500, // Exp is hardcoded to 500 ]); // Cooldown should be set $this->assertTrue((bool) Redis::exists("earn_video:cooldown:{$user->id}")); } public function test_cannot_claim_during_cooldown() { $user = User::factory()->create(); // First claim $this->actingAs($user)->postJson(route('earn.video_reward')); // Second claim immediately should fail due to cooldown $response = $this->actingAs($user)->postJson(route('earn.video_reward')); $response->assertStatus(200); $response->assertJson([ 'success' => false, 'message' => '操作过快,请稍后再试。', ]); } public function test_cannot_exceed_daily_limit() { $user = User::factory()->create(); $dateKey = now()->format('Y-m-d'); // Manually set daily count to max limit (3) Redis::set("earn_video:count:{$user->id}:{$dateKey}", 3); $response = $this->actingAs($user)->postJson(route('earn.video_reward')); $response->assertStatus(200); $response->assertJsonFragment([ 'success' => false, ]); } }