Implement full CRUD operations for team members with TDD approach: Backend: - TeamMemberController with REST API endpoints - TeamMemberService for business logic extraction - TeamMemberPolicy for authorization (superuser/manager access) - 14 tests passing (8 API, 6 unit tests) Frontend: - Team member list with search and status filter - Create/Edit modal with form validation - Delete confirmation with constraint checking - Currency formatting for hourly rates - Real API integration with teamMemberService Tests: - E2E tests fixed with seed data helper - All 157 tests passing (backend + frontend + E2E) Closes #22
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Models;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
use App\Models\TeamMember;
|
|
use App\Models\Role;
|
|
|
|
class TeamMemberModelTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
// 2.1.17 Unit test: TeamMember model validation
|
|
public function test_team_member_model_validation()
|
|
{
|
|
$role = Role::factory()->create();
|
|
|
|
// Test valid team member
|
|
$teamMember = TeamMember::factory()->create([
|
|
'role_id' => $role->id,
|
|
'name' => 'John Doe',
|
|
'hourly_rate' => 150.00,
|
|
'active' => true,
|
|
]);
|
|
|
|
$this->assertInstanceOf(TeamMember::class, $teamMember);
|
|
$this->assertEquals('John Doe', $teamMember->name);
|
|
$this->assertEquals('150.00', $teamMember->hourly_rate);
|
|
$this->assertTrue($teamMember->active);
|
|
$this->assertEquals($role->id, $teamMember->role_id);
|
|
|
|
// Test casts
|
|
$this->assertIsBool($teamMember->active);
|
|
$this->assertIsString($teamMember->hourly_rate);
|
|
}
|
|
|
|
public function test_team_member_has_role_relationship()
|
|
{
|
|
$role = Role::factory()->create(['name' => 'Backend Developer']);
|
|
$teamMember = TeamMember::factory()->create(['role_id' => $role->id]);
|
|
|
|
$this->assertInstanceOf(Role::class, $teamMember->role);
|
|
$this->assertEquals('Backend Developer', $teamMember->role->name);
|
|
}
|
|
}
|