feat: enhance agent management and validation logic
- Updated AGENTS.md to clarify agent account restrictions and permissions. - Implemented checks in AgentNodeAdminUserStoreController and AgentNodeRoleStoreController to restrict admin user and role creation to the agent's own node. - Enhanced validation in AdminPlayerStoreController and AdminPlayerUpdateController to enforce credit limit and rebate rate rules based on player funding mode. - Refactored various request classes to utilize shared admin account field rules for consistency. - Improved error handling in services related to credit allocation and rebate limits to ensure proper validation and messaging.
This commit is contained in:
@@ -47,6 +47,97 @@ test('native player can login without site code using default site', function ()
|
||||
->assertJsonPath('data.player.id', $player->id);
|
||||
});
|
||||
|
||||
test('native player can login without site code on non-default site when username is unique', function (): void {
|
||||
$siteId = (int) DB::table('admin_sites')->insertGetId([
|
||||
'code' => 'kk88',
|
||||
'name' => 'kk88',
|
||||
'is_default' => false,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$rootId = (int) DB::table('agent_nodes')->insertGetId([
|
||||
'admin_site_id' => $siteId,
|
||||
'parent_id' => null,
|
||||
'depth' => 0,
|
||||
'path' => '/kk88',
|
||||
'code' => 'kk88-root',
|
||||
'name' => 'Root',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$player = Player::query()->create([
|
||||
'site_code' => 'kk88',
|
||||
'agent_node_id' => $rootId,
|
||||
'site_player_id' => 'native:kk88-1',
|
||||
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
||||
'funding_mode' => PlayerFundingMode::CREDIT,
|
||||
'username' => 'play1',
|
||||
'password_hash' => Hash::make('secret-pass'),
|
||||
'nickname' => null,
|
||||
'default_currency' => 'NPR',
|
||||
'status' => 0,
|
||||
]);
|
||||
|
||||
$this->postJson('/api/v1/player/auth/login', [
|
||||
'username' => 'play1',
|
||||
'password' => 'secret-pass',
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.player.id', $player->id)
|
||||
->assertJsonPath('data.player.site_code', 'kk88');
|
||||
});
|
||||
|
||||
test('native player login without site code rejects ambiguous username across sites', function (): void {
|
||||
$defaultSite = DB::table('admin_sites')->where('is_default', true)->first();
|
||||
$rootId = (int) DB::table('agent_nodes')->where('depth', 0)->value('id');
|
||||
|
||||
$siteId = (int) DB::table('admin_sites')->insertGetId([
|
||||
'code' => 'other_site',
|
||||
'name' => 'Other',
|
||||
'is_default' => false,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$otherRootId = (int) DB::table('agent_nodes')->insertGetId([
|
||||
'admin_site_id' => $siteId,
|
||||
'parent_id' => null,
|
||||
'depth' => 0,
|
||||
'path' => '/other',
|
||||
'code' => 'other-root',
|
||||
'name' => 'Other Root',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
foreach ([
|
||||
['site_code' => (string) $defaultSite->code, 'agent_node_id' => $rootId, 'site_player_id' => 'dup-a'],
|
||||
['site_code' => 'other_site', 'agent_node_id' => $otherRootId, 'site_player_id' => 'dup-b'],
|
||||
] as $row) {
|
||||
Player::query()->create([
|
||||
'site_code' => $row['site_code'],
|
||||
'agent_node_id' => $row['agent_node_id'],
|
||||
'site_player_id' => $row['site_player_id'],
|
||||
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
||||
'funding_mode' => PlayerFundingMode::CREDIT,
|
||||
'username' => 'dup_user',
|
||||
'password_hash' => Hash::make('secret-pass'),
|
||||
'nickname' => null,
|
||||
'default_currency' => 'NPR',
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->postJson('/api/v1/player/auth/login', [
|
||||
'username' => 'dup_user',
|
||||
'password' => 'secret-pass',
|
||||
])->assertJsonPath('code', 8006);
|
||||
});
|
||||
|
||||
test('native player can login and access me', function (): void {
|
||||
$site = DB::table('admin_sites')->where('is_default', true)->first();
|
||||
$rootId = (int) DB::table('agent_nodes')->where('depth', 0)->value('id');
|
||||
|
||||
Reference in New Issue
Block a user