Add tasks to customer jobs
Phase 1, item 7, in the Jobs module (tasks are part of a job, and my jobs needs their assignees): - Tasks with name, work type, assignees, status (waiting, in progress, in review, done), due date, estimated hours and description. - Tasks can be added once the job is a quote request or later, not to an archived job. The work type must belong to the job's service units or the shared ones and be in use; assignees must be active. What a task already has stays allowed after being taken out of use. - Job page: a Tehtävät section with a status select per task (announced, focus kept), edit links and delete with a confirmation dialog. Task form with work types grouped by unit and service. - Access: adding, changing and removing for everyone but subcontractors; subcontractors may change task statuses on jobs they are attached to. - Task assignees now count in my jobs (list, Kanban, job access). - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
||||
$this->actingAs($this->employee);
|
||||
$this->marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
|
||||
$this->job = CustomerJobModel::factory()->create(['name' => 'Kampanja', 'status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $this->marketing->id]);
|
||||
$this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
$this->planning = WorkTypeModel::query()->where('name', 'suunnittelu')->sole();
|
||||
});
|
||||
|
||||
it('adds a task with work types of the job and the shared ones on offer', function () {
|
||||
$this->get(route('jobs.tasks.create', $this->job->id))
|
||||
->assertOk()
|
||||
->assertSee('graafinen työ')
|
||||
->assertSee('suunnittelu')
|
||||
->assertDontSee('painotyö');
|
||||
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id])
|
||||
->assertSet('form.assignee_user_ids', [(string) $this->employee->id])
|
||||
->set('form.title', 'Mainoskuvat')
|
||||
->set('form.work_type_id', (string) $this->graphic->id)
|
||||
->set('form.due_on', '2026-05-20')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('jobs.show', $this->job->id).'#tasks');
|
||||
|
||||
$task = TaskModel::query()->sole();
|
||||
expect($task->work_type_id)->toBe($this->graphic->id)
|
||||
->and(DB::table('task_assignees')->where('task_id', $task->id)->pluck('user_id')->all())->toBe([$this->employee->id]);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))
|
||||
->assertSee('Mainoskuvat')
|
||||
->assertSee('graafinen työ')
|
||||
->assertSee('Eero Työntekijä');
|
||||
});
|
||||
|
||||
it('shows Finnish errors on the task form', function () {
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id])
|
||||
->call('save')
|
||||
->assertHasErrors(['form.title', 'form.work_type_id'])
|
||||
->assertSee('Anna tehtävän nimi.')
|
||||
->assertSee('Valitse työtehtävä.');
|
||||
});
|
||||
|
||||
it('does not add tasks before the job is a quote request', function () {
|
||||
$this->job->update(['status' => 'tentative']);
|
||||
|
||||
$this->get(route('jobs.tasks.create', $this->job->id))->assertNotFound();
|
||||
$this->get(route('jobs.show', $this->job->id))
|
||||
->assertSee('Tehtäviä voi lisätä, kun työ on tarjouspyyntö-tilassa')
|
||||
->assertDontSee('Lisää tehtävä');
|
||||
});
|
||||
|
||||
it('edits, changes the status of and removes a task on the job page', function () {
|
||||
$task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat']);
|
||||
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id, 'task' => $task->id])
|
||||
->assertSet('form.title', 'Mainoskuvat')
|
||||
->set('form.work_type_id', (string) $this->planning->id)
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
Livewire::test('jobs::show', ['job' => $this->job->id])
|
||||
->call('changeTaskStatus', $task->id, 'in_review')
|
||||
->assertSee('Tehtävän Mainoskuvat tila on nyt Tarkastettavana.')
|
||||
->call('confirmTaskRemoval', $task->id)
|
||||
->assertSee('Poistetaanko tehtävä Mainoskuvat?')
|
||||
->call('removeTask')
|
||||
->assertSee('Tehtävä Mainoskuvat poistettu.');
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('counts task assignees as members in my jobs', function () {
|
||||
$colleague = User::factory()->create();
|
||||
TaskModel::factory()->assignedTo([$colleague->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id]);
|
||||
|
||||
$this->actingAs($colleague);
|
||||
|
||||
Livewire::test('jobs::index')->assertSee('Kampanja');
|
||||
});
|
||||
|
||||
it('lets a subcontractor change task statuses on their jobs, but not add or change tasks', function () {
|
||||
$subcontractor = User::factory()->subcontractor()->create();
|
||||
$task = TaskModel::factory()->assignedTo([$subcontractor->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id]);
|
||||
|
||||
$this->actingAs($subcontractor);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertOk()->assertDontSee('Lisää tehtävä');
|
||||
$this->get(route('jobs.tasks.create', $this->job->id))->assertForbidden();
|
||||
$this->get(route('jobs.tasks.edit', [$this->job->id, $task->id]))->assertForbidden();
|
||||
|
||||
Livewire::test('jobs::show', ['job' => $this->job->id])
|
||||
->call('changeTaskStatus', $task->id, 'done')
|
||||
->assertHasNoErrors()
|
||||
->call('confirmTaskRemoval', $task->id)
|
||||
->assertForbidden();
|
||||
|
||||
expect($task->fresh()->status->value)->toBe('done');
|
||||
});
|
||||
|
||||
it('returns 404 for a task of another job', function () {
|
||||
$other = TaskModel::factory()->create();
|
||||
|
||||
$this->get(route('jobs.tasks.edit', [$this->job->id, $other->id]))->assertNotFound();
|
||||
});
|
||||
Reference in New Issue
Block a user