Add comprehensive API documentation for the reporting endpoint: - Request/response structure - View type inference (did/is/will) - Blank vs explicit zero semantics - Status values and error responses Related to enhanced-allocation change.
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?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));
|
|
}
|
|
|
|
// 2.3 Unit test: AllocationPolicy allows untracked allocation
|
|
public function test_manager_can_create_untracked_allocations()
|
|
{
|
|
$manager = User::factory()->create(['role' => 'manager']);
|
|
|
|
// Policy should allow creating allocations (untracked is just null team_member_id)
|
|
$this->assertTrue($this->policy->create($manager));
|
|
}
|
|
}
|