Fix horse race seed pool payouts

This commit is contained in:
2026-04-11 16:11:00 +08:00
parent cc1dd017ce
commit 44db0d7853
7 changed files with 103 additions and 21 deletions
+65
View File
@@ -2,12 +2,15 @@
namespace Tests\Feature;
use App\Jobs\CloseHorseRaceJob;
use App\Models\GameConfig;
use App\Models\HorseBet;
use App\Models\HorseRace;
use App\Models\User;
use App\Services\ChatStateService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class HorseRaceControllerTest extends TestCase
@@ -182,4 +185,66 @@ class HorseRaceControllerTest extends TestCase
$response->assertJsonStructure(['history']);
$this->assertCount(1, $response->json('history'));
}
public function test_single_winner_receives_seed_pool_and_does_not_lose_principal(): void
{
Event::fake();
Queue::fake();
GameConfig::updateOrCreate(
['game_key' => 'horse_racing'],
[
'name' => 'Horse Racing',
'icon' => 'horse',
'description' => 'Horse Racing Game',
'enabled' => true,
'params' => [
'min_bet' => 100,
'max_bet' => 100000,
'house_take_percent' => 5,
'seed_pool' => 10,
],
]
);
/** @var \App\Models\User $user */
$user = User::factory()->create(['jjb' => 500]);
$race = HorseRace::create([
'status' => 'running',
'bet_opens_at' => now()->subMinutes(2),
'bet_closes_at' => now()->subMinute(),
'race_starts_at' => now()->subSeconds(30),
'winner_horse_id' => 1,
'horses' => [
['id' => 1, 'name' => 'Horse A', 'emoji' => '🐎'],
['id' => 2, 'name' => 'Horse B', 'emoji' => '🏇'],
],
]);
HorseBet::create([
'race_id' => $race->id,
'user_id' => $user->id,
'horse_id' => 1,
'amount' => 100,
'status' => 'pending',
]);
$user->decrement('jjb', 100);
$chatState = $this->createMock(ChatStateService::class);
$chatState->method('nextMessageId')->willReturn(1);
$chatState->method('pushMessage');
app()->instance(ChatStateService::class, $chatState);
(new CloseHorseRaceJob($race))->handle(app('App\Services\UserCurrencyService'), $chatState);
$bet = HorseBet::query()->first();
$this->assertNotNull($bet);
$this->assertSame('won', $bet->status);
$this->assertSame(105, $bet->payout);
$this->assertSame(505, $user->fresh()->jjb);
}
}