This commit is contained in:
antv
2026-07-02 17:02:02 +07:00
parent 89790539b7
commit f594a45e84
17 changed files with 200 additions and 122 deletions
+38 -31
View File
@@ -25,7 +25,8 @@ class AdminUserListStatsTest extends TestCase
{
// 1. Create mock users
$userA = User::create([
'msnv' => 'USER_A',
'msnv' => 1001,
'name' => 'User A',
'mail' => 'usera@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -36,7 +37,8 @@ class AdminUserListStatsTest extends TestCase
]);
$userB = User::create([
'msnv' => 'USER_B',
'msnv' => 1002,
'name' => 'User B',
'mail' => 'userb@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -52,18 +54,18 @@ class AdminUserListStatsTest extends TestCase
// 2. Create mock transaction logs in administration table
// A sends 3 cards to B
Administration::create([
'msnv' => 'USER_A',
'msnv' => 1001,
'received' => 0,
'sender' => null,
'sent' => 3,
'receiver' => 'USER_B',
'receiver' => 1002,
'date' => $testDate,
]);
Administration::create([
'msnv' => 'USER_B',
'msnv' => 1002,
'received' => 3,
'sender' => 'USER_A',
'sender' => 1001,
'sent' => 0,
'receiver' => null,
'date' => $testDate,
@@ -77,8 +79,8 @@ class AdminUserListStatsTest extends TestCase
$topSent = $stats['topSentUser'];
// Find users in the paginated collection
$userAResult = collect($users->items())->firstWhere('msnv', 'USER_A');
$userBResult = collect($users->items())->firstWhere('msnv', 'USER_B');
$userAResult = collect($users->items())->firstWhere('msnv', 1001);
$userBResult = collect($users->items())->firstWhere('msnv', 1002);
$this->assertNotNull($userAResult);
$this->assertNotNull($userBResult);
@@ -91,17 +93,18 @@ class AdminUserListStatsTest extends TestCase
$this->assertEquals(3, $userBResult->total_received);
// Assert top users
$this->assertEquals('USER_B', $topReceived->msnv);
$this->assertEquals(1002, $topReceived->msnv);
$this->assertEquals(3, $topReceived->total_received);
$this->assertEquals('USER_A', $topSent->msnv);
$this->assertEquals(1001, $topSent->msnv);
$this->assertEquals(3, $topSent->total_sent);
}
public function test_user_transactions_history_displays_correct_records(): void
{
$userA = User::create([
'msnv' => 'USER_A',
'msnv' => 1001,
'name' => 'User A',
'mail' => 'usera@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -116,25 +119,25 @@ class AdminUserListStatsTest extends TestCase
// 1. Create a send record
Administration::create([
'msnv' => 'USER_A',
'msnv' => 1001,
'received' => 0,
'sender' => null,
'sent' => 3,
'receiver' => 'USER_B',
'receiver' => 1002,
'date' => $testDate,
]);
// 2. Create a receive record
Administration::create([
'msnv' => 'USER_A',
'msnv' => 1001,
'received' => 5,
'sender' => 'USER_C',
'sender' => 1003,
'sent' => 0,
'receiver' => null,
'date' => $testDate,
]);
$transactions = $this->adminService->getUserTransactions('USER_A', $selectedMonth);
$transactions = $this->adminService->getUserTransactions(1001, $selectedMonth);
$this->assertCount(2, $transactions->items());
@@ -145,10 +148,10 @@ class AdminUserListStatsTest extends TestCase
$this->assertNotNull($sendTx);
$this->assertNotNull($receiveTx);
$this->assertEquals('USER_B', $sendTx->receiver);
$this->assertEquals(1002, $sendTx->receiver);
$this->assertNull($sendTx->sender);
$this->assertEquals('USER_C', $receiveTx->sender);
$this->assertEquals(1003, $receiveTx->sender);
$this->assertNull($receiveTx->receiver);
}
@@ -156,7 +159,8 @@ class AdminUserListStatsTest extends TestCase
{
// 1. Create mock users
User::create([
'msnv' => 'DEV_ALPHA',
'msnv' => 2001,
'name' => 'DEV ALPHA',
'mail' => 'alpha@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -167,7 +171,8 @@ class AdminUserListStatsTest extends TestCase
]);
User::create([
'msnv' => 'DEV_BETA',
'msnv' => 2002,
'name' => 'DEV BETA',
'mail' => 'beta@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -177,26 +182,27 @@ class AdminUserListStatsTest extends TestCase
'first_login' => User::FIRST_LOGIN_FALSE,
]);
// 2. Fetch statistics via AdminService with search for 'ALPHA'
$stats = $this->adminService->getUserListWithStats('2026-07', 'ALPHA');
// 2. Fetch statistics via AdminService with search for '2001' (msnv)
$stats = $this->adminService->getUserListWithStats('2026-07', '2001');
$users = $stats['users'];
$this->assertCount(1, $users->items());
$this->assertEquals('DEV_ALPHA', $users->items()[0]->msnv);
$this->assertEquals(2001, $users->items()[0]->msnv);
// 3. Fetch statistics via AdminService with search for 'beta@example.com'
// 3. Fetch statistics via AdminService with search for 'beta@example.com' (mail)
$stats2 = $this->adminService->getUserListWithStats('2026-07', 'beta@example.com');
$users2 = $stats2['users'];
$this->assertCount(1, $users2->items());
$this->assertEquals('DEV_BETA', $users2->items()[0]->msnv);
$this->assertEquals(2002, $users2->items()[0]->msnv);
}
public function test_user_list_stats_filters_by_flag_send(): void
{
// 1. Create mock users
User::create([
'msnv' => 'DEV_ENABLED',
'msnv' => 3001,
'name' => 'DEV ENABLED',
'mail' => 'enabled@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -207,7 +213,8 @@ class AdminUserListStatsTest extends TestCase
]);
User::create([
'msnv' => 'DEV_DISABLED',
'msnv' => 3002,
'name' => 'DEV DISABLED',
'mail' => 'disabled@example.com',
'pass' => bcrypt('password'),
'role' => User::ROLE_MEMBER,
@@ -220,13 +227,13 @@ class AdminUserListStatsTest extends TestCase
// 2. Fetch statistics via AdminService with flag_send = '1'
$stats = $this->adminService->getUserListWithStats('2026-07', null, '1');
$users = collect($stats['users']->items());
$this->assertTrue($users->contains('msnv', 'DEV_ENABLED'));
$this->assertFalse($users->contains('msnv', 'DEV_DISABLED'));
$this->assertTrue($users->contains('msnv', 3001));
$this->assertFalse($users->contains('msnv', 3002));
// 3. Fetch statistics via AdminService with flag_send = '0'
$stats2 = $this->adminService->getUserListWithStats('2026-07', null, '0');
$users2 = collect($stats2['users']->items());
$this->assertTrue($users2->contains('msnv', 'DEV_DISABLED'));
$this->assertFalse($users2->contains('msnv', 'DEV_ENABLED'));
$this->assertTrue($users2->contains('msnv', 3002));
$this->assertFalse($users2->contains('msnv', 3001));
}
}