'Admin']); Role::create(['name' => 'RH']); Role::create(['name' => 'DSI']); // Setup services Service::create(['name' => 'DSI', 'code' => 'DSI']); Service::create(['name' => 'RH', 'code' => 'RH']); } public function test_full_onboarding_workflow() { $this->withoutExceptionHandling(); $admin = User::factory()->create(); $admin->assignRole('Admin'); $rhUser = User::factory()->create(); $rhUser->assignRole('RH'); $dsiUser = User::factory()->create(); $dsiUser->assignRole('DSI'); // 1. Create Template $template = IntegrationTemplate::create(['name' => 'Test Template', 'is_active' => true]); TemplateServiceItem::create([ 'template_id' => $template->id, 'service_id' => Service::where('code', 'DSI')->first()->id, 'label' => 'Pack Info', 'is_mandatory' => true ]); // 2. Draft creation $this->actingAs($rhUser); $response = $this->post(route('integrations.store'), [ 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@example.com', 'position' => 'Dev', 'department' => 'DSI', 'arrival_date' => now()->addDays(7)->format('Y-m-d'), 'template_id' => $template->id, ]); $response->assertSessionHasNoErrors(); $response->assertStatus(302); $response->assertRedirect(); $integration = IntegrationRequest::first(); $this->assertEquals(IntegrationStatus::PendingRHValidation, $integration->status); $this->assertCount(0, $integration->serviceTasks); // 3. RH Validation $response = $this->post(route('integrations.validate-rh', $integration->id)); $integration->refresh(); $this->assertEquals(IntegrationStatus::InProgress, $integration->status); $this->assertCount(1, $integration->serviceTasks); $integration->refresh(); $this->assertEquals(IntegrationStatus::InProgress, $integration->status); $task = $integration->serviceTasks()->whereHas('service', fn($q) => $q->where('code', 'DSI'))->first(); $this->assertEquals(ServiceTaskStatus::Pending, $task->status); // 4. Service Task Processing $this->actingAs($dsiUser); // Start task $this->post(route('service-tasks.start', $task->id)); $task->refresh(); $this->assertEquals(ServiceTaskStatus::InProgress, $task->status); // Complete item $item = $task->taskItems->first(); $this->post(route('task-items.toggle', $item->id)); $item->refresh(); $this->assertTrue($item->is_completed); // Wait... InProgress logic auto-transitions to WaitingValidation if all mandatory items are done? // Let's check ServiceTaskManager.php $task->refresh(); $this->assertEquals(ServiceTaskStatus::WaitingValidation, $task->status); // Validate task $this->post(route('service-tasks.approve', $task->id)); $task->refresh(); $this->assertEquals(ServiceTaskStatus::Completed, $task->status); // 5. Global Completion $integration->refresh(); $this->assertEquals(IntegrationStatus::Completed, $integration->status); } }