赛马优化通知
This commit is contained in:
@@ -11,6 +11,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Events\HorseRaceSettled;
|
||||
use App\Jobs\CloseHorseRaceJob;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\GameConfig;
|
||||
use App\Models\HorseBet;
|
||||
use App\Models\HorseRace;
|
||||
@@ -19,6 +20,7 @@ use App\Services\ChatStateService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -414,4 +416,61 @@ class HorseRaceControllerTest extends TestCase
|
||||
$this->assertSame(5000, $payload['winner_pool']);
|
||||
$this->assertSame(9500, $payload['distributable_pool']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:验证赛马开奖后会给参与者发送带右下角提示的私聊结算通知。
|
||||
*/
|
||||
public function test_settlement_pushes_private_toast_notification_to_participant(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
/** @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' => '🏇'],
|
||||
],
|
||||
'total_pool' => 100,
|
||||
]);
|
||||
|
||||
HorseBet::create([
|
||||
'race_id' => $race->id,
|
||||
'user_id' => $user->id,
|
||||
'horse_id' => 2,
|
||||
'amount' => 100,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
// 模拟下注时已扣款,便于校验结算通知中的净输赢语义。
|
||||
$user->decrement('jjb', 100);
|
||||
|
||||
(new CloseHorseRaceJob($race))->handle(
|
||||
app(\App\Services\UserCurrencyService::class),
|
||||
app(ChatStateService::class),
|
||||
);
|
||||
|
||||
$messages = Redis::lrange('room:1:messages', 0, -1);
|
||||
$privateMessage = collect($messages)
|
||||
->map(fn (string $item) => json_decode($item, true))
|
||||
->first(fn (array $item) => ($item['from_user'] ?? null) === '系统'
|
||||
&& ($item['to_user'] ?? null) === $user->username
|
||||
&& ($item['toast_notification']['title'] ?? null) === '🏇 赛马本场结算');
|
||||
|
||||
$this->assertNotNull($privateMessage);
|
||||
$this->assertTrue((bool) ($privateMessage['is_secret'] ?? false));
|
||||
$this->assertStringContainsString('净输 100 金币', (string) ($privateMessage['content'] ?? ''));
|
||||
$this->assertStringContainsString('-100', (string) ($privateMessage['toast_notification']['message'] ?? ''));
|
||||
$this->assertSame('📉', $privateMessage['toast_notification']['icon'] ?? null);
|
||||
$this->assertSame('#ef4444', $privateMessage['toast_notification']['color'] ?? null);
|
||||
|
||||
// 公屏赛果消息 + 参与者私聊结算通知,都应进入落库队列。
|
||||
Queue::assertPushed(SaveMessageJob::class, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user