增加每日游戏三杰榜
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Models\Department;
|
||||
use App\Models\Gift;
|
||||
@@ -16,6 +17,7 @@ use App\Models\Ride;
|
||||
use App\Models\Room;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCurrencyLog;
|
||||
use App\Models\UserPosition;
|
||||
use App\Models\UserRidePurchase;
|
||||
use App\Models\VipLevel;
|
||||
@@ -67,6 +69,57 @@ class ChatControllerTest extends TestCase
|
||||
$this->assertEquals(1, Redis::hexists("room:{$room->id}:users", $user->username));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试聊天室顶部会展示百家乐与赛马今日净盈利前三。
|
||||
*/
|
||||
public function test_room_header_displays_daily_game_profit_top_three(): void
|
||||
{
|
||||
Cache::flush();
|
||||
Sysparam::updateOrCreate(['alias' => 'superlevel'], ['body' => '100']);
|
||||
|
||||
$room = Room::create(['room_name' => 'profitroom']);
|
||||
$viewer = User::factory()->create(['username' => '围观群众', 'user_level' => 1]);
|
||||
$first = User::factory()->create(['username' => '第一赢家', 'user_level' => 1]);
|
||||
$second = User::factory()->create(['username' => '第二赢家', 'user_level' => 1]);
|
||||
$third = User::factory()->create(['username' => '第三赢家', 'user_level' => 1]);
|
||||
$yesterdayWinner = User::factory()->create(['username' => '昨日财神', 'user_level' => 1]);
|
||||
$breakEvenUser = User::factory()->create(['username' => '白忙选手', 'user_level' => 1]);
|
||||
$admin = User::factory()->create(['username' => '超级管理员', 'user_level' => 100]);
|
||||
$bot = User::factory()->create(['username' => 'AI小班长', 'user_level' => 1]);
|
||||
|
||||
$this->recordGameGoldLog($first, CurrencySource::BACCARAT_WIN, 10000);
|
||||
$this->recordGameGoldLog($first, CurrencySource::BACCARAT_BET, -2500);
|
||||
$this->recordGameGoldLog($second, CurrencySource::HORSE_WIN, 6000);
|
||||
$this->recordGameGoldLog($second, CurrencySource::HORSE_BET, -1000);
|
||||
$this->recordGameGoldLog($third, CurrencySource::BACCARAT_WIN, 3000);
|
||||
$this->recordGameGoldLog($yesterdayWinner, CurrencySource::HORSE_WIN, 50000, now()->subDay());
|
||||
$this->recordGameGoldLog($breakEvenUser, CurrencySource::BACCARAT_WIN, 1000);
|
||||
$this->recordGameGoldLog($breakEvenUser, CurrencySource::BACCARAT_BET, -1000);
|
||||
$this->recordGameGoldLog($admin, CurrencySource::BACCARAT_WIN, 999999);
|
||||
$this->recordGameGoldLog($bot, CurrencySource::HORSE_WIN, 888888);
|
||||
|
||||
$response = $this->actingAs($viewer)->get(route('chat.room', $room->id));
|
||||
|
||||
$leaders = $response->viewData('dailyGameProfitLeaders');
|
||||
|
||||
$this->assertSame(['超级管理员', '第一赢家', '第二赢家'], $leaders->pluck('username')->all());
|
||||
$this->assertSame([999999, 7500, 5000], $leaders->pluck('net_profit')->all());
|
||||
$this->assertStringStartsWith('/images/headface/', $leaders->first()->headface_url);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('今日游戏三杰');
|
||||
$response->assertSee('class="daily-game-profit-avatar"', false);
|
||||
$response->assertSee('data-username="超级管理员"', false);
|
||||
$response->assertSee('data-username="第一赢家"', false);
|
||||
$response->assertSee('data-username="第二赢家"', false);
|
||||
$response->assertDontSee('金库爆破王');
|
||||
$response->assertDontSee('马桌双修财神');
|
||||
$response->assertDontSee('金币收割机');
|
||||
$response->assertDontSee('+999,999');
|
||||
$response->assertDontSee('+7,500');
|
||||
$response->assertDontSee('+5,000');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试关闭房间会拒绝普通用户直接进入。
|
||||
*/
|
||||
@@ -1499,6 +1552,23 @@ class ChatControllerTest extends TestCase
|
||||
$response->assertStatus(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录一条游戏金币流水,用于构造每日游戏净盈利榜测试数据。
|
||||
*/
|
||||
private function recordGameGoldLog(User $user, CurrencySource $source, int $amount, \DateTimeInterface|string|null $createdAt = null): void
|
||||
{
|
||||
UserCurrencyLog::forceCreate([
|
||||
'user_id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'currency' => 'gold',
|
||||
'amount' => $amount,
|
||||
'balance_after' => max(0, 100000 + $amount),
|
||||
'source' => $source->value,
|
||||
'remark' => '每日游戏净盈利榜测试',
|
||||
'created_at' => $createdAt ?? now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建带指定聊天室权限的在职职务用户。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user