测试: 完成游戏娱乐模块 (Gomoku, HorseRace, Lottery 等) 功能全量联调测试与代码格式化
This commit is contained in:
143
tests/Feature/SlotMachineControllerTest.php
Normal file
143
tests/Feature/SlotMachineControllerTest.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\GameConfig;
|
||||
use App\Models\SlotMachineLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SlotMachineControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
GameConfig::updateOrCreate(
|
||||
['game_key' => 'slot_machine'],
|
||||
[
|
||||
'name' => 'Slot Machine',
|
||||
'icon' => 'slot',
|
||||
'description' => 'Slot Machine Game',
|
||||
'enabled' => true,
|
||||
'params' => [
|
||||
'cost_per_spin' => 100,
|
||||
'daily_limit' => 100,
|
||||
'jackpot_payout' => 100,
|
||||
'triple_payout' => 50,
|
||||
'same_payout' => 10,
|
||||
'pair_payout' => 2,
|
||||
'curse_enabled' => true,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_can_get_info()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('slot.info'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson([
|
||||
'enabled' => true,
|
||||
'cost_per_spin' => 100,
|
||||
'daily_limit' => 100,
|
||||
'used_today' => 0,
|
||||
]);
|
||||
$response->assertJsonStructure(['symbols']);
|
||||
}
|
||||
|
||||
public function test_can_spin_enough_gold()
|
||||
{
|
||||
Event::fake();
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 200]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('slot.spin'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
$this->assertDatabaseHas('slot_machine_logs', [
|
||||
'user_id' => $user->id,
|
||||
'cost' => 100,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_spin_without_enough_gold()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 50]); // Need 100
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('slot.spin'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => false]);
|
||||
}
|
||||
|
||||
public function test_cannot_spin_exceed_daily_limit()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 2000]);
|
||||
|
||||
// Mock daily limit 1
|
||||
GameConfig::updateOrCreate(
|
||||
['game_key' => 'slot_machine'],
|
||||
[
|
||||
'name' => 'Slot Machine',
|
||||
'icon' => 'slot',
|
||||
'description' => 'Slot Mac',
|
||||
'enabled' => true,
|
||||
'params' => [
|
||||
'cost_per_spin' => 100,
|
||||
'daily_limit' => 1,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
SlotMachineLog::create([
|
||||
'user_id' => $user->id,
|
||||
'reel1' => 'cherry',
|
||||
'reel2' => 'lemon',
|
||||
'reel3' => 'orange',
|
||||
'result_type' => 'miss',
|
||||
'cost' => 100,
|
||||
'payout' => 0,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('slot.spin'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => false]);
|
||||
}
|
||||
|
||||
public function test_can_get_history()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
SlotMachineLog::create([
|
||||
'user_id' => $user->id,
|
||||
'reel1' => 'cherry',
|
||||
'reel2' => 'cherry',
|
||||
'reel3' => 'cherry',
|
||||
'result_type' => 'triple',
|
||||
'cost' => 100,
|
||||
'payout' => 1000,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('slot.history'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonStructure(['history']);
|
||||
$this->assertCount(1, $response->json('history'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user