Additional Changes
This commit is contained in:
121
Modules/ProjectManagement/tests/Feature/ProjectWorkflowTest.php
Normal file
121
Modules/ProjectManagement/tests/Feature/ProjectWorkflowTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ProjectManagement\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 Modules\MaterialLogistics\Models\MaterialRequisition;
|
||||
use Modules\MaterialLogistics\Models\PurchaseOrder;
|
||||
use Modules\MaterialLogistics\Models\Warehouse;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectWorkflowTest 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' => 'Standard Portland Cement',
|
||||
'sku' => 'CEM-POR-001',
|
||||
'unit' => 'bag',
|
||||
'unit_cost' => 350.00,
|
||||
'category' => 'cement',
|
||||
'type' => 'raw',
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
// Create Project (defaults to planning state because no estimates are defined)
|
||||
$this->project = Project::create([
|
||||
'name' => 'Terminal A Expansion',
|
||||
'code' => 'PRJ-2026-999',
|
||||
'status' => ProjectStatus::Planning,
|
||||
'project_type' => 'standard',
|
||||
'is_unprofitable' => false,
|
||||
'contract_value' => 100000.00,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_mr_creation_blocked_when_project_is_in_planning(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)->post(route('requisitions.store'), [
|
||||
'project_ulid' => $this->project->ulid,
|
||||
'notes' => 'Urgent materials',
|
||||
'items' => [
|
||||
[
|
||||
'material_ulid' => $this->material->ulid,
|
||||
'quantity' => 10,
|
||||
'unit_cost' => 350.00,
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$response->assertSessionHas('error');
|
||||
$this->assertDatabaseMissing('material_requisitions', [
|
||||
'project_id' => $this->project->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_mr_creation_allowed_when_project_has_estimates(): void
|
||||
{
|
||||
// Add materials estimate to project
|
||||
$this->project->materialsEstimates()->create([
|
||||
'material_id' => $this->material->id,
|
||||
'estimated_qty' => 50,
|
||||
'unit_cost' => 350.00,
|
||||
]);
|
||||
|
||||
// Add a dummy task so it progresses from 'estimated' to 'scheduled' state
|
||||
$this->project->tasks()->create([
|
||||
'name' => 'Foundation Pouring',
|
||||
'status' => 'pending',
|
||||
'labor_cost' => 0,
|
||||
'estimated_hours' => 10,
|
||||
'actual_hours' => 0,
|
||||
'completion_percentage' => 0,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$this->project->update(['current_wizard_step' => 8]);
|
||||
|
||||
$response = $this->actingAs($this->user)->post(route('requisitions.store'), [
|
||||
'project_ulid' => $this->project->ulid,
|
||||
'notes' => 'Allowed materials',
|
||||
'items' => [
|
||||
[
|
||||
'material_ulid' => $this->material->ulid,
|
||||
'quantity' => 10,
|
||||
'unit_cost' => 350.00,
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$this->assertDatabaseHas('material_requisitions', [
|
||||
'project_id' => $this->project->id,
|
||||
'notes' => 'Allowed materials',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user