Add the task calendar, holidays, workflow templates and customer removal
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]>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ProductModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\VatRateModel;
|
||||
@@ -20,6 +23,10 @@ it('has no accessibility issues on the catalog pages', function (string $page, s
|
||||
$workType->update(['hourly_rate_cents' => 9500]);
|
||||
$product = ProductModel::factory()->consumer()->create(['name' => 'Passikuvat', 'auto_hours' => 0.25, 'work_type_id' => WorkTypeModel::query()->where('name', 'passikuvat')->sole()->id]);
|
||||
ProductModel::factory()->inactive()->create(['name' => 'Vanha tuloste']);
|
||||
$templateId = app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData('Lyhyt video', $workType->id, [
|
||||
new WorkflowStepData('Suunnittelu', null, WorkTypeModel::query()->where('name', 'suunnittelu')->sole()->id),
|
||||
new WorkflowStepData('Kuvaus', 'Kuvauspäivä asiakkaalla'),
|
||||
]));
|
||||
|
||||
$url = match ($page) {
|
||||
'catalog' => route('catalog.index'),
|
||||
@@ -31,6 +38,9 @@ it('has no accessibility issues on the catalog pages', function (string $page, s
|
||||
'edit product' => route('catalog.products.edit', $product->id),
|
||||
'edit VAT rate' => route('catalog.vat-rates.edit', VatRateModel::query()->where('is_default', true)->value('id')),
|
||||
'read-only price list' => route('catalog.price-list'),
|
||||
'workflow templates' => route('catalog.workflow-templates'),
|
||||
'new workflow template' => route('catalog.workflow-templates.create'),
|
||||
'edit workflow template' => route('catalog.workflow-templates.edit', $templateId),
|
||||
};
|
||||
|
||||
$visit = visit($url);
|
||||
@@ -39,7 +49,7 @@ it('has no accessibility issues on the catalog pages', function (string $page, s
|
||||
|
||||
$visit->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['catalog', 'new service unit', 'new service', 'edit work type', 'price list', 'new product', 'edit product', 'edit VAT rate', 'read-only price list'])->with([
|
||||
})->with(['catalog', 'new service unit', 'new service', 'edit work type', 'price list', 'new product', 'edit product', 'edit VAT rate', 'read-only price list', 'workflow templates', 'new workflow template', 'edit workflow template'])->with([
|
||||
'desktop, light' => ['desktop', 'light'],
|
||||
'desktop, dark' => ['desktop', 'dark'],
|
||||
'mobile, light' => ['mobile', 'light'],
|
||||
@@ -96,3 +106,17 @@ it('has no accessibility issues on the price list of an employee without the pri
|
||||
'mobile, light' => ['mobile', 'light'],
|
||||
'mobile, dark' => ['mobile', 'dark'],
|
||||
]);
|
||||
|
||||
it('adds and moves workflow steps with the keyboard, keeping focus and announcing it', function () {
|
||||
visit(route('catalog.workflow-templates.create'))
|
||||
->type('#step-1-title', 'Kuvaus')
|
||||
->keys('#add-step', 'Enter')
|
||||
->assertSee('Vaihe 2 lisätty.')
|
||||
->assertScript('document.activeElement.id', 'step-2-title')
|
||||
->type('#step-2-title', 'Suunnittelu')
|
||||
->keys('#step-2-up', 'Enter')
|
||||
->assertSee('Vaihe 2 siirretty kohtaan 1.')
|
||||
->assertScript('document.activeElement.id', 'step-2-up')
|
||||
->assertScript('document.querySelector("ol input").value', 'Suunnittelu')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
});
|
||||
|
||||
@@ -137,6 +137,30 @@ it('removes a contact with the keyboard, in a dialog that keeps and returns focu
|
||||
->assertSee('Pekka');
|
||||
})->with(['light', 'dark']);
|
||||
|
||||
it('removes a customer with nothing linked to it with the keyboard, and offers no removal for one with a contact', function (string $colorScheme) {
|
||||
$empty = CustomerModel::factory()->create(['name' => 'Turha Oy']);
|
||||
$linked = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
|
||||
CustomerContactModel::factory()->create(['customer_id' => $linked->id, 'name' => 'Maija']);
|
||||
|
||||
$removeCustomer = '[wire\:click^="confirmRemoval(\'customer\'"]';
|
||||
|
||||
visit(route('customers.show', $linked->id))
|
||||
->assertSee('Maija')
|
||||
->assertDontSee('Poista asiakas');
|
||||
|
||||
$page = visit(route('customers.show', $empty->id));
|
||||
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
|
||||
|
||||
// Removed: the dialog takes focus, then the list shows a status message.
|
||||
$page->keys($removeCustomer, 'Enter')
|
||||
->assertSee('Poistetaanko asiakas Turha Oy?')
|
||||
->assertScript('document.getElementById("remove-dialog").contains(document.activeElement)', true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->click('#remove-dialog [wire\:click="remove"]')
|
||||
->assertSee('Asiakas Turha Oy poistettu.')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['light', 'dark']);
|
||||
|
||||
it('has no accessibility issues with a consumer\'s personal identity code', function (string $page, string $device, string $colorScheme) {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
$consumer = CustomerModel::factory()->consumer()->create([
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
@@ -229,3 +232,34 @@ it('adds, checks, renames, moves and removes checklist items with the keyboard',
|
||||
->assertScript('document.activeElement.id', 'checklist-new-'.$task->id)
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
});
|
||||
|
||||
it('adds tasks from a workflow template with the keyboard, without accessibility issues', function (string $device, string $colorScheme) {
|
||||
$this->job->update(['status' => 'order']);
|
||||
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
|
||||
$templateId = app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData('Lyhyt video', $workType->id, [
|
||||
new WorkflowStepData('Suunnittelu', null, WorkTypeModel::query()->where('name', 'suunnittelu')->sole()->id),
|
||||
new WorkflowStepData('Kuvaus'),
|
||||
]));
|
||||
|
||||
$visit = visit(route('jobs.tasks.from-template', $this->job->id));
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->keys('[value="'.$templateId.'"]', 'Space')
|
||||
->assertSee('Pohjan Lyhyt video tehtävät')
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->type('#row-1-hours', '2,5')
|
||||
->keys('main form button[type="submit"]', 'Enter')
|
||||
->assertSee('Lisättiin 2 tehtävää pohjasta Lyhyt video (videokuvaus).')
|
||||
->assertSee('Suunnittelu')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
|
||||
expect(TaskModel::query()->where('customer_job_id', $this->job->id)->orderBy('id')->pluck('estimated_hours')->map(fn ($hours) => $hours === null ? null : (float) $hours)->all())->toBe([null, 2.5]);
|
||||
})->with([
|
||||
'desktop, light' => ['desktop', 'light'],
|
||||
'desktop, dark' => ['desktop', 'dark'],
|
||||
'mobile, light' => ['mobile', 'light'],
|
||||
'mobile, dark' => ['mobile', 'dark'],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
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;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->management()->create(['name' => 'Johanna Johto']);
|
||||
$this->other = User::factory()->create(['name' => 'Aino Ahkera']);
|
||||
$this->actingAs($this->user);
|
||||
$job = CustomerJobModel::factory()->create(['name' => 'Messuvideo', 'status' => 'order', 'responsible_user_id' => $this->user->id]);
|
||||
$workType = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
|
||||
$this->task = TaskModel::factory()->assignedTo([$this->user->id])->create([
|
||||
'customer_job_id' => $job->id,
|
||||
'work_type_id' => $workType->id,
|
||||
'title' => 'Leikkaus',
|
||||
'estimated_hours' => 4,
|
||||
'due_on' => now()->addDay()->toDateString(),
|
||||
'planned_from' => now()->toDateString(),
|
||||
'planned_to' => now()->addDays(2)->toDateString(),
|
||||
]);
|
||||
TaskModel::factory()->assignedTo([$this->other->id])->create(['customer_job_id' => $job->id, 'work_type_id' => $workType->id, 'title' => 'Värimäärittely']);
|
||||
});
|
||||
|
||||
it('has no accessibility issues on the task calendar', function (string $device, string $colorScheme) {
|
||||
$visit = visit(route('jobs.calendar'));
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertNoJavaScriptErrors()
|
||||
->assertSee('Leikkaus')
|
||||
->assertSee('Värimäärittely')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with([
|
||||
'desktop, light' => ['desktop', 'light'],
|
||||
'desktop, dark' => ['desktop', 'dark'],
|
||||
'mobile, light' => ['mobile', 'light'],
|
||||
'mobile, dark' => ['mobile', 'dark'],
|
||||
]);
|
||||
|
||||
it('reschedules a task with the keyboard and returns focus to its bar', function () {
|
||||
$key = $this->task->id.'-'.$this->user->id;
|
||||
|
||||
visit(route('jobs.calendar'))
|
||||
->on()->desktop()
|
||||
->keys('#bar-'.$key, 'Enter')
|
||||
->assertSee('Tehtävän aikataulu')
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->type('#task-schedule-dialog [wire\:model="plannedFrom"]', now()->addDay()->format('Y-m-d'))
|
||||
->type('#task-schedule-dialog [wire\:model="plannedTo"]', now()->addDays(3)->format('Y-m-d'))
|
||||
->press('#task-schedule-dialog [wire\:click="saveDialog"]')
|
||||
->assertSee('Tehtävä Leikkaus: Johanna Johto '.now()->addDay()->format('j.n.Y').'–'.now()->addDays(3)->format('j.n.Y').'.')
|
||||
->assertScript('document.activeElement.id', 'bar-'.$key);
|
||||
|
||||
expect($this->task->refresh()->planned_from?->format('Y-m-d'))->toBe(now()->addDay()->toDateString());
|
||||
});
|
||||
|
||||
it('moves a task to another person by dragging its bar', function () {
|
||||
// The bar (today – today + 2) is grabbed at its middle day, so dropping it
|
||||
// on today + 4 moves it three days later.
|
||||
$day = now()->addDays(4)->toDateString();
|
||||
|
||||
visit(route('jobs.calendar'))
|
||||
->on()->desktop()
|
||||
->drag('#bar-'.$this->task->id.'-'.$this->user->id, '[data-calendar-day="'.$day.'"][data-calendar-user="'.$this->other->id.'"]')
|
||||
->assertSee('Tehtävä Leikkaus: Aino Ahkera');
|
||||
|
||||
expect($this->task->refresh()->planned_from?->format('Y-m-d'))->toBe(now()->addDays(3)->toDateString())
|
||||
->and(DB::table('task_assignees')->where('task_id', $this->task->id)->pluck('user_id')->all())->toBe([$this->other->id]);
|
||||
});
|
||||
|
||||
it('has no accessibility issues on the holidays page', function (string $colorScheme) {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
$visit = visit(route('settings.holidays'));
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertNoJavaScriptErrors()
|
||||
->assertSee('Itsenäisyyspäivä')
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['light', 'dark']);
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Customers\Application\Contracts\CustomerReferences;
|
||||
|
||||
class FakeCustomerReferences implements CustomerReferences
|
||||
{
|
||||
/**
|
||||
* @var list<int>
|
||||
*/
|
||||
public array $referencedIds = [];
|
||||
|
||||
public function refersTo(int $customerId): bool
|
||||
{
|
||||
return in_array($customerId, $this->referencedIds, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepSummary;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateSummary;
|
||||
|
||||
class FakeWorkflowTemplateQueries implements WorkflowTemplateQueries
|
||||
{
|
||||
/** @var array<int, WorkflowTemplateDetails> */
|
||||
public array $templates = [];
|
||||
|
||||
/**
|
||||
* @param list<array{0: string, 1?: int|null}> $steps Title and the step's own work type.
|
||||
*/
|
||||
public function addTemplate(int $id, string $name, int $workTypeId, int $serviceUnitId, array $steps, bool $active = true): void
|
||||
{
|
||||
$this->templates[$id] = new WorkflowTemplateDetails(
|
||||
$id,
|
||||
$name,
|
||||
$workTypeId,
|
||||
'työtehtävä '.$workTypeId,
|
||||
$serviceUnitId,
|
||||
$active,
|
||||
array_map(fn (array $step): WorkflowStepSummary => new WorkflowStepSummary(
|
||||
$step[0],
|
||||
null,
|
||||
$step[1] ?? null,
|
||||
$step[1] ?? $workTypeId,
|
||||
'työtehtävä '.($step[1] ?? $workTypeId),
|
||||
), $steps),
|
||||
);
|
||||
}
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
return array_values(array_map(fn (WorkflowTemplateDetails $template): WorkflowTemplateSummary => new WorkflowTemplateSummary(
|
||||
$template->id,
|
||||
$template->name,
|
||||
$template->workTypeId,
|
||||
$template->workTypeName,
|
||||
$template->serviceUnitId,
|
||||
'yksikkö '.$template->serviceUnitId,
|
||||
$template->isActive,
|
||||
count($template->steps),
|
||||
), $this->templates));
|
||||
}
|
||||
|
||||
public function find(int $id): ?WorkflowTemplateDetails
|
||||
{
|
||||
return $this->templates[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit 9 plays the shared unit.
|
||||
*/
|
||||
public function activeFor(array $serviceUnitIds): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->templates,
|
||||
fn (WorkflowTemplateDetails $template): bool => $template->isActive
|
||||
&& (in_array($template->serviceUnitId, $serviceUnitIds, true) || $template->serviceUnitId === 9),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,15 @@ class InMemoryBillingUnitRepository implements BillingUnitRepository
|
||||
{
|
||||
unset($this->billingUnits[$billingUnit->id()]);
|
||||
}
|
||||
|
||||
public function existsForCustomer(int $customerId): bool
|
||||
{
|
||||
foreach ($this->billingUnits as $billingUnit) {
|
||||
if ($billingUnit->customerId() === $customerId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,15 @@ class InMemoryCustomerContactRepository implements CustomerContactRepository
|
||||
{
|
||||
unset($this->contacts[$contact->id()]);
|
||||
}
|
||||
|
||||
public function existsForCustomer(int $customerId): bool
|
||||
{
|
||||
foreach ($this->contacts as $contact) {
|
||||
if ($contact->customerId() === $customerId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ class InMemoryCustomerRepository implements CustomerRepository
|
||||
return clone $stored;
|
||||
}
|
||||
|
||||
public function delete(Customer $customer): void
|
||||
{
|
||||
unset($this->customers[$customer->id()]);
|
||||
}
|
||||
|
||||
public function isPersonalIdentityCodeTaken(PersonalIdentityCode $code, ?int $exceptCustomerId = null): bool
|
||||
{
|
||||
foreach ($this->customers as $id => $customer) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Shared\Application\Contracts\HolidayOverrides;
|
||||
use App\Modules\Shared\Application\DTOs\HolidayOverride;
|
||||
|
||||
class InMemoryHolidayOverrides implements HolidayOverrides
|
||||
{
|
||||
/** @var array<string, HolidayOverride> */
|
||||
public array $overrides = [];
|
||||
|
||||
public function between(string $from, string $to): array
|
||||
{
|
||||
ksort($this->overrides);
|
||||
|
||||
return array_values(array_filter($this->overrides, fn (HolidayOverride $override): bool => $override->date >= $from && $override->date <= $to));
|
||||
}
|
||||
|
||||
public function find(string $date): ?HolidayOverride
|
||||
{
|
||||
return $this->overrides[$date] ?? null;
|
||||
}
|
||||
|
||||
public function save(HolidayOverride $override): void
|
||||
{
|
||||
$this->overrides[$override->date] = $override;
|
||||
}
|
||||
|
||||
public function delete(string $date): void
|
||||
{
|
||||
unset($this->overrides[$date]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskBookingRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
class InMemoryTaskBookingRepository implements TaskBookingRepository
|
||||
{
|
||||
/** @var array<int, array<int, array<string, int>>> task id => user id => day => minutes */
|
||||
public array $bookings = [];
|
||||
|
||||
public function __construct(private InMemoryTaskRepository $tasks) {}
|
||||
|
||||
public function replaceFor(int $taskId, int $userId, array $minutesByDay): void
|
||||
{
|
||||
$this->bookings[$taskId][$userId] = array_filter($minutesByDay, fn (int $minutes): bool => $minutes > 0);
|
||||
}
|
||||
|
||||
public function deleteForTask(int $taskId, array $keepUserIds = []): void
|
||||
{
|
||||
foreach (array_keys($this->bookings[$taskId] ?? []) as $userId) {
|
||||
if (! in_array($userId, $keepUserIds, true)) {
|
||||
unset($this->bookings[$taskId][$userId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function otherOpenMinutes(int $userId, string $from, string $to, int $exceptTaskId): array
|
||||
{
|
||||
$minutes = [];
|
||||
|
||||
foreach ($this->bookings as $taskId => $users) {
|
||||
if ($taskId === $exceptTaskId || ($this->tasks->tasks[$taskId] ?? null)?->status() === TaskStatus::Done) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($users[$userId] ?? [] as $day => $booked) {
|
||||
if ($day >= $from && $day <= $to) {
|
||||
$minutes[$day] = ($minutes[$day] ?? 0) + $booked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($minutes);
|
||||
|
||||
return $minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function of(int $taskId, int $userId): array
|
||||
{
|
||||
$days = $this->bookings[$taskId][$userId] ?? [];
|
||||
ksort($days);
|
||||
|
||||
return $days;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ class InMemoryTaskRepository implements TaskRepository
|
||||
$task->estimatedHours(),
|
||||
$task->assigneeUserIds(),
|
||||
$task->createdBy(),
|
||||
$task->plannedFrom(),
|
||||
$task->plannedTo(),
|
||||
);
|
||||
|
||||
return clone $this->tasks[$id];
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Modules\Catalog\Domain\Contracts\WorkflowTemplateRepository;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkflowTemplate;
|
||||
|
||||
class InMemoryWorkflowTemplateRepository implements WorkflowTemplateRepository
|
||||
{
|
||||
/** @var array<int, WorkflowTemplate> */
|
||||
public array $items = [];
|
||||
|
||||
private int $nextId = 1;
|
||||
|
||||
public function findById(int $id): ?WorkflowTemplate
|
||||
{
|
||||
return isset($this->items[$id]) ? clone $this->items[$id] : null;
|
||||
}
|
||||
|
||||
public function save(WorkflowTemplate $template): WorkflowTemplate
|
||||
{
|
||||
$id = $template->id() ?? $this->nextId++;
|
||||
$this->items[$id] = WorkflowTemplate::reconstitute($id, $template->workTypeId(), $template->name(), $template->isActive(), $template->steps());
|
||||
|
||||
return clone $this->items[$id];
|
||||
}
|
||||
|
||||
public function isNameTaken(int $workTypeId, string $name, ?int $exceptId = null): bool
|
||||
{
|
||||
foreach ($this->items as $id => $template) {
|
||||
if ($id !== $exceptId && $template->workTypeId() === $workTypeId && mb_strtolower($template->name()->value) === mb_strtolower($name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
$this->workType = fn (string $name, string $unit = 'Mediatuotanto', ?string $service = 'Videotuotanto') => WorkTypeModel::query()
|
||||
->where('name', $name)
|
||||
->where('service_unit_id', ServiceUnitModel::query()->where('name', $unit)->sole()->id)
|
||||
->where('service_id', $service === null ? null : ServiceModel::query()->where('name', $service)->sole()->id)
|
||||
->sole();
|
||||
$this->videography = ($this->workType)('videokuvaus');
|
||||
$this->editing = ($this->workType)('editointi');
|
||||
$this->planning = ($this->workType)('suunnittelu', 'Kaikille yhteiset', null);
|
||||
|
||||
$this->addTemplate = fn (string $name, int $workTypeId, array $steps): int => app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
));
|
||||
});
|
||||
|
||||
it('shows the template pages to admins and management only', function (string $role, int $status) {
|
||||
$this->actingAs(User::factory()->{$role}()->create());
|
||||
|
||||
$this->get(route('catalog.workflow-templates'))->assertStatus($status);
|
||||
$this->get(route('catalog.workflow-templates.create'))->assertStatus($status);
|
||||
})->with([
|
||||
'admin' => ['admin', 200],
|
||||
'management' => ['management', 200],
|
||||
'employee' => ['employee', 403],
|
||||
'subcontractor' => ['subcontractor', 403],
|
||||
]);
|
||||
|
||||
it('links the templates from the catalog page', function () {
|
||||
$this->get(route('catalog.index'))->assertSee(route('catalog.workflow-templates'));
|
||||
});
|
||||
|
||||
it('adds a template with steps added, moved and removed on the form', function () {
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'Lyhyt video')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->assertSee('editointi')
|
||||
->assertSee('suunnittelu')
|
||||
->set('form.steps.0.title', 'Kuvaus')
|
||||
->call('addStep')
|
||||
->assertSee('Vaihe 2 lisätty.')
|
||||
->set('form.steps.1.title', 'Suunnittelu')
|
||||
->set('form.steps.1.work_type_id', (string) $this->planning->id)
|
||||
->call('moveStep', 1, 'up')
|
||||
->assertSee('Vaihe 2 siirretty kohtaan 1.')
|
||||
->call('addStep')
|
||||
->set('form.steps.2.title', 'Turha')
|
||||
->call('removeStep', 2)
|
||||
->assertSee('Vaihe 3 poistettu.')
|
||||
->call('addStep')
|
||||
->set('form.steps.2.title', 'Editointi')
|
||||
->set('form.steps.2.work_type_id', (string) $this->editing->id)
|
||||
->set('form.steps.2.description', 'Leikkaus ja värimäärittely')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('catalog.workflow-templates'));
|
||||
|
||||
$template = app(WorkflowTemplateQueries::class)->all()[0];
|
||||
$details = app(WorkflowTemplateQueries::class)->find($template->id);
|
||||
|
||||
expect($template->name)->toBe('Lyhyt video')
|
||||
->and($template->workTypeName)->toBe('videokuvaus')
|
||||
->and($template->serviceUnitName)->toBe('Mediatuotanto')
|
||||
->and($template->stepCount)->toBe(3)
|
||||
->and(array_map(fn ($step) => [$step->title, $step->workTypeId, $step->effectiveWorkTypeId, $step->workTypeName, $step->description], $details->steps))->toBe([
|
||||
['Suunnittelu', $this->planning->id, $this->planning->id, 'suunnittelu', null],
|
||||
['Kuvaus', null, $this->videography->id, 'videokuvaus', null],
|
||||
['Editointi', $this->editing->id, $this->editing->id, 'editointi', 'Leikkaus ja värimäärittely'],
|
||||
]);
|
||||
|
||||
$this->get(route('catalog.workflow-templates'))->assertSee('Lyhyt video')->assertSee('videokuvaus');
|
||||
});
|
||||
|
||||
it('shows Finnish errors on the right fields', function () {
|
||||
($this->addTemplate)('Lyhyt video', $this->videography->id, [['Kuvaus']]);
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.name', 'form.work_type_id', 'form.steps.0.title'])
|
||||
->assertSee('Anna nimi.')
|
||||
->assertSee('Valitse työtehtävä.')
|
||||
->assertSee('Anna tehtävän nimi.');
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'lyhyt video')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->set('form.steps.0.title', 'Kuvaus')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.name'])
|
||||
->assertSee('Työtehtävällä on jo tämänniminen pohja.');
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'Video ja grafiikka')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->set('form.steps.0.title', 'Grafiikka')
|
||||
->set('form.steps.0.work_type_id', (string) ($this->workType)('graafinen työ', 'Markkinointi', null)->id)
|
||||
->call('save')
|
||||
->assertHasErrors(['form.steps.0.work_type_id'])
|
||||
->assertSee('Valitse käytössä oleva työtehtävä pohjan palveluyksiköstä tai kaikille yhteisistä.');
|
||||
});
|
||||
|
||||
it('edits a template and keeps tasks offered only while it is in use', function () {
|
||||
$id = ($this->addTemplate)('Lyhyt video', $this->videography->id, [['Kuvaus'], ['Editointi', null, $this->editing->id]]);
|
||||
|
||||
Livewire::test('catalog::workflow-template-form', ['template' => $id])
|
||||
->assertSet('form.name', 'Lyhyt video')
|
||||
->assertSet('form.steps.1.work_type_id', (string) $this->editing->id)
|
||||
->call('removeStep', 0)
|
||||
->set('form.name', 'Pelkkä editointi')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(array_map(fn ($step) => $step->title, app(WorkflowTemplateQueries::class)->find($id)->steps))->toBe(['Editointi']);
|
||||
|
||||
$media = ServiceUnitModel::query()->where('name', 'Mediatuotanto')->sole()->id;
|
||||
$marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole()->id;
|
||||
|
||||
expect(array_map(fn ($template) => $template->name, app(WorkflowTemplateQueries::class)->activeFor([$media])))->toBe(['Pelkkä editointi'])
|
||||
->and(app(WorkflowTemplateQueries::class)->activeFor([$marketing]))->toBe([]);
|
||||
|
||||
Livewire::test('catalog::workflow-templates')
|
||||
->call('toggleActive', $id)
|
||||
->assertSee('Pelkkä editointi poistettu käytöstä.');
|
||||
|
||||
expect(app(WorkflowTemplateQueries::class)->activeFor([$media]))->toBe([]);
|
||||
});
|
||||
|
||||
it('offers shared work type templates to every job', function () {
|
||||
($this->addTemplate)('Työpaja', $this->planning->id, [['Valmistelu'], ['Työpaja']]);
|
||||
|
||||
$marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole()->id;
|
||||
|
||||
expect(array_map(fn ($template) => $template->name, app(WorkflowTemplateQueries::class)->activeFor([$marketing])))->toBe(['Työpaja']);
|
||||
});
|
||||
|
||||
it('returns 404 for an unknown template', function () {
|
||||
$this->get(route('catalog.workflow-templates.edit', 999))->assertNotFound();
|
||||
});
|
||||
|
||||
it('locks the template id', function () {
|
||||
Livewire::test('catalog::workflow-template-form')->set('templateId', 1);
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
@@ -5,6 +5,8 @@ use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\BillingUnitModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerContactModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Sales\Infrastructure\Persistence\Eloquent\QuickSaleModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
@@ -184,3 +186,73 @@ it('deletes the contacts and billing units of a deleted customer', function () {
|
||||
expect(CustomerContactModel::query()->count())->toBe(0)
|
||||
->and(BillingUnitModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('removes a customer that has nothing linked to it and returns to the list', function () {
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $this->customer->id)
|
||||
->assertSee('Poistetaanko asiakas Mainos Oy?')
|
||||
->call('remove')
|
||||
->assertRedirect(route('customers.index'));
|
||||
|
||||
expect($this->customer->fresh())->toBeNull()
|
||||
->and(session('status'))->toBe('Asiakas Mainos Oy poistettu.');
|
||||
});
|
||||
|
||||
it('keeps a customer that has a contact or a customer job and tells why', function (string $link) {
|
||||
match ($link) {
|
||||
'contact' => CustomerContactModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
};
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $this->customer->id)
|
||||
->call('remove')
|
||||
->assertNoRedirect()
|
||||
->assertSee('Asiakasta Mainos Oy ei poistettu');
|
||||
|
||||
expect($this->customer->fresh())->not->toBeNull();
|
||||
})->with(['contact', 'customer job']);
|
||||
|
||||
it('has no remove button for the internal customer and does not remove it', function () {
|
||||
$internal = CustomerModel::query()->where('is_internal', true)->sole();
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $internal->id])
|
||||
->assertDontSee('Poista asiakas')
|
||||
->call('confirmRemoval', 'customer', $internal->id)
|
||||
->call('remove')
|
||||
->assertSee('Sisäistä asiakasta ei voi poistaa.');
|
||||
|
||||
expect($internal->fresh())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('does not remove another customer than the one on the page', function () {
|
||||
$other = CustomerModel::factory()->create();
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $other->id)
|
||||
->assertSet('removalId', null)
|
||||
->call('remove');
|
||||
|
||||
expect($other->fresh())->not->toBeNull()
|
||||
->and($this->customer->fresh())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('shows the remove customer button only when nothing is linked to the customer', function (?string $link) {
|
||||
match ($link) {
|
||||
null => null,
|
||||
'contact' => CustomerContactModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'billing unit' => BillingUnitModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
};
|
||||
|
||||
$page = Livewire::test('customers::show', ['customer' => $this->customer->id]);
|
||||
|
||||
$link === null ? $page->assertSee('Poista asiakas') : $page->assertDontSee('Poista asiakas');
|
||||
})->with([
|
||||
'nothing' => [null],
|
||||
'contact' => ['contact'],
|
||||
'billing unit' => ['billing unit'],
|
||||
'customer job' => ['customer job'],
|
||||
'quick sale' => ['quick sale'],
|
||||
]);
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerReferences;
|
||||
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
||||
use App\Modules\Customers\Domain\Entities\Customer;
|
||||
use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Customers\Domain\Exceptions\CustomerInUse;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Sales\Infrastructure\Persistence\Eloquent\QuickSaleModel;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -55,3 +61,46 @@ it('returns summaries filtered by name or business id, ordered by name', functio
|
||||
->and($queries->paginate(null)->total())->toBe(4) // and the internal customer
|
||||
->and($queries->search('100%'))->toBe([]);
|
||||
});
|
||||
|
||||
it('deletes a customer that nothing refers to', function () {
|
||||
$repository = app(CustomerRepository::class);
|
||||
$customer = $repository->save(Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company));
|
||||
|
||||
$repository->delete($customer);
|
||||
|
||||
expect($repository->findById((int) $customer->id()))->toBeNull();
|
||||
});
|
||||
|
||||
it('refuses to delete a customer that a customer job or a quick sale refers to', function (string $reference) {
|
||||
$customer = CustomerModel::factory()->create();
|
||||
|
||||
match ($reference) {
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $customer->id]),
|
||||
};
|
||||
|
||||
$repository = app(CustomerRepository::class);
|
||||
|
||||
expect(fn () => $repository->delete($repository->findById($customer->id)))->toThrow(CustomerInUse::class)
|
||||
->and($customer->fresh())->not->toBeNull();
|
||||
})->with(['customer job', 'quick sale']);
|
||||
|
||||
it('tells whether customer jobs, quick sales or invoices refer to a customer', function (string $reference) {
|
||||
$customer = CustomerModel::factory()->create();
|
||||
$references = app(CustomerReferences::class);
|
||||
|
||||
expect($references->refersTo($customer->id))->toBeFalse();
|
||||
|
||||
match ($reference) {
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'invoice' => DB::table('billing_invoices')->insert([
|
||||
'billing_export_id' => DB::table('billing_exports')->insertGetId(['status' => 'draft', 'created_by' => User::factory()->create()->id, 'created_at' => now(), 'updated_at' => now()]),
|
||||
'customer_id' => $customer->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]),
|
||||
};
|
||||
|
||||
expect($references->refersTo($customer->id))->toBeTrue();
|
||||
})->with(['customer job', 'quick sale', 'invoice']);
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?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->travelTo(new DateTimeImmutable('2026-12-21 09:00'));
|
||||
|
||||
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
||||
$this->other = User::factory()->create(['name' => 'Aino Ahkera']);
|
||||
$this->actingAs($this->employee);
|
||||
$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' => $marketing->id]);
|
||||
$this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
});
|
||||
|
||||
function calendarTaskModel(array $attributes, array $assignees): TaskModel
|
||||
{
|
||||
return TaskModel::factory()->assignedTo($assignees)->create($attributes);
|
||||
}
|
||||
|
||||
it('shows the two weeks from today with holidays, rows and bars', function () {
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-23'], [test()->other->id]);
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Ilman aikataulua'], [test()->employee->id]);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Tehtäväkalenteri')
|
||||
->assertSee('21.12.2026–3.1.2027')
|
||||
->assertSee('Jouluaatto')
|
||||
->assertSee('Uudenvuodenpäivä')
|
||||
->assertSeeInOrder(['Eero Työntekijä', 'Aino Ahkera', 'Ei tekijää'])
|
||||
->assertSee('Mainoskuvat')
|
||||
->assertSee('Aikatauluttamattomat tehtävät')
|
||||
->assertSee('Ilman aikataulua');
|
||||
});
|
||||
|
||||
it('moves a task to another person by dropping it and books their days', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'estimated_hours' => 12], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->other->id, '2026-12-28', null)
|
||||
->assertSee('Tehtävä Mainoskuvat: Aino Ahkera 28.12.2026–29.12.2026.');
|
||||
|
||||
expect($task->refresh()->planned_from?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and($task->planned_to?->format('Y-m-d'))->toBe('2026-12-29')
|
||||
->and(DB::table('task_assignees')->where('task_id', $task->id)->pluck('user_id')->all())->toBe([$this->other->id])
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 360, '2026-12-29' => 360]);
|
||||
});
|
||||
|
||||
it('continues a task on the next working day when the day is full', function () {
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Kuvaus', 'estimated_hours' => 6], [$this->employee->id]);
|
||||
$first = TaskModel::query()->sole();
|
||||
Livewire::test('jobs::calendar')->call('reschedule', $first->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23');
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Taitto', 'estimated_hours' => 4], [$this->employee->id]);
|
||||
|
||||
// 24.–27.12. are holidays and a weekend, so the rest goes to Monday.
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23')
|
||||
->assertSee('Päivät olivat täynnä, joten tehtävä jatkuu 28.12.2026 asti.')
|
||||
->assertSee('8 / 8 h');
|
||||
|
||||
expect($task->refresh()->planned_to?->format('Y-m-d'))->toBe('2026-12-28');
|
||||
});
|
||||
|
||||
it('changes the schedule and status in the dialog and takes a task out of the calendar', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->assertSet('plannedFrom', '2026-12-22')
|
||||
->set('plannedFrom', '2026-12-29')
|
||||
->set('plannedTo', '2026-12-28')
|
||||
->call('saveDialog')
|
||||
->assertHasErrors('plannedTo')
|
||||
->set('plannedTo', '2026-12-30')
|
||||
->set('status', 'in_progress')
|
||||
->call('saveDialog')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Tehtävän Mainoskuvat tila on nyt Työn alla.')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->call('clearSchedule')
|
||||
->assertSee('Tehtävän Mainoskuvat aikataulu poistettu.');
|
||||
|
||||
expect($task->refresh()->status->value)->toBe('in_progress')
|
||||
->and($task->planned_from)->toBeNull();
|
||||
});
|
||||
|
||||
it('shows a subcontractor only their own row and lets them change only the status', function () {
|
||||
$subcontractor = User::factory()->subcontractor()->create(['name' => 'Ville Alihankkija']);
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
$own = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Oma tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$subcontractor->id]);
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Toisen tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
$this->actingAs($subcontractor);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Oma tehtävä')
|
||||
->assertDontSee('Toisen tehtävä')
|
||||
->assertDontSee('Eero Työntekijä')
|
||||
->assertDontSee('Ei tekijää');
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $own->id, $this->job->id, $subcontractor->id, $subcontractor->id, '2026-12-28', null)
|
||||
->assertForbidden();
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $own->id, $subcontractor->id)
|
||||
->set('status', 'done')
|
||||
->call('saveDialog')
|
||||
->assertSee('Tehtävän Oma tehtävä tila on nyt Valmis.');
|
||||
|
||||
expect($own->refresh()->status->value)->toBe('done')
|
||||
->and($own->planned_from?->format('Y-m-d'))->toBe('2026-12-22');
|
||||
});
|
||||
|
||||
it('adds a schedule on the task form', function () {
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id])
|
||||
->set('form.title', 'Mainoskuvat')
|
||||
->set('form.work_type_id', (string) $this->graphic->id)
|
||||
->set('form.estimated_hours', '4')
|
||||
->set('form.planned_from', '2026-12-28')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$task = TaskModel::query()->sole();
|
||||
|
||||
expect($task->planned_to?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->sum('minutes'))->toBe(240);
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Application\UseCases\SetWorkflowTemplateActive;
|
||||
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\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
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();
|
||||
$printing = WorkTypeModel::query()->where('name', 'painotyö')->sole();
|
||||
|
||||
$add = fn (string $name, int $workTypeId, array $steps): int => app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
));
|
||||
|
||||
$this->campaign = $add('Somekampanja', $this->graphic->id, [['Suunnittelu', 'Kohderyhmä ja viestit', $this->planning->id], ['Kuvat'], ['Julkaisu']]);
|
||||
$this->print = $add('Esite', $printing->id, [['Painatus']]);
|
||||
});
|
||||
|
||||
it('adds the steps of a template as tasks of the job', function () {
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee(route('jobs.tasks.from-template', $this->job->id));
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertSee('Somekampanja (graafinen työ)')
|
||||
->assertSee('Vaiheet: Suunnittelu (suunnittelu) → Kuvat → Julkaisu')
|
||||
->assertDontSee('Esite')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->call('add')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('jobs.show', $this->job->id).'#tasks');
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->work_type_id, $task->status->value, $task->description])->all())->toBe([
|
||||
['Suunnittelu', $this->planning->id, 'waiting', 'Kohderyhmä ja viestit'],
|
||||
['Kuvat', $this->graphic->id, 'waiting', null],
|
||||
['Julkaisu', $this->graphic->id, 'waiting', null],
|
||||
])
|
||||
->and(DB::table('task_assignees')->pluck('user_id')->unique()->values()->all())->toBe([$this->employee->id]);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee('Lisättiin 3 tehtävää pohjasta Somekampanja (graafinen työ).');
|
||||
});
|
||||
|
||||
it('needs a template that is still available', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Valitse pohja.');
|
||||
|
||||
$component = Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('templateId', (string) $this->campaign);
|
||||
app(SetWorkflowTemplateActive::class)->execute($this->campaign, false);
|
||||
|
||||
$component->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Pohja ei ole enää käytettävissä tälle työlle. Valitse toinen.');
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->print)
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId']);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('is not for subcontractors, jobs before a quote request or archived jobs', function () {
|
||||
$this->job->update(['status' => 'tentative']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'archived']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'order']);
|
||||
$subcontractor = User::factory()->subcontractor()->create();
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
|
||||
$this->actingAs($subcontractor)->get(route('jobs.tasks.from-template', $this->job->id))->assertForbidden();
|
||||
});
|
||||
|
||||
it('locks the job id', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('jobId', 999);
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
|
||||
it('shows a table of the chosen template tasks and saves their due dates and estimates', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertDontSee('Pohjan Somekampanja tehtävät')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows', array_fill(0, 3, ['due_on' => '', 'estimated_hours' => '']))
|
||||
->assertSee('Pohjan Somekampanja tehtävät')
|
||||
->assertSee('Määräpäivä: Kuvat')
|
||||
->assertSee('Arvioitu aika (h): Julkaisu')
|
||||
->set('rows.0.due_on', '2026-06-01')
|
||||
->set('rows.0.estimated_hours', '1,5')
|
||||
->set('rows.2.estimated_hours', '2')
|
||||
->call('add')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->due_on?->format('Y-m-d'), $task->estimated_hours === null ? null : (float) $task->estimated_hours])->all())->toBe([
|
||||
['Suunnittelu', '2026-06-01', 1.5],
|
||||
['Kuvat', null, null],
|
||||
['Julkaisu', null, 2.0],
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows errors in the table cells and adds nothing', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.1.due_on', '1.6.2026')
|
||||
->set('rows.2.estimated_hours', 'paljon')
|
||||
->call('add')
|
||||
->assertHasErrors(['rows.1.due_on', 'rows.2.estimated_hours'])
|
||||
->assertSee('aria-invalid="true"', escape: false);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('empties the rows when another template is chosen', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.0.estimated_hours', '3')
|
||||
->set('templateId', '')
|
||||
->assertSet('rows', [])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows.0.estimated_hours', '');
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('lets only the admin open the holidays page', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
$this->get(route('settings.holidays'))->assertForbidden();
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$this->get(route('settings.holidays', ['year' => 2026]))
|
||||
->assertOk()
|
||||
->assertSee('Arkipyhät')
|
||||
->assertSee('Vuosi 2026')
|
||||
->assertSee('pe 3.4.2026')
|
||||
->assertSee('Pitkäperjantai')
|
||||
->assertSee('Juhannusaatto');
|
||||
});
|
||||
|
||||
it('takes a holiday out of use and adds and removes a company day off', function () {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test('shared::holidays', ['year' => 2026])
|
||||
->call('disable', '2026-12-24')
|
||||
->assertSee('Jouluaatto (to 24.12.2026) poistettu käytöstä.')
|
||||
->assertSee('Ei käytössä')
|
||||
->set('date', '2026-12-23')
|
||||
->set('name', 'Pikkujoulu')
|
||||
->call('add')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Pikkujoulu (ke 23.12.2026) lisätty.')
|
||||
->set('date', '2026-12-25')
|
||||
->set('name', 'Joulu')
|
||||
->call('add')
|
||||
->assertHasErrors('date')
|
||||
->call('remove', '2026-12-23')
|
||||
->assertSee('Pikkujoulu (ke 23.12.2026) poistettu.');
|
||||
|
||||
$this->assertDatabaseHas('holiday_overrides', ['date' => '2026-12-24', 'is_holiday' => false]);
|
||||
$this->assertDatabaseMissing('holiday_overrides', ['date' => '2026-12-23']);
|
||||
});
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\Services\WorkflowStepBuilder;
|
||||
use App\Modules\Catalog\Application\UseCases\AddServiceUnit;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkType;
|
||||
use App\Modules\Catalog\Application\UseCases\SetCatalogItemActive;
|
||||
use App\Modules\Catalog\Application\UseCases\SetWorkflowTemplateActive;
|
||||
use App\Modules\Catalog\Application\UseCases\UpdateWorkflowTemplate;
|
||||
use App\Modules\Catalog\Domain\Entities\ServiceUnit;
|
||||
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidWorkflowStepTitle;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowStepWorkTypeNotAllowed;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNeedsSteps;
|
||||
use App\Modules\Catalog\Domain\Exceptions\WorkflowTemplateNotFound;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\InMemoryServiceRepository;
|
||||
use Tests\Fakes\InMemoryServiceUnitRepository;
|
||||
use Tests\Fakes\InMemoryWorkflowTemplateRepository;
|
||||
use Tests\Fakes\InMemoryWorkTypeRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
$units = new InMemoryServiceUnitRepository;
|
||||
$services = new InMemoryServiceRepository;
|
||||
$this->workTypes = new InMemoryWorkTypeRepository;
|
||||
$this->templates = new InMemoryWorkflowTemplateRepository;
|
||||
$transactions = new FakeTransactionManager;
|
||||
$builder = new WorkflowStepBuilder($this->workTypes, $units);
|
||||
|
||||
$this->add = new AddWorkflowTemplate($this->templates, $this->workTypes, $builder, $transactions);
|
||||
$this->update = new UpdateWorkflowTemplate($this->templates, $this->workTypes, $builder, $transactions);
|
||||
$this->setActive = new SetWorkflowTemplateActive($this->templates, $transactions);
|
||||
$this->setWorkTypeActive = new SetCatalogItemActive($units, $services, $this->workTypes, $transactions);
|
||||
|
||||
$addUnit = new AddServiceUnit($units, $transactions);
|
||||
$addWorkType = new AddWorkType($units, $services, $this->workTypes, $transactions);
|
||||
$media = $addUnit->execute('Mediatuotanto');
|
||||
$marketing = $addUnit->execute('Markkinointi');
|
||||
$shared = (int) $units->save(ServiceUnit::create(new CatalogName('Kaikille yhteiset'), 3, shared: true))->id();
|
||||
|
||||
$this->videography = $addWorkType->execute($media, null, 'videokuvaus');
|
||||
$this->editing = $addWorkType->execute($media, null, 'editointi');
|
||||
$this->graphics = $addWorkType->execute($marketing, null, 'graafinen työ');
|
||||
$this->planning = $addWorkType->execute($shared, null, 'suunnittelu');
|
||||
|
||||
$this->data = fn (string $name, array $steps, ?int $workTypeId = null): WorkflowTemplateData => new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId ?? $this->videography,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
);
|
||||
});
|
||||
|
||||
it('adds a template with steps in order and their own work types', function () {
|
||||
$id = $this->add->execute(($this->data)('Lyhyt video', [
|
||||
['Suunnittelu', null, $this->planning],
|
||||
[' Kuvaus ', 'Kuvauspäivä asiakkaalla'],
|
||||
['Editointi', '', $this->editing],
|
||||
]));
|
||||
|
||||
$template = $this->templates->findById($id);
|
||||
|
||||
expect($template?->name()->value)->toBe('Lyhyt video')
|
||||
->and($template?->isActive())->toBeTrue()
|
||||
->and(array_map(fn ($step) => [$step->title->value, $step->description, $step->workTypeId], $template?->steps() ?? []))->toBe([
|
||||
['Suunnittelu', null, $this->planning],
|
||||
['Kuvaus', 'Kuvauspäivä asiakkaalla', null],
|
||||
['Editointi', null, $this->editing],
|
||||
]);
|
||||
});
|
||||
|
||||
it('needs at least one step with a title, and tells which step is wrong', function () {
|
||||
expect(fn () => $this->add->execute(($this->data)('Tyhjä', [])))->toThrow(WorkflowTemplateNeedsSteps::class);
|
||||
|
||||
try {
|
||||
$this->add->execute(($this->data)('Lyhyt video', [['Kuvaus'], [' ']]));
|
||||
$this->fail('The empty title was accepted.');
|
||||
} catch (InvalidWorkflowStepTitle $exception) {
|
||||
expect($exception->stepIndex)->toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects a name the work type already has, but allows it for another work type', function () {
|
||||
$this->add->execute(($this->data)('Lyhyt video', [['Kuvaus']]));
|
||||
$this->add->execute(($this->data)('lyhyt video', [['Kuvaus']], $this->editing));
|
||||
|
||||
expect(fn () => $this->add->execute(($this->data)('LYHYT VIDEO', [['Kuvaus']])))->toThrow(WorkflowTemplateNameTaken::class);
|
||||
});
|
||||
|
||||
it('allows a step work type only from the same unit or the shared unit, and in use', function () {
|
||||
try {
|
||||
$this->add->execute(($this->data)('Lyhyt video', [['Kuvaus'], ['Grafiikka', null, $this->graphics]]));
|
||||
$this->fail('A work type of another unit was accepted.');
|
||||
} catch (WorkflowStepWorkTypeNotAllowed $exception) {
|
||||
expect($exception->stepIndex)->toBe(1);
|
||||
}
|
||||
|
||||
$this->setWorkTypeActive->execute(CatalogLevel::WorkType, $this->editing, false);
|
||||
|
||||
expect(fn () => $this->add->execute(($this->data)('Lyhyt video', [['Editointi', null, $this->editing]])))
|
||||
->toThrow(WorkflowStepWorkTypeNotAllowed::class);
|
||||
});
|
||||
|
||||
it('needs a template work type in use', function () {
|
||||
$this->setWorkTypeActive->execute(CatalogLevel::WorkType, $this->videography, false);
|
||||
|
||||
$this->add->execute(($this->data)('Lyhyt video', [['Kuvaus']]));
|
||||
})->throws(CatalogItemNotFound::class);
|
||||
|
||||
it('updates name and steps, keeping step work types taken out of use since', function () {
|
||||
$id = $this->add->execute(($this->data)('Lyhyt video', [['Kuvaus'], ['Editointi', null, $this->editing]]));
|
||||
$this->setWorkTypeActive->execute(CatalogLevel::WorkType, $this->editing, false);
|
||||
|
||||
$this->update->execute($id, ($this->data)('Lyhyt video 2', [['Editointi', null, $this->editing], ['Toimitus']]));
|
||||
|
||||
$template = $this->templates->findById($id);
|
||||
|
||||
expect($template?->name()->value)->toBe('Lyhyt video 2')
|
||||
->and(array_map(fn ($step) => $step->title->value, $template?->steps() ?? []))->toBe(['Editointi', 'Toimitus']);
|
||||
|
||||
expect(fn () => $this->update->execute(999, ($this->data)('X', [['Kuvaus']])))->toThrow(WorkflowTemplateNotFound::class);
|
||||
});
|
||||
|
||||
it('takes a template out of use and back', function () {
|
||||
$id = $this->add->execute(($this->data)('Lyhyt video', [['Kuvaus']]));
|
||||
|
||||
$this->setActive->execute($id, false);
|
||||
expect($this->templates->findById($id)?->isActive())->toBeFalse();
|
||||
|
||||
$this->setActive->execute($id, true);
|
||||
expect($this->templates->findById($id)?->isActive())->toBeTrue();
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Customers\Application\Services\CustomerRemoval;
|
||||
use App\Modules\Customers\Application\UseCases\RemoveCustomer;
|
||||
use App\Modules\Customers\Domain\Entities\BillingUnit;
|
||||
use App\Modules\Customers\Domain\Entities\Customer;
|
||||
use App\Modules\Customers\Domain\Entities\CustomerContact;
|
||||
use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Customers\Domain\Exceptions\CustomerInUse;
|
||||
use App\Modules\Customers\Domain\Exceptions\CustomerNotFound;
|
||||
use App\Modules\Customers\Domain\Exceptions\InternalCustomerCannotBeRemoved;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BillingUnitName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\ContactName;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use Tests\Fakes\FakeCustomerReferences;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\InMemoryBillingUnitRepository;
|
||||
use Tests\Fakes\InMemoryCustomerContactRepository;
|
||||
use Tests\Fakes\InMemoryCustomerRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->customers = new InMemoryCustomerRepository;
|
||||
$this->contacts = new InMemoryCustomerContactRepository;
|
||||
$this->billingUnits = new InMemoryBillingUnitRepository;
|
||||
$this->references = new FakeCustomerReferences;
|
||||
$this->removal = new CustomerRemoval($this->customers, $this->contacts, $this->billingUnits, $this->references);
|
||||
$this->removeCustomer = new RemoveCustomer($this->customers, $this->removal, new FakeTransactionManager);
|
||||
|
||||
$this->customerId = $this->customers->save(Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company))->id();
|
||||
});
|
||||
|
||||
it('removes a customer that has nothing but its name', function () {
|
||||
expect($this->removal->canRemove($this->customerId))->toBeTrue();
|
||||
|
||||
$this->removeCustomer->execute($this->customerId);
|
||||
|
||||
expect($this->customers->findById($this->customerId))->toBeNull()
|
||||
->and($this->removal->canRemove($this->customerId))->toBeFalse();
|
||||
});
|
||||
|
||||
it('does not remove an unknown customer', function () {
|
||||
$this->removeCustomer->execute(999);
|
||||
})->throws(CustomerNotFound::class);
|
||||
|
||||
it('does not remove the internal customer', function () {
|
||||
$internalId = $this->customers->save(Customer::reconstitute(50, new CustomerName('Oma Oy'), CustomerType::Company, null, null, true))->id();
|
||||
|
||||
expect($this->removal->canRemove($internalId))->toBeFalse()
|
||||
->and(fn () => $this->removeCustomer->execute($internalId))->toThrow(InternalCustomerCannotBeRemoved::class)
|
||||
->and($this->customers->findById($internalId))->not->toBeNull();
|
||||
});
|
||||
|
||||
it('does not remove a customer that has a contact or a billing unit', function (string $row) {
|
||||
match ($row) {
|
||||
'contact' => $this->contacts->save(CustomerContact::create($this->customerId, new ContactName('Maija'))),
|
||||
'billing unit' => $this->billingUnits->save(BillingUnit::create($this->customerId, new BillingUnitName('Mainos Oy'))),
|
||||
};
|
||||
|
||||
expect($this->removal->canRemove($this->customerId))->toBeFalse()
|
||||
->and(fn () => $this->removeCustomer->execute($this->customerId))->toThrow(CustomerInUse::class)
|
||||
->and($this->customers->findById($this->customerId))->not->toBeNull();
|
||||
})->with(['contact', 'billing unit']);
|
||||
|
||||
it('does not remove a customer that other modules refer to', function () {
|
||||
$this->references->referencedIds = [$this->customerId];
|
||||
|
||||
expect($this->removal->canRemove($this->customerId))->toBeFalse()
|
||||
->and(fn () => $this->removeCustomer->execute($this->customerId))->toThrow(CustomerInUse::class)
|
||||
->and($this->customers->findById($this->customerId))->not->toBeNull();
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\CalendarAssignment;
|
||||
use App\Modules\Jobs\Application\DTOs\CalendarTask;
|
||||
use App\Modules\Jobs\Application\Services\TaskCalendarLayout;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
/**
|
||||
* @param list<CalendarAssignment> $assignments
|
||||
*/
|
||||
function calendarTask(int $id, string $from, string $to, array $assignments, ?string $dueOn = null): CalendarTask
|
||||
{
|
||||
return new CalendarTask($id, 1, '2026-001', 'Kampanja', 'Tehtävä '.$id, TaskStatus::Waiting, $dueOn, null, $from, $to, $assignments);
|
||||
}
|
||||
|
||||
it('puts each task on its assignees rows and overlapping tasks on their own lanes', function () {
|
||||
$days = ['2026-12-07', '2026-12-08', '2026-12-09', '2026-12-10'];
|
||||
$tasks = [
|
||||
calendarTask(1, '2026-12-07', '2026-12-08', [new CalendarAssignment(10, '2026-12-07', '2026-12-08', 480), new CalendarAssignment(11, '2026-12-07', '2026-12-09', 480)]),
|
||||
calendarTask(2, '2026-12-08', '2026-12-08', [new CalendarAssignment(10, '2026-12-08', '2026-12-08', 120)]),
|
||||
calendarTask(3, '2026-12-09', '2026-12-20', [new CalendarAssignment(10, null, null, 0)], dueOn: '2026-12-15'),
|
||||
calendarTask(4, '2026-12-01', '2026-12-07', []),
|
||||
];
|
||||
$people = [['id' => 10, 'name' => 'Eero'], ['id' => 11, 'name' => 'Aino'], ['id' => null, 'name' => 'Ei tekijää']];
|
||||
|
||||
$rows = TaskCalendarLayout::build($days, $people, $tasks, [10 => ['2026-12-08' => 360]]);
|
||||
$bars = fn (int $row): array => array_map(fn ($bar) => [$bar->task->taskId, $bar->start, $bar->span, $bar->lane, $bar->late], $rows[$row]->bars);
|
||||
|
||||
expect($bars(0))->toBe([[1, 0, 2, 0, false], [2, 1, 1, 1, false], [3, 2, 2, 0, true]])
|
||||
->and($rows[0]->lanes)->toBe(2)
|
||||
->and($rows[0]->minutesByDay)->toBe(['2026-12-07' => 0, '2026-12-08' => 360, '2026-12-09' => 0, '2026-12-10' => 0])
|
||||
->and($bars(1))->toBe([[1, 0, 3, 0, false]])
|
||||
->and($bars(2))->toBe([[4, 0, 1, 0, false]])
|
||||
->and(array_map(fn ($bar) => $bar->task->taskId, $rows[0]->barsOn(1)))->toBe([1, 2]);
|
||||
});
|
||||
@@ -3,28 +3,36 @@
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobData;
|
||||
use App\Modules\Jobs\Application\DTOs\TaskData;
|
||||
use App\Modules\Jobs\Application\Services\JobDetailsFactory;
|
||||
use App\Modules\Jobs\Application\Services\TaskPlanner;
|
||||
use App\Modules\Jobs\Application\Services\TaskReferenceChecker;
|
||||
use App\Modules\Jobs\Application\UseCases\AddTask;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeJobStatus;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeTaskStatus;
|
||||
use App\Modules\Jobs\Application\UseCases\ClearTaskSchedule;
|
||||
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
||||
use App\Modules\Jobs\Application\UseCases\RemoveTask;
|
||||
use App\Modules\Jobs\Application\UseCases\ScheduleTask;
|
||||
use App\Modules\Jobs\Application\UseCases\UpdateTask;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskTitle;
|
||||
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskHasTimeEntries;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use Tests\Fakes\FakeCatalogQueries;
|
||||
use Tests\Fakes\FakeClock;
|
||||
use Tests\Fakes\FakeCustomerQueries;
|
||||
use Tests\Fakes\FakeSettings;
|
||||
use Tests\Fakes\FakeTaskUsage;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\FakeUserAccountQueries;
|
||||
use Tests\Fakes\InMemoryCustomerJobRepository;
|
||||
use Tests\Fakes\InMemoryHolidayOverrides;
|
||||
use Tests\Fakes\InMemoryTaskBookingRepository;
|
||||
use Tests\Fakes\InMemoryTaskRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -50,8 +58,12 @@ beforeEach(function () {
|
||||
$this->tentativeJobId = $createJob->execute(new CustomerJobData('Alustava', 1, [1], 10, 'one_off', 'tentative', 'normal'), 10);
|
||||
|
||||
$checker = new TaskReferenceChecker($this->catalog, $this->users);
|
||||
$this->addTask = new AddTask($this->jobs, $this->tasks, $checker, $transactions);
|
||||
$this->updateTask = new UpdateTask($this->jobs, $this->tasks, $checker, $transactions);
|
||||
$this->bookings = new InMemoryTaskBookingRepository($this->tasks);
|
||||
$this->planner = new TaskPlanner($this->bookings, new HolidayCalendar(new InMemoryHolidayOverrides), new FakeSettings);
|
||||
$this->addTask = new AddTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions);
|
||||
$this->updateTask = new UpdateTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions);
|
||||
$this->scheduleTask = new ScheduleTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions);
|
||||
$this->clearSchedule = new ClearTaskSchedule($this->tasks, $this->planner, $transactions);
|
||||
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions);
|
||||
$this->usage = new FakeTaskUsage;
|
||||
$this->removeTask = new RemoveTask($this->tasks, $this->usage, $transactions);
|
||||
@@ -136,3 +148,61 @@ it('does not remove a task with time entries', function () {
|
||||
->and(JobStatus::Done->locksTime())->toBeTrue()
|
||||
->and(JobStatus::OnHold->locksTime())->toBeFalse();
|
||||
});
|
||||
|
||||
it('books a scheduled task evenly from the working days of its period', function () {
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '12', assigneeUserIds: [10], plannedFrom: '2026-12-04', plannedTo: '2026-12-07'), 10);
|
||||
$oneDayId = $this->addTask->execute($this->jobId, new TaskData('Palaveri', 91, 'waiting', assigneeUserIds: [10], plannedFrom: '2026-12-08'), 10);
|
||||
|
||||
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 360, '2026-12-07' => 360])
|
||||
->and($this->tasks->findForJob($this->jobId, $oneDayId)?->plannedTo()?->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and($this->bookings->of($oneDayId, 10))->toBe([]);
|
||||
});
|
||||
|
||||
it('moves what does not fit in a full day to the next working day', function () {
|
||||
$this->addTask->execute($this->jobId, new TaskData('Kuvaus', 11, 'waiting', estimatedHours: '6', assigneeUserIds: [10], plannedFrom: '2026-12-04'), 10);
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '4', assigneeUserIds: [10]), 10);
|
||||
|
||||
$result = $this->scheduleTask->execute($this->jobId, $taskId, 10, 10, '2026-12-04', '2026-12-04');
|
||||
|
||||
expect($result->extended)->toBeTrue()
|
||||
->and($result->plannedTo)->toBe('2026-12-07')
|
||||
->and($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 120, '2026-12-07' => 120]);
|
||||
});
|
||||
|
||||
it('does not count done tasks in the day load', function () {
|
||||
$doneId = $this->addTask->execute($this->jobId, new TaskData('Kuvaus', 11, 'waiting', estimatedHours: '8', assigneeUserIds: [10], plannedFrom: '2026-12-04'), 10);
|
||||
$this->changeTaskStatus->execute($this->jobId, $doneId, TaskStatus::Done);
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '8', assigneeUserIds: [10], plannedFrom: '2026-12-04'), 10);
|
||||
|
||||
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 480]);
|
||||
});
|
||||
|
||||
it('moves a task to another person and gives it the days its estimate needs', function () {
|
||||
$this->users->addUser(11, 'Aino');
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '20', assigneeUserIds: [10], plannedFrom: '2026-12-01'), 10);
|
||||
|
||||
$result = $this->scheduleTask->execute($this->jobId, $taskId, 10, 11, '2026-12-11', null);
|
||||
|
||||
expect($this->tasks->findForJob($this->jobId, $taskId)?->assigneeUserIds())->toBe([11])
|
||||
->and($result->plannedFrom)->toBe('2026-12-11')
|
||||
->and($result->plannedTo)->toBe('2026-12-15')
|
||||
->and($result->extended)->toBeFalse()
|
||||
->and($this->bookings->of($taskId, 10))->toBe([])
|
||||
->and(array_sum($this->bookings->of($taskId, 11)))->toBe(1200);
|
||||
});
|
||||
|
||||
it('rejects moving a task to an inactive person or ending it before it starts', function () {
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', assigneeUserIds: [10]), 10);
|
||||
|
||||
expect(fn () => $this->scheduleTask->execute($this->jobId, $taskId, 10, 12, '2026-12-07', '2026-12-07'))->toThrow(InvalidTaskReference::class)
|
||||
->and(fn () => $this->scheduleTask->execute($this->jobId, $taskId, 10, 10, '2026-12-07', '2026-12-04'))->toThrow(PlanEndsBeforeStart::class);
|
||||
});
|
||||
|
||||
it('takes a task out of the calendar', function () {
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '4', assigneeUserIds: [10], plannedFrom: '2026-12-07'), 10);
|
||||
|
||||
$this->clearSchedule->execute($this->jobId, $taskId);
|
||||
|
||||
expect($this->tasks->findForJob($this->jobId, $taskId)?->isScheduled())->toBeFalse()
|
||||
->and($this->bookings->of($taskId, 10))->toBe([]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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);
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Jobs\Domain\Services\TaskScheduler;
|
||||
|
||||
function scheduleDay(string $date): DateTimeImmutable
|
||||
{
|
||||
return new DateTimeImmutable($date);
|
||||
}
|
||||
|
||||
it('splits the estimate evenly over the working days of the period', function () {
|
||||
// Fri 4.12.2026 – Tue 8.12.2026; the weekend in between gets nothing.
|
||||
$schedule = TaskScheduler::schedule(scheduleDay('2026-12-04'), scheduleDay('2026-12-08'), 600, [], 480, []);
|
||||
|
||||
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 210, '2026-12-07' => 195, '2026-12-08' => 195])
|
||||
->and($schedule->end->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and($schedule->extended)->toBeFalse();
|
||||
});
|
||||
|
||||
it('skips holidays and uses weekend days when the period has nothing else', function () {
|
||||
$overHolidays = TaskScheduler::schedule(scheduleDay('2026-12-24'), scheduleDay('2026-12-28'), 240, [], 480, ['2026-12-24', '2026-12-25']);
|
||||
$weekend = TaskScheduler::schedule(scheduleDay('2026-12-05'), scheduleDay('2026-12-06'), 300, [], 480, []);
|
||||
|
||||
expect($overHolidays->minutesByDay)->toBe(['2026-12-28' => 240])
|
||||
->and($weekend->minutesByDay)->toBe(['2026-12-05' => 150, '2026-12-06' => 150]);
|
||||
});
|
||||
|
||||
it('moves what does not fit to the next working days and ends later', function () {
|
||||
$schedule = TaskScheduler::schedule(scheduleDay('2026-12-04'), scheduleDay('2026-12-04'), 600, ['2026-12-04' => 300, '2026-12-07' => 480], 480, []);
|
||||
|
||||
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 180, '2026-12-08' => 420])
|
||||
->and($schedule->end->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and($schedule->extended)->toBeTrue();
|
||||
});
|
||||
|
||||
it('books nothing without an estimate', function () {
|
||||
$schedule = TaskScheduler::schedule(scheduleDay('2026-12-07'), scheduleDay('2026-12-09'), 0, [], 480, []);
|
||||
|
||||
expect($schedule->minutesByDay)->toBe([])
|
||||
->and($schedule->end->format('Y-m-d'))->toBe('2026-12-09');
|
||||
});
|
||||
|
||||
it('gives a placed task the working days its estimate needs', function () {
|
||||
expect(TaskScheduler::defaultEnd(scheduleDay('2026-12-07'), 240, 480, [])->format('Y-m-d'))->toBe('2026-12-07')
|
||||
->and(TaskScheduler::defaultEnd(scheduleDay('2026-12-04'), 1200, 480, [])->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and(TaskScheduler::defaultEnd(scheduleDay('2026-12-23'), 960, 480, ['2026-12-24', '2026-12-25'])->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and(TaskScheduler::defaultEnd(scheduleDay('2026-12-05'), 0, 480, [])->format('Y-m-d'))->toBe('2026-12-05');
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use App\Modules\Shared\Domain\Exceptions\HolidayAlreadyExists;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidHolidayName;
|
||||
use App\Modules\Shared\Domain\Exceptions\NotAHoliday;
|
||||
use App\Modules\Shared\Domain\Services\FinnishHolidays;
|
||||
use Tests\Fakes\InMemoryHolidayOverrides;
|
||||
|
||||
it('calculates Easter and Midsummer Eve', function (int $year, string $easter, string $midsummerEve) {
|
||||
$holidays = FinnishHolidays::forYear($year);
|
||||
|
||||
expect(FinnishHolidays::easterSunday($year)->format('Y-m-d'))->toBe($easter)
|
||||
->and(array_search('midsummer_eve', $holidays, true))->toBe($midsummerEve);
|
||||
})->with([
|
||||
[2025, '2025-04-20', '2025-06-20'],
|
||||
[2026, '2026-04-05', '2026-06-19'],
|
||||
[2027, '2027-03-28', '2027-06-25'],
|
||||
]);
|
||||
|
||||
it('lists the holidays of a year in date order', function () {
|
||||
expect(FinnishHolidays::forYear(2026))->toBe([
|
||||
'2026-01-01' => 'new_years_day',
|
||||
'2026-01-06' => 'epiphany',
|
||||
'2026-04-03' => 'good_friday',
|
||||
'2026-04-06' => 'easter_monday',
|
||||
'2026-05-01' => 'may_day',
|
||||
'2026-05-14' => 'ascension_day',
|
||||
'2026-06-19' => 'midsummer_eve',
|
||||
'2026-12-06' => 'independence_day',
|
||||
'2026-12-24' => 'christmas_eve',
|
||||
'2026-12-25' => 'christmas_day',
|
||||
'2026-12-26' => 'st_stephens_day',
|
||||
]);
|
||||
});
|
||||
|
||||
it('takes holidays out of use and adds company days off', function () {
|
||||
$calendar = new HolidayCalendar(new InMemoryHolidayOverrides);
|
||||
|
||||
$calendar->disable('2026-12-24');
|
||||
$calendar->addCompanyDay('2026-12-23', ' Pikkujoulu ');
|
||||
|
||||
$december = $calendar->between('2026-12-20', '2026-12-31');
|
||||
|
||||
expect(array_map(fn ($holiday) => [$holiday->date, $holiday->key, $holiday->name, $holiday->active], $december))->toBe([
|
||||
['2026-12-23', null, 'Pikkujoulu', true],
|
||||
['2026-12-24', 'christmas_eve', null, false],
|
||||
['2026-12-25', 'christmas_day', null, true],
|
||||
['2026-12-26', 'st_stephens_day', null, true],
|
||||
])->and($calendar->activeDatesBetween('2026-12-20', '2026-12-31'))->toBe(['2026-12-23', '2026-12-25', '2026-12-26']);
|
||||
|
||||
$calendar->enable('2026-12-24');
|
||||
$calendar->removeCompanyDay('2026-12-23');
|
||||
|
||||
expect($calendar->activeDatesBetween('2026-12-20', '2026-12-31'))->toBe(['2026-12-24', '2026-12-25', '2026-12-26']);
|
||||
});
|
||||
|
||||
it('rejects invalid holiday changes', function () {
|
||||
$calendar = new HolidayCalendar(new InMemoryHolidayOverrides);
|
||||
|
||||
expect(fn () => $calendar->disable('2026-12-23'))->toThrow(NotAHoliday::class)
|
||||
->and(fn () => $calendar->removeCompanyDay('2026-12-25'))->toThrow(NotAHoliday::class)
|
||||
->and(fn () => $calendar->addCompanyDay('2026-12-25', 'Joulu'))->toThrow(HolidayAlreadyExists::class)
|
||||
->and(fn () => $calendar->addCompanyDay('2026-12-23', ' '))->toThrow(InvalidHolidayName::class);
|
||||
});
|
||||
Reference in New Issue
Block a user