feature: change password
This commit is contained in:
@@ -202,13 +202,13 @@ class AdminUserListStatsTest extends TestCase
|
||||
$this->assertEquals(2002, $users2->items()[0]->msnv);
|
||||
}
|
||||
|
||||
public function test_user_list_stats_filters_by_flag_send(): void
|
||||
public function test_user_list_stats_filters_by_status(): void
|
||||
{
|
||||
// 1. Create mock users
|
||||
User::create([
|
||||
'msnv' => 3001,
|
||||
'name' => 'DEV ENABLED',
|
||||
'mail' => 'enabled@example.com',
|
||||
'name' => 'DEV ACTIVE',
|
||||
'mail' => 'active@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
@@ -220,27 +220,75 @@ class AdminUserListStatsTest extends TestCase
|
||||
|
||||
User::create([
|
||||
'msnv' => 3002,
|
||||
'name' => 'DEV DISABLED',
|
||||
'mail' => 'disabled@example.com',
|
||||
'name' => 'DEV INACTIVE',
|
||||
'mail' => 'inactive@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
'status' => User::STATUS_INACTIVE,
|
||||
'card' => 10,
|
||||
'flag_send' => User::FLAG_SEND_DISABLED,
|
||||
'first_login' => User::FIRST_LOGIN_FALSE,
|
||||
]);
|
||||
|
||||
// 2. Fetch statistics via AdminService with status = '1'
|
||||
$stats = $this->adminService->getUserListWithStats('2026-07', null, '1');
|
||||
$users = collect($stats['users']->items());
|
||||
$this->assertTrue($users->contains('msnv', 3001));
|
||||
$this->assertFalse($users->contains('msnv', 3002));
|
||||
|
||||
// 3. Fetch statistics via AdminService with status = '0'
|
||||
$stats2 = $this->adminService->getUserListWithStats('2026-07', null, '0');
|
||||
$users2 = collect($stats2['users']->items());
|
||||
$this->assertTrue($users2->contains('msnv', 3002));
|
||||
$this->assertFalse($users2->contains('msnv', 3001));
|
||||
}
|
||||
|
||||
public function test_user_list_stats_filters_by_role_department_and_flag_send(): void
|
||||
{
|
||||
// 1. Create mock users
|
||||
User::create([
|
||||
'msnv' => 4001,
|
||||
'name' => 'ADMIN DEV ENABLED',
|
||||
'mail' => 'admin_dev@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_ADMIN,
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'card' => 10,
|
||||
'flag_send' => User::FLAG_SEND_ENABLED,
|
||||
'first_login' => User::FIRST_LOGIN_FALSE,
|
||||
]);
|
||||
|
||||
User::create([
|
||||
'msnv' => 4002,
|
||||
'name' => 'MEMBER HR DISABLED',
|
||||
'mail' => 'member_hr@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 2,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'card' => 10,
|
||||
'flag_send' => User::FLAG_SEND_DISABLED,
|
||||
'first_login' => User::FIRST_LOGIN_FALSE,
|
||||
]);
|
||||
|
||||
// 2. Fetch statistics via AdminService with flag_send = '1'
|
||||
$stats = $this->adminService->getUserListWithStats('2026-07', null, '1');
|
||||
// Filter by role = Admin ('1')
|
||||
$stats = $this->adminService->getUserListWithStats('2026-07', null, '1', '1');
|
||||
$users = collect($stats['users']->items());
|
||||
$this->assertTrue($users->contains('msnv', 3001));
|
||||
$this->assertFalse($users->contains('msnv', 3002));
|
||||
$this->assertTrue($users->contains('msnv', 4001));
|
||||
$this->assertFalse($users->contains('msnv', 4002));
|
||||
|
||||
// 3. Fetch statistics via AdminService with flag_send = '0'
|
||||
$stats2 = $this->adminService->getUserListWithStats('2026-07', null, '0');
|
||||
// Filter by department = HR ('2')
|
||||
$stats2 = $this->adminService->getUserListWithStats('2026-07', null, '1', null, '2');
|
||||
$users2 = collect($stats2['users']->items());
|
||||
$this->assertTrue($users2->contains('msnv', 3002));
|
||||
$this->assertFalse($users2->contains('msnv', 3001));
|
||||
$this->assertTrue($users2->contains('msnv', 4002));
|
||||
$this->assertFalse($users2->contains('msnv', 4001));
|
||||
|
||||
// Filter by flag_send = Enabled ('1')
|
||||
$stats3 = $this->adminService->getUserListWithStats('2026-07', null, '1', null, null, '1');
|
||||
$users3 = collect($stats3['users']->items());
|
||||
$this->assertTrue($users3->contains('msnv', 4001));
|
||||
$this->assertFalse($users3->contains('msnv', 4002));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PasswordValidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = User::create([
|
||||
'msnv' => 5001,
|
||||
'name' => 'Test User',
|
||||
'mail' => 'test@example.com',
|
||||
'pass' => md5('password123'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'card' => 10,
|
||||
'flag_send' => User::FLAG_SEND_ENABLED,
|
||||
'first_login' => User::FIRST_LOGIN_TRUE,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_password_change_requires_fields(): void
|
||||
{
|
||||
$res = $this->actingAs($this->user)
|
||||
->post(route('user.update_password'), [
|
||||
'password' => '',
|
||||
'password_confirmation' => '',
|
||||
]);
|
||||
|
||||
$res->assertSessionHasErrors([
|
||||
'password' => 'Mật khẩu mới không được để trống.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_password_change_requires_minimum_length(): void
|
||||
{
|
||||
$res = $this->actingAs($this->user)
|
||||
->post(route('user.update_password'), [
|
||||
'password' => '123',
|
||||
'password_confirmation' => '123',
|
||||
]);
|
||||
|
||||
$res->assertSessionHasErrors([
|
||||
'password' => 'Mật khẩu mới phải có ít nhất 6 ký tự.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_password_change_requires_confirmation_match(): void
|
||||
{
|
||||
$res = $this->actingAs($this->user)
|
||||
->post(route('user.update_password'), [
|
||||
'password' => 'newpassword123',
|
||||
'password_confirmation' => 'differentpassword',
|
||||
]);
|
||||
|
||||
$res->assertSessionHasErrors([
|
||||
'password' => 'Mật khẩu xác nhận không trùng khớp.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Administration;
|
||||
use App\Services\User\Contracts\UserServiceInterface;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SendThankCardTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private UserServiceInterface $userService;
|
||||
private User $sender;
|
||||
private User $receiver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->userService = $this->app->make(UserServiceInterface::class);
|
||||
|
||||
// Create sender and receiver
|
||||
$this->sender = User::create([
|
||||
'msnv' => 5001,
|
||||
'name' => 'Sender User',
|
||||
'mail' => 'sender@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'card' => 10,
|
||||
'flag_send' => User::FLAG_SEND_ENABLED,
|
||||
'first_login' => User::FIRST_LOGIN_FALSE,
|
||||
]);
|
||||
|
||||
$this->receiver = User::create([
|
||||
'msnv' => 5002,
|
||||
'name' => 'Receiver User',
|
||||
'mail' => 'receiver@example.com',
|
||||
'pass' => md5('password'),
|
||||
'departments' => 1,
|
||||
'role' => User::ROLE_MEMBER,
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'card' => 0,
|
||||
'flag_send' => User::FLAG_SEND_ENABLED,
|
||||
'first_login' => User::FIRST_LOGIN_FALSE,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_send_thankcards_reduces_card_balance_and_creates_records(): void
|
||||
{
|
||||
$this->userService->sendThankcards($this->sender, '5002', 3);
|
||||
|
||||
$this->sender->refresh();
|
||||
$this->assertEquals(7, $this->sender->card);
|
||||
|
||||
// Check administration records
|
||||
$this->assertDatabaseHas('administration', [
|
||||
'msnv' => 5002,
|
||||
'received' => 3,
|
||||
'sender' => 5001,
|
||||
'sent' => 0,
|
||||
'receiver' => null,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('administration', [
|
||||
'msnv' => 5001,
|
||||
'received' => 0,
|
||||
'sender' => null,
|
||||
'sent' => 3,
|
||||
'receiver' => 5002,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_controller_validates_and_stores_thankcard(): void
|
||||
{
|
||||
$this->actingAs($this->sender);
|
||||
|
||||
$response = $this->postJson(route('user.store_send'), [
|
||||
'receiver' => '5002',
|
||||
'amount' => 2,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['success' => true]);
|
||||
|
||||
$this->sender->refresh();
|
||||
$this->assertEquals(8, $this->sender->card);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user