Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
97 lines
4.5 KiB
PHP
97 lines
4.5 KiB
PHP
<?php
|
|
|
|
use App\Modules\Jobs\Application\DTOs\CustomerJobData;
|
|
use App\Modules\Jobs\Application\DTOs\TemplateTaskSchedule;
|
|
use App\Modules\Jobs\Application\Services\JobDetailsFactory;
|
|
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
|
|
use App\Modules\Jobs\Application\UseCases\AddTasksFromWorkflowTemplate;
|
|
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
|
use App\Modules\Jobs\Domain\Entities\Task;
|
|
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
|
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
|
|
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
|
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
|
use App\Modules\Jobs\Domain\Exceptions\WorkflowTemplateNotAvailable;
|
|
use Tests\Fakes\FakeCatalogQueries;
|
|
use Tests\Fakes\FakeClock;
|
|
use Tests\Fakes\FakeCustomerQueries;
|
|
use Tests\Fakes\FakeTransactionManager;
|
|
use Tests\Fakes\FakeUserAccountQueries;
|
|
use Tests\Fakes\FakeWorkflowTemplateQueries;
|
|
use Tests\Fakes\InMemoryCustomerJobRepository;
|
|
use Tests\Fakes\InMemoryTaskRepository;
|
|
|
|
beforeEach(function () {
|
|
$this->jobs = new InMemoryCustomerJobRepository;
|
|
$this->tasks = new InMemoryTaskRepository;
|
|
$customers = new FakeCustomerQueries;
|
|
$catalog = new FakeCatalogQueries;
|
|
$users = new FakeUserAccountQueries;
|
|
$this->templates = new FakeWorkflowTemplateQueries;
|
|
$transactions = new FakeTransactionManager;
|
|
|
|
$customers->customers = [1 => 'Mainos Oy'];
|
|
$catalog->addServiceUnit(1, 'Mediatuotanto');
|
|
$catalog->addServiceUnit(2, 'Painotuotanto');
|
|
$catalog->addServiceUnit(9, 'Kaikille yhteiset', shared: true);
|
|
$catalog->addWorkType(11, 1, 'videokuvaus');
|
|
$catalog->addWorkType(12, 1, 'editointi');
|
|
$catalog->addWorkType(21, 2, 'painotyö');
|
|
$catalog->addWorkType(91, 9, 'suunnittelu');
|
|
$users->addUser(10, 'Eero');
|
|
|
|
$createJob = new CreateCustomerJob($this->jobs, $this->jobs, new JobDetailsFactory($customers, $catalog, $users), $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
|
$this->jobId = $createJob->execute(new CustomerJobData('Video', 1, [1], 10, 'one_off', 'quote_request', 'normal'), 10);
|
|
$this->tentativeJobId = $createJob->execute(new CustomerJobData('Alustava', 1, [1], 10, 'one_off', 'tentative', 'normal'), 10);
|
|
|
|
$this->templates->addTemplate(1, 'Lyhyt video', 11, 1, [['Suunnittelu', 91], ['Kuvaus'], ['Editointi', 12]]);
|
|
$this->templates->addTemplate(2, 'Painos', 21, 2, [['Painatus']]);
|
|
$this->templates->addTemplate(3, 'Vanha', 11, 1, [['Kuvaus']], active: false);
|
|
$this->templates->addTemplate(4, 'Rikki', 11, 1, [['Painatus', 21]]);
|
|
|
|
$this->addTasks = new AddTasksFromWorkflowTemplate($this->jobs, $this->tasks, $this->templates, new TaskReferenceChecker($catalog, $users), $transactions);
|
|
});
|
|
|
|
it('adds a waiting task per step in order, with the step work type and the adder as assignee', function () {
|
|
expect($this->addTasks->execute($this->jobId, 1, 10))->toBe(3);
|
|
|
|
$tasks = array_values($this->tasks->tasks);
|
|
|
|
expect(array_map(fn (Task $task): array => [$task->title()->value, $task->workTypeId(), $task->status(), $task->assigneeUserIds()], $tasks))->toBe([
|
|
['Suunnittelu', 91, TaskStatus::Waiting, [10]],
|
|
['Kuvaus', 11, TaskStatus::Waiting, [10]],
|
|
['Editointi', 12, TaskStatus::Waiting, [10]],
|
|
]);
|
|
});
|
|
|
|
it('rejects a template out of use or for other service units', function (int $templateId) {
|
|
$this->addTasks->execute($this->jobId, $templateId, 10);
|
|
})->with([3, 2, 999])->throws(WorkflowTemplateNotAvailable::class);
|
|
|
|
it('rejects a step whose work type is not available for the job', function () {
|
|
expect(fn () => $this->addTasks->execute($this->jobId, 4, 10))->toThrow(InvalidTaskReference::class);
|
|
});
|
|
|
|
it('adds no tasks before the job is a quote request', function () {
|
|
$this->addTasks->execute($this->tentativeJobId, 1, 10);
|
|
})->throws(TasksNotAllowedYet::class);
|
|
|
|
it('gives each task the due date and estimate entered for its step', function () {
|
|
$this->addTasks->execute($this->jobId, 1, 10, [
|
|
new TemplateTaskSchedule('2026-05-10', '1,5'),
|
|
new TemplateTaskSchedule(null, '8'),
|
|
]);
|
|
|
|
$tasks = array_values($this->tasks->tasks);
|
|
|
|
expect(array_map(fn (Task $task): array => [$task->dueOn()?->format('Y-m-d'), $task->estimatedHours()?->format()], $tasks))->toBe([
|
|
['2026-05-10', '1.5'],
|
|
[null, '8'],
|
|
[null, null],
|
|
]);
|
|
});
|
|
|
|
it('rejects an estimate that is not a number', function () {
|
|
$this->addTasks->execute($this->jobId, 1, 10, [new TemplateTaskSchedule(null, 'paljon')]);
|
|
})->throws(InvalidEstimatedHours::class);
|