feat(core): harden sessions settlement and credit activity
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
lotterLaravel E2E / e2e-api (push) Has been cancelled

This commit is contained in:
wchino
2026-07-22 20:53:43 +08:00
parent 35f6e46958
commit 15bd997c4e
48 changed files with 1920 additions and 93 deletions

View File

@@ -17,6 +17,7 @@ use App\Events\PlayCatalogUpdatedBroadcast;
use Database\Seeders\LotterySettingsSeeder;
use Illuminate\Broadcasting\PrivateChannel;
use App\Services\Config\RiskCapStreamService;
use App\Events\PlayerSessionReplacedBroadcast;
use App\Services\Wallet\LotteryTransferService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Services\Wallet\WalletBalanceRealtimeNotifier;
@@ -39,6 +40,21 @@ test('balance update broadcasts only on the player private channel', function ()
->and($channels[0]->name)->toBe('private-player.42');
});
test('session replacement broadcasts the monotonic version on the player private channel', function (): void {
$event = new PlayerSessionReplacedBroadcast(42, 3, 1_234_567);
$channels = $event->broadcastOn();
expect($channels)->toHaveCount(1)
->and($channels[0])->toBeInstanceOf(PrivateChannel::class)
->and($channels[0]->name)->toBe('private-player.42')
->and($event->broadcastAs())->toBe('session.replaced')
->and($event->broadcastWith())->toBe([
'player_id' => 42,
'session_version' => 3,
'emitted_at_ms' => 1_234_567,
]);
});
test('player private channel auth allows only the matching bearer player', function (): void {
config([
'broadcasting.default' => 'reverb',