'Project Manager']); $this->user = User::factory()->create(['user_type' => 'admin']); $this->user->assignRole('Project Manager'); $this->project = Project::factory()->create([ 'completion_percentage' => 0, ]); $this->milestone = ProjectMilestone::create([ 'project_id' => $this->project->id, 'name' => 'Structural Works', 'weight_percentage' => 100, 'sort_order' => 1, ]); $this->task = Task::factory()->create([ 'project_id' => $this->project->id, 'milestone_id' => $this->milestone->id, 'status' => 'pending', 'completion_percentage' => 0, 'sort_order' => 0, ]); } /** @test */ public function reordering_task_to_completed_column_updates_status_and_project_completion() { $response = $this->actingAs($this->user) ->post(route('projects.tasks.reorder'), [ 'tasks' => [ [ 'ulid' => $this->task->ulid, 'status' => 'completed', 'sort_order' => 0, ] ] ]); $response->assertSessionHasNoErrors(); $this->assertDatabaseHas('tasks', [ 'id' => $this->task->id, 'status' => 'completed', 'completion_percentage' => 100, ]); } /** @test */ public function reordering_task_to_in_progress_column_updates_status_and_completion() { $response = $this->actingAs($this->user) ->post(route('projects.tasks.reorder'), [ 'tasks' => [ [ 'ulid' => $this->task->ulid, 'status' => 'in_progress', 'sort_order' => 0, ] ] ]); $response->assertSessionHasNoErrors(); $this->assertDatabaseHas('tasks', [ 'id' => $this->task->id, 'status' => 'in_progress', ]); } /** @test */ public function updating_task_progress_percentage_syncs_status_and_project_completion() { $response = $this->actingAs($this->user) ->put(route('projects.tasks.update', $this->task->ulid), [ 'name' => 'Updated Task Name', 'completion_percentage' => 100, ]); $response->assertSessionHasNoErrors(); $this->assertDatabaseHas('tasks', [ 'id' => $this->task->id, 'status' => 'completed', 'completion_percentage' => 100, ]); } /** @test */ public function status_transition_endpoint_updates_task_status_and_completion() { $response = $this->actingAs($this->user) ->patch(route('projects.tasks.transition', $this->task->ulid), [ 'status' => 'in_progress', ]); $response->assertSessionHasNoErrors(); $this->assertDatabaseHas('tasks', [ 'id' => $this->task->id, 'status' => 'in_progress', 'completion_percentage' => 50, ]); } }