feat(allocation): implement resource allocation feature
- Add AllocationController with CRUD + bulk endpoints - Add AllocationValidationService for capacity/estimate validation - Add AllocationMatrixService for optimized matrix queries - Add AllocationPolicy for authorization - Add AllocationResource for API responses - Add frontend allocationService and matrix UI - Add E2E tests for allocation matrix (20 tests) - Add unit tests for validation service and policies - Fix month format conversion (YYYY-MM to YYYY-MM-01)
This commit is contained in:
50
backend/tests/Unit/AllocationPolicyTest.php
Normal file
50
backend/tests/Unit/AllocationPolicyTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\AllocationPolicy;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AllocationPolicyTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected AllocationPolicy $policy;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->policy = new AllocationPolicy;
|
||||
}
|
||||
|
||||
// 5.1.17 Unit test: AllocationPolicy authorization
|
||||
public function test_manager_can_view_allocations()
|
||||
{
|
||||
$manager = User::factory()->create(['role' => 'manager']);
|
||||
|
||||
$this->assertTrue($this->policy->viewAny($manager));
|
||||
}
|
||||
|
||||
public function test_manager_can_create_allocations()
|
||||
{
|
||||
$manager = User::factory()->create(['role' => 'manager']);
|
||||
|
||||
$this->assertTrue($this->policy->create($manager));
|
||||
}
|
||||
|
||||
public function test_superuser_can_create_allocations()
|
||||
{
|
||||
$superuser = User::factory()->create(['role' => 'superuser']);
|
||||
|
||||
$this->assertTrue($this->policy->create($superuser));
|
||||
}
|
||||
|
||||
public function test_developer_cannot_create_allocations()
|
||||
{
|
||||
$developer = User::factory()->create(['role' => 'developer']);
|
||||
|
||||
$this->assertFalse($this->policy->create($developer));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user