- 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 更新多个请求类,统一代理资料字段的验证逻辑,提升代码复用性。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义。 - 在 AgentProfile 模型中设置主键为 agent_node_id,确保与代理节点的关联性。 - 更新错误信息,增加对授信额度和占成比例的验证,确保数据一致性。
92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminUser;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
|
|
});
|
|
|
|
test('enabled agent primary account can login after create', function (): void {
|
|
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
|
$rootId = (int) DB::table('agent_nodes')->where('admin_site_id', $siteId)->where('depth', 0)->value('id');
|
|
$service = app(\App\Services\Agent\AgentNodeService::class);
|
|
|
|
$super = AdminUser::query()->create([
|
|
'username' => 'login_super',
|
|
'name' => 'Login Super',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($super);
|
|
|
|
$child = $service->createChild($super, agentChildPayload([
|
|
'parent_id' => $rootId,
|
|
'code' => 'login-agent',
|
|
'name' => 'Login Agent',
|
|
'username' => 'agent_login_user',
|
|
'status' => 1,
|
|
]));
|
|
|
|
$userId = (int) DB::table('admin_user_agents')
|
|
->where('agent_node_id', $child->id)
|
|
->where('is_primary', true)
|
|
->value('admin_user_id');
|
|
|
|
expect((int) AdminUser::query()->find($userId)?->status)->toBe(0);
|
|
|
|
$captchaKey = (string) Str::uuid();
|
|
Cache::put(
|
|
'admin_captcha:'.$captchaKey,
|
|
hash_hmac('sha256', 'xwz2', (string) config('app.key')),
|
|
now()->addSeconds(120),
|
|
);
|
|
|
|
$this->postJson('/api/v1/admin/auth/login', [
|
|
'account' => 'agent_login_user',
|
|
'password' => agentNodeTestPassword(),
|
|
'captcha_key' => $captchaKey,
|
|
'captcha_code' => 'xwz2',
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('code', 0);
|
|
});
|
|
|
|
test('updating enabled agent keeps admin user login status active', function (): void {
|
|
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
|
$rootId = (int) DB::table('agent_nodes')->where('admin_site_id', $siteId)->where('depth', 0)->value('id');
|
|
$service = app(\App\Services\Agent\AgentNodeService::class);
|
|
|
|
$super = AdminUser::query()->create([
|
|
'username' => 'login_super2',
|
|
'name' => 'Login Super',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($super);
|
|
|
|
$child = $service->createChild($super, agentChildPayload([
|
|
'parent_id' => $rootId,
|
|
'code' => 'login-agent2',
|
|
'name' => 'Login Agent 2',
|
|
'username' => 'agent_login_user2',
|
|
'status' => 1,
|
|
]));
|
|
|
|
$service->update($child, ['name' => 'Login Agent 2 Updated', 'status' => 1]);
|
|
|
|
$userId = (int) DB::table('admin_user_agents')
|
|
->where('agent_node_id', $child->id)
|
|
->where('is_primary', true)
|
|
->value('admin_user_id');
|
|
|
|
expect((int) AdminUser::query()->find($userId)?->status)->toBe(0);
|
|
});
|