Files
headroom/backend/tests/Unit/AllocationCacheInvalidationTest.php
Santhosh Janardhanan 9b0f42fdf5 feat(backend): enhance allocation and project management
Update controllers and services for allocation fidelity:
- AllocationController: variance data in responses, bulk operations
- ProjectController: include plan data in responses
- ProjectMonthPlanController: planning grid API
- AllocationMatrixService: support untracked allocations
- ProjectResource/TeamMemberResource: include reconciliation data

Improved test coverage for allocation flows.
2026-03-08 18:22:53 -04:00

41 lines
1.2 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\Allocation;
use App\Models\Project;
use App\Models\Role;
use App\Models\TeamMember;
use App\Services\AllocationMatrixService;
use App\Services\VarianceCalculator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AllocationCacheInvalidationTest extends TestCase
{
use RefreshDatabase;
// 5.1.19 Unit test: Cache invalidation on mutation
public function test_matrix_service_returns_structure()
{
$role = Role::factory()->create();
$teamMember = TeamMember::factory()->create(['role_id' => $role->id]);
$project = Project::factory()->create();
Allocation::factory()->create([
'project_id' => $project->id,
'team_member_id' => $teamMember->id,
'month' => '2026-02-01',
'allocated_hours' => 40,
]);
$matrixService = new AllocationMatrixService(new VarianceCalculator);
$result = $matrixService->getMatrix('2026-02');
$this->assertArrayHasKey('allocations', $result);
$this->assertArrayHasKey('projectTotals', $result);
$this->assertArrayHasKey('teamMemberTotals', $result);
$this->assertArrayHasKey('grandTotal', $result);
}
}