- Changed super admin detection from role-based to `is_super_admin` flag in AdminUser model
- Added `requireDefaultAdminSiteId()` method to throw validation error when no integration site exists
- Enhanced site deletion to migrate platform role bindings to fallback site and auto-delete site-specific admin accounts
- Made agent line code optional with auto-generation fallback using `{site_code}-agent-{counter}` format
137 lines
4.8 KiB
PHP
137 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Player;
|
|
use App\Support\PlayerAuthSource;
|
|
use App\Support\PlayerFundingMode;
|
|
use Database\Seeders\CurrencySeeder;
|
|
use Database\Seeders\LotterySettingsSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->seed(CurrencySeeder::class);
|
|
$this->seed(LotterySettingsSeeder::class);
|
|
});
|
|
|
|
test('credit player wallet logs reads credit_ledger not wallet_txns', function (): void {
|
|
$player = Player::query()->create([
|
|
'site_code' => 'default_site',
|
|
'site_player_id' => 'native:logs-1',
|
|
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
|
'funding_mode' => PlayerFundingMode::CREDIT,
|
|
'username' => 'credit_logs',
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
DB::table('player_credit_accounts')->insert([
|
|
'player_id' => $player->id,
|
|
'credit_limit' => 200,
|
|
'used_credit' => 10,
|
|
'frozen_credit' => 0,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('credit_ledger')->insert([
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'amount' => -1000,
|
|
'reason' => 'bet_hold',
|
|
'ref_type' => 'bet',
|
|
'ref_id' => null,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/logs?page=1&size=10')
|
|
->assertOk()
|
|
->assertJsonPath('data.ledger_source', 'credit_ledger')
|
|
->assertJsonPath('data.funding_mode', PlayerFundingMode::CREDIT)
|
|
->assertJsonPath('data.auth_source', PlayerAuthSource::LOTTERY_NATIVE)
|
|
->assertJsonPath('data.total', 1)
|
|
->assertJsonPath('data.items.0.type', 'bet')
|
|
->assertJsonPath('data.items.0.biz_type', 'bet_hold')
|
|
->assertJsonPath('data.items.0.ledger_source', 'credit_ledger');
|
|
});
|
|
|
|
test('credit player wallet logs distinguish win credit from bill settlement', function (): void {
|
|
$player = Player::query()->create([
|
|
'site_code' => 'default_site',
|
|
'site_player_id' => 'native:logs-2',
|
|
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
|
'funding_mode' => PlayerFundingMode::CREDIT,
|
|
'username' => 'credit_logs_2',
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
DB::table('player_credit_accounts')->insert([
|
|
'player_id' => $player->id,
|
|
'credit_limit' => 500,
|
|
'used_credit' => 0,
|
|
'frozen_credit' => 0,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('credit_ledger')->insert([
|
|
[
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'amount' => 3600,
|
|
'reason' => 'settlement_payout',
|
|
'ref_type' => 'settlement_bill',
|
|
'ref_id' => 25,
|
|
'created_at' => now()->subMinute(),
|
|
'updated_at' => now()->subMinute(),
|
|
],
|
|
[
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'amount' => 1200,
|
|
'reason' => 'game_settlement_win',
|
|
'ref_type' => 'ticket_item',
|
|
'ref_id' => 99,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
],
|
|
]);
|
|
|
|
$response = $this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/logs?page=1&size=10');
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.total', 2)
|
|
->assertJsonPath('data.items.0.type', 'win_credit')
|
|
->assertJsonPath('data.items.0.biz_type', 'game_settlement_win')
|
|
->assertJsonPath('data.items.0.affects_available_credit', true)
|
|
->assertJsonPath('data.items.1.type', 'bill_settlement')
|
|
->assertJsonPath('data.items.1.biz_type', 'settlement_payout')
|
|
->assertJsonPath('data.items.1.affects_available_credit', false)
|
|
->assertJsonPath('data.items.1.balance_after', null);
|
|
|
|
expect($response->json('data.items.0.balance_after'))->not->toBeNull();
|
|
|
|
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/logs?type=bill_settlement')
|
|
->assertOk()
|
|
->assertJsonPath('data.total', 1)
|
|
->assertJsonPath('data.items.0.type', 'bill_settlement');
|
|
|
|
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/logs?type=win_credit')
|
|
->assertOk()
|
|
->assertJsonPath('data.total', 1)
|
|
->assertJsonPath('data.items.0.type', 'win_credit');
|
|
|
|
$this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/logs?type=credit_release')
|
|
->assertOk()
|
|
->assertJsonPath('data.total', 1)
|
|
->assertJsonPath('data.items.0.type', 'win_credit');
|
|
});
|