Files
GSB-Construction/Modules/MaterialLogistics/tests/Feature/MaterialRequisitionPrefillTest.php
Christopher Boyles 64d4b331a8
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
Additional Changes
2026-06-02 22:04:03 +08:00

81 lines
2.5 KiB
PHP

<?php
namespace Modules\MaterialLogistics\Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Modules\ProjectManagement\Models\Project;
use Modules\ProjectManagement\Enums\ProjectStatus;
use Modules\MasterData\Models\Material;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Tests\TestCase;
class MaterialRequisitionPrefillTest extends TestCase
{
use RefreshDatabase;
protected User $user;
protected Project $project;
protected Material $material;
protected function setUp(): void
{
parent::setUp();
// Seed roles & permissions
$role = Role::firstOrCreate(['name' => 'Super Admin']);
Permission::firstOrCreate(['name' => 'projects.access']);
$this->user = User::factory()->create([
'status' => 'active',
'user_type' => 'admin',
]);
$this->user->assignRole($role);
// Standard Material
$this->material = Material::create([
'name' => 'Test Cement Bag',
'sku' => 'CEM-TST-101',
'unit' => 'bag',
'unit_cost' => 300.00,
'category' => 'cement',
'type' => 'raw',
'status' => 'active',
]);
// Create Project (step = 8, status = in_progress)
$this->project = Project::create([
'name' => 'Approved Active Project',
'code' => 'PRJ-ACT-2026',
'status' => ProjectStatus::InProgress,
'project_type' => 'standard',
'is_unprofitable' => false,
'contract_value' => 500000.00,
'current_wizard_step' => 8,
]);
// Create estimation for project
$this->project->materialsEstimates()->create([
'material_id' => $this->material->id,
'estimated_qty' => 100,
'unit_cost' => 300.00,
]);
}
public function test_can_load_requisition_create_form_with_prefilled_items(): void
{
$response = $this->actingAs($this->user)->get(route('requisitions.create', [
'project_ulid' => $this->project->ulid
]));
$response->assertStatus(200);
// Assert prefilledItems exists and contains the estimated materials
$prefilled = $response->viewData('page')['props']['prefilledItems'];
$this->assertCount(1, $prefilled);
$this->assertEquals($this->material->ulid, $prefilled[0]['material_ulid']);
$this->assertEquals(100, $prefilled[0]['quantity']);
}
}