|
|
@@ -3,9 +3,12 @@
|
|
|
namespace Tests\Integration;
|
|
|
|
|
|
use App\Http\Controllers\agent\ProfileController;
|
|
|
+use App\Models\Agent\Agent;
|
|
|
use App\Services\Agent\AgentReportService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Database\Schema\Blueprint;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Schema;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Tests\Support\AgentTestEnvironment;
|
|
|
|
|
|
@@ -51,10 +54,32 @@ class AgentDashboardTest extends TestCase
|
|
|
$this->assertSame('815.0000', $summary['company_profit'], '1000 - 150 - 25 - 10');
|
|
|
$this->assertSame('0.0000', $summary['commission_amount']);
|
|
|
$this->assertSame(0, $summary['agent_count']);
|
|
|
+ $this->assertSame('own', $summary['scope']);
|
|
|
foreach (['bet_count', 'bet_amount', 'valid_bet_amount', 'win_loss'] as $field) $this->assertArrayHasKey($field, $summary);
|
|
|
|
|
|
$request = Request::create('/agent/dashboard', 'GET', ['start_date' => '2026-09-08', 'end_date' => '2026-09-07']);
|
|
|
$request->attributes->set('agent', $agent);
|
|
|
$this->assertNotSame(0, (new ProfileController())->dashboard($request, new AgentReportService())->getData(true)['code']);
|
|
|
}
|
|
|
+
|
|
|
+ public function test_equity_agent_sees_whole_platform_excluding_demo_accounts(): void
|
|
|
+ {
|
|
|
+ if (!Schema::hasColumn('users', 'from')) Schema::table('users', fn (Blueprint $t) => $t->integer('from')->nullable());
|
|
|
+ $joint = $this->agent();
|
|
|
+ $equity = $this->agent(Agent::TYPE_EQUITY);
|
|
|
+ foreach (['a1' => [$joint->id, 1], 'a2' => [null, 1], 'a3' => [null, null], 'demo' => [null, 2]] as $memberId => [$agentId, $from]) {
|
|
|
+ DB::table('users')->insert(['member_id' => $memberId, 'username' => $memberId, 'agent_id' => $agentId, 'from' => $from, 'created_at' => now()]);
|
|
|
+ DB::table('recharges')->insert(['member_id' => $memberId, 'status' => 1, 'amount' => 100, 'created_at' => '2026-09-07 10:00:00']);
|
|
|
+ }
|
|
|
+ $summary = (new AgentReportService())->dashboard($equity, '2026-09-07', '2026-09-07');
|
|
|
+ $this->assertSame('platform', $summary['scope']);
|
|
|
+ $this->assertSame(3, $summary['member_count'], 'all real members, no demo account, regardless of agent');
|
|
|
+ $this->assertSame('300.0000', $summary['deposit_amount']);
|
|
|
+ $this->assertSame('0.0000', $summary['commission_amount']);
|
|
|
+
|
|
|
+ $own = (new AgentReportService())->dashboard($joint, '2026-09-07', '2026-09-07');
|
|
|
+ $this->assertSame(['own', 1, '100.0000'], [$own['scope'], $own['member_count'], $own['deposit_amount']]);
|
|
|
+ $rows = array_column((new AgentReportService())->reportRows(null, ['start_date' => '2026-09-07'])['list'], null, 'id');
|
|
|
+ $this->assertSame(0, $rows[$equity->id]['member_count'], 'admin agent report still counts only the equity agent\'s own members');
|
|
|
+ }
|
|
|
}
|