修复猜谜双题答题状态误同步

This commit is contained in:
pllx
2026-04-30 16:49:25 +08:00
parent 82dbc19319
commit fdd4f8a179
3 changed files with 138 additions and 17 deletions
@@ -368,6 +368,83 @@ class RiddleQuizControllerTest extends TestCase
$this->assertSame(10, $player->exp_num);
}
/**
* 方法功能:验证同一房间两种题型同时存在时,答对一题不会结算另一题。
*/
public function test_answer_only_ends_matching_round_when_two_quiz_types_are_active(): void
{
$this->mockChatStateService();
$player = User::factory()->create([
'username' => '破题用户',
'exp_num' => 10,
]);
$room = Room::create(['room_name' => '双题房间']);
$idiom = $this->createQuestion(
type: Riddle::TYPE_IDIOM,
answer: '画蛇添足',
hint: '🧩 四人比赛画蛇,最慢的那个反而多此一举。猜一成语',
);
$brainTeaser = $this->createQuestion(
type: Riddle::TYPE_BRAIN_TEASER,
answer: '影子',
hint: '🧠 天天跟着你走,白天有晚上无,看得见摸不着,是什么?',
);
GameConfig::create([
'game_key' => 'idiom',
'name' => '猜谜活动',
'icon' => '🧩',
'enabled' => true,
'params' => [
'reward_gold' => 20,
'reward_exp' => 15,
'auto_start_interval' => 0,
'expire_minutes' => 5,
'room_scope_mode' => 'single',
'room_ids' => [$room->id],
],
]);
$idiomRound = RiddleGameRound::create([
'room_id' => $room->id,
'idiom_id' => $idiom->id,
'quiz_type' => Riddle::TYPE_IDIOM,
'status' => 'active',
'reward_gold' => 20,
'reward_exp' => 15,
'started_at' => now(),
]);
$brainTeaserRound = RiddleGameRound::create([
'room_id' => $room->id,
'idiom_id' => $brainTeaser->id,
'quiz_type' => Riddle::TYPE_BRAIN_TEASER,
'status' => 'active',
'reward_gold' => 20,
'reward_exp' => 15,
'started_at' => now(),
]);
$response = $this->actingAs($player)->postJson(route('riddle-quiz.answer'), [
'round_id' => $idiomRound->id,
'room_id' => $room->id,
'quiz_type' => Riddle::TYPE_IDIOM,
'answer' => '画蛇添足',
]);
$response->assertOk()
->assertJsonPath('status', 'success')
->assertJsonPath('data.quiz_round_id', $idiomRound->id);
$idiomRound->refresh();
$brainTeaserRound->refresh();
$this->assertSame('answered', $idiomRound->status);
$this->assertSame('破题用户', $idiomRound->winner_username);
$this->assertSame('active', $brainTeaserRound->status);
$this->assertNull($brainTeaserRound->winner_username);
}
/**
* 方法功能:验证自动出题会按房间和题型两个维度独立判断。
*/
@@ -491,6 +568,7 @@ class RiddleQuizControllerTest extends TestCase
Schema::disableForeignKeyConstraints();
Schema::dropIfExists('idiom_game_rounds');
Schema::dropIfExists('idioms');
Schema::dropIfExists('user_currency_logs');
Schema::dropIfExists('game_configs');
Schema::dropIfExists('rooms');
Schema::dropIfExists('users');
@@ -507,6 +585,8 @@ class RiddleQuizControllerTest extends TestCase
$table->text('custom_leave_message')->nullable();
$table->integer('user_level')->default(1);
$table->integer('exp_num')->default(0);
$table->integer('jjb')->default(0);
$table->integer('meili')->default(0);
$table->timestamps();
});
@@ -552,6 +632,19 @@ class RiddleQuizControllerTest extends TestCase
$table->timestamp('ended_at')->nullable();
$table->timestamps();
});
Schema::create('user_currency_logs', function (Blueprint $table): void {
$table->id();
$table->unsignedBigInteger('user_id')->index();
$table->string('username', 50);
$table->string('currency', 10);
$table->integer('amount');
$table->integer('balance_after');
$table->string('source', 30)->index();
$table->string('remark', 200)->nullable();
$table->unsignedBigInteger('room_id')->nullable();
$table->timestamp('created_at')->nullable()->index();
});
}
/**