|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace Tests\Integration;
|
|
namespace Tests\Integration;
|
|
|
|
|
|
|
|
|
|
+use App\Console\Commands\UnlinkAgentOwners;
|
|
|
use App\Http\Controllers\admin\AgentApplication as AdminApplication;
|
|
use App\Http\Controllers\admin\AgentApplication as AdminApplication;
|
|
|
use App\Models\Agent\Agent;
|
|
use App\Models\Agent\Agent;
|
|
|
use App\Models\Agent\AgentApplication;
|
|
use App\Models\Agent\AgentApplication;
|
|
@@ -24,6 +25,7 @@ use Illuminate\Translation\ArrayLoader;
|
|
|
use Illuminate\Translation\Translator;
|
|
use Illuminate\Translation\Translator;
|
|
|
use Illuminate\Validation\Factory;
|
|
use Illuminate\Validation\Factory;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
+use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
class AgentApplicationTest extends TestCase
|
|
class AgentApplicationTest extends TestCase
|
|
|
{
|
|
{
|
|
@@ -118,13 +120,13 @@ class AgentApplicationTest extends TestCase
|
|
|
return (new AdminApplication())->audit($this->service, $this->agents)->getData(true);
|
|
return (new AdminApplication())->audit($this->service, $this->agents)->getData(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_approval_creates_bound_first_level_agent_keeps_passwords_and_sends_one_private_message(): void
|
|
|
|
|
|
|
+ public function test_approval_creates_independent_agent_keeps_passwords_and_sends_one_private_message(): void
|
|
|
{
|
|
{
|
|
|
$application = $this->application();
|
|
$application = $this->application();
|
|
|
$response = $this->audit($application->id);
|
|
$response = $this->audit($application->id);
|
|
|
$this->assertSame(0, $response['code'], $response['msg']);
|
|
$this->assertSame(0, $response['code'], $response['msg']);
|
|
|
$agent = Agent::firstOrFail();
|
|
$agent = Agent::firstOrFail();
|
|
|
- $this->assertSame(11, $agent->owner_user_id);
|
|
|
|
|
|
|
+ $this->assertNull($agent->owner_user_id);
|
|
|
$this->assertSame(1, $agent->level);
|
|
$this->assertSame(1, $agent->level);
|
|
|
$this->assertSame(1, $agent->status);
|
|
$this->assertSame(1, $agent->status);
|
|
|
$this->assertTrue(Hash::check('login-secret', $agent->password));
|
|
$this->assertTrue(Hash::check('login-secret', $agent->password));
|
|
@@ -134,6 +136,7 @@ class AgentApplicationTest extends TestCase
|
|
|
$this->assertNull($agent->profit_commission_profile_id, 'the agent applies for a plan in its own backend');
|
|
$this->assertNull($agent->profit_commission_profile_id, 'the agent applies for a plan in its own backend');
|
|
|
$application->refresh();
|
|
$application->refresh();
|
|
|
$this->assertSame('approved', $application->status);
|
|
$this->assertSame('approved', $application->status);
|
|
|
|
|
+ $this->assertSame($agent->id, (int) $application->agent_id);
|
|
|
$this->assertNull($application->password_hash); $this->assertNull($application->withdraw_password_hash);
|
|
$this->assertNull($application->password_hash); $this->assertNull($application->withdraw_password_hash);
|
|
|
$this->assertNull($application->pending_user_id); $this->assertNull($application->pending_username);
|
|
$this->assertNull($application->pending_user_id); $this->assertNull($application->pending_username);
|
|
|
$inbox = new SiteInboxService();
|
|
$inbox = new SiteInboxService();
|
|
@@ -183,17 +186,49 @@ class AgentApplicationTest extends TestCase
|
|
|
$this->assertSame(0, DB::table('site_messages')->count()); $this->assertSame(0, DB::transactionLevel());
|
|
$this->assertSame(0, DB::table('site_messages')->count()); $this->assertSame(0, DB::transactionLevel());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_existing_agents_can_be_bound_explicitly_but_identity_cannot_be_reassigned(): void
|
|
|
|
|
|
|
+ public function test_already_approved_member_cannot_open_a_second_agent_through_another_application(): void
|
|
|
{
|
|
{
|
|
|
- $agent = $this->agents->create(['username' => 'legacyagent', 'password' => 'legacy-secret']);
|
|
|
|
|
- $this->assertSame(11, $this->service->bindMember($agent, 11)->owner_user_id);
|
|
|
|
|
- $this->assertSame(11, $this->service->bindMember($agent, 11)->owner_user_id);
|
|
|
|
|
- try { $this->service->bindMember($agent, 22); $this->fail('Agent identity cannot be reassigned'); }
|
|
|
|
|
- catch (\RuntimeException $e) { $this->assertStringContainsString('已绑定', $e->getMessage()); }
|
|
|
|
|
- $another = $this->agents->create(['username' => 'anotheragent', 'password' => 'legacy-secret']);
|
|
|
|
|
- try { $this->service->bindMember($another, 11); $this->fail('One member cannot own two agents'); }
|
|
|
|
|
- catch (\RuntimeException $e) { $this->assertStringContainsString('已绑定', $e->getMessage()); }
|
|
|
|
|
- $this->assertNull($another->refresh()->owner_user_id);
|
|
|
|
|
|
|
+ $application = $this->application();
|
|
|
|
|
+ $this->assertSame(0, $this->audit($application->id)['code']);
|
|
|
|
|
+ $another = $this->application(11, 'anotheragent');
|
|
|
|
|
+ $this->assertSame('该会员已有通过的代理申请', $this->audit($another->id)['msg']);
|
|
|
|
|
+ $this->assertSame(1, Agent::count());
|
|
|
|
|
+ $this->assertSame('pending', $another->refresh()->status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_unlink_command_previews_and_only_updates_explicitly_selected_agent_owners(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $first = $this->agents->create(['username' => 'aa123', 'password' => 'legacy-secret']);
|
|
|
|
|
+ $second = $this->agents->create(['username' => 'anotheragent', 'password' => 'legacy-secret']);
|
|
|
|
|
+ DB::table('agents')->where('id', $first->id)->update(['owner_user_id' => 11]);
|
|
|
|
|
+ DB::table('agents')->where('id', $second->id)->update(['owner_user_id' => 22]);
|
|
|
|
|
+ $before = DB::table('agents')->where('id', $first->id)->first();
|
|
|
|
|
+ $users = DB::table('users')->orderBy('id')->get()->toJson();
|
|
|
|
|
+ $command = new UnlinkAgentOwners();
|
|
|
|
|
+ $command->setLaravel($this->app);
|
|
|
|
|
+ $tester = new CommandTester($command);
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertSame(0, $tester->execute([]));
|
|
|
|
|
+ $preview = $tester->getDisplay();
|
|
|
|
|
+ foreach (['检查到关联:2 条', '实际更新:0 条', 'bot_agents', 'owner_user_id', 'aa123', 'anotheragent', 'NULL'] as $value) {
|
|
|
|
|
+ $this->assertStringContainsString($value, $preview);
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->assertEquals($before, DB::table('agents')->where('id', $first->id)->first());
|
|
|
|
|
+ $this->assertSame(2, $tester->execute(['--write' => true]));
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertSame(0, $tester->execute(['--username' => 'aa123', '--write' => true]));
|
|
|
|
|
+ $this->assertStringContainsString('实际更新:1 条', $tester->getDisplay());
|
|
|
|
|
+ $this->assertStringNotContainsString('anotheragent', $tester->getDisplay());
|
|
|
|
|
+ $before->owner_user_id = null;
|
|
|
|
|
+ $this->assertEquals($before, DB::table('agents')->where('id', $first->id)->first());
|
|
|
|
|
+ $this->assertSame(22, (int) DB::table('agents')->where('id', $second->id)->value('owner_user_id'));
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertSame(0, $tester->execute(['--all' => true, '--write' => true]));
|
|
|
|
|
+ $this->assertStringContainsString('实际更新:1 条', $tester->getDisplay());
|
|
|
|
|
+ $this->assertSame(0, DB::table('agents')->whereNotNull('owner_user_id')->count());
|
|
|
|
|
+ $this->assertSame($users, DB::table('users')->orderBy('id')->get()->toJson());
|
|
|
|
|
+ $this->assertSame(0, $tester->execute(['--all' => true, '--write' => true]));
|
|
|
|
|
+ $this->assertStringContainsString('实际更新:0 条', $tester->getDisplay());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function test_listing_hides_credentials_and_unknown_member_language_gets_a_private_fallback_notice(): void
|
|
public function test_listing_hides_credentials_and_unknown_member_language_gets_a_private_fallback_notice(): void
|
|
@@ -214,7 +249,7 @@ class AgentApplicationTest extends TestCase
|
|
|
$this->request(['id' => $agent->id, 'owner_user_id' => 11, 'real_name' => 'Renamed']);
|
|
$this->request(['id' => $agent->id, 'owner_user_id' => 11, 'real_name' => 'Renamed']);
|
|
|
$response = (new \App\Http\Controllers\admin\Agent())->update(request(), $this->agents)->getData(true);
|
|
$response = (new \App\Http\Controllers\admin\Agent())->update(request(), $this->agents)->getData(true);
|
|
|
$this->assertSame(0, $response['code'], $response['msg']);
|
|
$this->assertSame(0, $response['code'], $response['msg']);
|
|
|
- $this->assertNull($response['data']['owner_user_id']);
|
|
|
|
|
|
|
+ $this->assertArrayNotHasKey('owner_user_id', $response['data']);
|
|
|
$this->assertArrayHasKey('profit_commission_profile', $response['data']);
|
|
$this->assertArrayHasKey('profit_commission_profile', $response['data']);
|
|
|
$this->assertSame('Renamed', $agent->refresh()->real_name);
|
|
$this->assertSame('Renamed', $agent->refresh()->real_name);
|
|
|
$this->assertNull($agent->owner_user_id);
|
|
$this->assertNull($agent->owner_user_id);
|