Add catalog module for service units, services and work types
Phase 1, item 3: the hierarchy customer jobs, tasks and time entries will refer to. - New Catalog module: service unit > optional service > work type. Names are unique per level (case-insensitive); items are never deleted, only deactivated, and foreign keys restrict deletes. - Pohjatiedot page (/catalog, admins and management): add, rename, reorder with move up/down buttons (keyboard-friendly, focus kept and announced) and an "in use" checkbox per row. Work types can move to another service of the same unit. - A migration inserts the starting catalog from the specification when the tables are empty, so every installation has it. - CatalogQueries gives other modules the active service units and the work types of chosen units plus the shared ones. - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\UseCases\AddService;
|
||||
use App\Modules\Catalog\Application\UseCases\AddServiceUnit;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkType;
|
||||
use App\Modules\Catalog\Application\UseCases\MoveCatalogItem;
|
||||
use App\Modules\Catalog\Application\UseCases\RenameCatalogItem;
|
||||
use App\Modules\Catalog\Application\UseCases\SetCatalogItemActive;
|
||||
use App\Modules\Catalog\Application\UseCases\UpdateWorkType;
|
||||
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
|
||||
use App\Modules\Catalog\Domain\Enums\MoveDirection;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
|
||||
use App\Modules\Catalog\Domain\Exceptions\CatalogNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\ServiceNotInUnit;
|
||||
use Tests\Fakes\FakeTransactionManager;
|
||||
use Tests\Fakes\InMemoryServiceRepository;
|
||||
use Tests\Fakes\InMemoryServiceUnitRepository;
|
||||
use Tests\Fakes\InMemoryWorkTypeRepository;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->units = new InMemoryServiceUnitRepository;
|
||||
$this->services = new InMemoryServiceRepository;
|
||||
$this->workTypes = new InMemoryWorkTypeRepository;
|
||||
$transactions = new FakeTransactionManager;
|
||||
|
||||
$this->addUnit = new AddServiceUnit($this->units, $transactions);
|
||||
$this->addService = new AddService($this->units, $this->services, $transactions);
|
||||
$this->addWorkType = new AddWorkType($this->units, $this->services, $this->workTypes, $transactions);
|
||||
$this->rename = new RenameCatalogItem($this->units, $this->services, $transactions);
|
||||
$this->updateWorkType = new UpdateWorkType($this->units, $this->services, $this->workTypes, $transactions);
|
||||
$this->setActive = new SetCatalogItemActive($this->units, $this->services, $this->workTypes, $transactions);
|
||||
$this->move = new MoveCatalogItem($this->units, $this->services, $this->workTypes, $transactions);
|
||||
|
||||
$this->media = $this->addUnit->execute('Mediatuotanto');
|
||||
$this->marketing = $this->addUnit->execute('Markkinointi');
|
||||
$this->video = $this->addService->execute($this->media, 'Videotuotanto');
|
||||
$this->photo = $this->addService->execute($this->media, 'Valokuvaus');
|
||||
});
|
||||
|
||||
it('adds items last among their siblings', function () {
|
||||
expect($this->units->findById($this->marketing)?->sortOrder())->toBe(2)
|
||||
->and($this->services->findById($this->photo)?->sortOrder())->toBe(2);
|
||||
});
|
||||
|
||||
it('rejects a name already used on the same level, ignoring case', function () {
|
||||
$this->addWorkType->execute($this->media, $this->video, 'editointi');
|
||||
|
||||
$this->addWorkType->execute($this->media, $this->video, 'Editointi');
|
||||
})->throws(CatalogNameTaken::class);
|
||||
|
||||
it('allows the same work type name under another service or unit', function () {
|
||||
$this->addWorkType->execute($this->media, $this->video, 'editointi');
|
||||
$this->addWorkType->execute($this->media, $this->photo, 'editointi');
|
||||
$this->addWorkType->execute($this->marketing, null, 'editointi');
|
||||
|
||||
expect($this->workTypes->items)->toHaveCount(3);
|
||||
});
|
||||
|
||||
it('rejects a service of another unit', function () {
|
||||
$this->addWorkType->execute($this->marketing, $this->video, 'editointi');
|
||||
})->throws(ServiceNotInUnit::class);
|
||||
|
||||
it('renames and rejects a taken name', function () {
|
||||
$this->rename->execute(CatalogLevel::Service, $this->video, 'Video');
|
||||
|
||||
expect($this->services->findById($this->video)?->name()->value)->toBe('Video')
|
||||
->and(fn () => $this->rename->execute(CatalogLevel::ServiceUnit, $this->media, 'markkinointi'))->toThrow(CatalogNameTaken::class);
|
||||
});
|
||||
|
||||
it('moves a work type to another service, last there', function () {
|
||||
$this->addWorkType->execute($this->media, $this->photo, 'kuvaus');
|
||||
$editing = $this->addWorkType->execute($this->media, $this->video, 'editointi');
|
||||
|
||||
$this->updateWorkType->execute($editing, $this->photo, 'editointi');
|
||||
|
||||
$workType = $this->workTypes->findById($editing);
|
||||
expect($workType?->serviceId())->toBe($this->photo)
|
||||
->and($workType?->sortOrder())->toBe(2);
|
||||
});
|
||||
|
||||
it('moves items up and down, and does nothing at either end', function () {
|
||||
expect($this->move->execute(CatalogLevel::ServiceUnit, $this->marketing, MoveDirection::Up))->toBeTrue()
|
||||
->and($this->units->findById($this->marketing)?->sortOrder())->toBe(1)
|
||||
->and($this->units->findById($this->media)?->sortOrder())->toBe(2)
|
||||
->and($this->move->execute(CatalogLevel::ServiceUnit, $this->marketing, MoveDirection::Up))->toBeFalse()
|
||||
->and($this->move->execute(CatalogLevel::Service, $this->photo, MoveDirection::Down))->toBeFalse();
|
||||
});
|
||||
|
||||
it('takes items out of use and back', function () {
|
||||
$this->setActive->execute(CatalogLevel::Service, $this->video, false);
|
||||
expect($this->services->findById($this->video)?->isActive())->toBeFalse();
|
||||
|
||||
$this->setActive->execute(CatalogLevel::Service, $this->video, true);
|
||||
expect($this->services->findById($this->video)?->isActive())->toBeTrue();
|
||||
});
|
||||
|
||||
it('fails for an unknown item', function () {
|
||||
$this->setActive->execute(CatalogLevel::WorkType, 999, false);
|
||||
})->throws(CatalogItemNotFound::class);
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Domain\Entities\Service;
|
||||
use App\Modules\Catalog\Domain\Entities\ServiceUnit;
|
||||
use App\Modules\Catalog\Domain\Entities\WorkType;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
|
||||
use App\Modules\Catalog\Domain\Exceptions\ServiceNotInUnit;
|
||||
use App\Modules\Catalog\Domain\Exceptions\SharedUnitHasNoServices;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
|
||||
it('normalises a catalog name and rejects an empty or too long one', function () {
|
||||
expect((new CatalogName(' 3D mallinnus '))->value)->toBe('3D mallinnus')
|
||||
->and(fn () => new CatalogName(' '))->toThrow(InvalidCatalogName::class)
|
||||
->and(fn () => new CatalogName(str_repeat('a', 101)))->toThrow(InvalidCatalogName::class);
|
||||
});
|
||||
|
||||
it('gives the shared unit no services', function () {
|
||||
$shared = ServiceUnit::reconstitute(1, new CatalogName('Kaikille yhteiset'), true, true, 1);
|
||||
|
||||
Service::create($shared, new CatalogName('Palvelu'), 1);
|
||||
})->throws(SharedUnitHasNoServices::class);
|
||||
|
||||
it('puts a work type only under a service of its own unit', function () {
|
||||
$media = ServiceUnit::reconstitute(1, new CatalogName('Mediatuotanto'), false, true, 1);
|
||||
$marketing = ServiceUnit::reconstitute(2, new CatalogName('Markkinointi'), false, true, 2);
|
||||
$video = Service::reconstitute(10, 1, new CatalogName('Videotuotanto'), true, 1);
|
||||
|
||||
expect(WorkType::create($media, $video, new CatalogName('editointi'), 1)->serviceId())->toBe(10)
|
||||
->and(fn () => WorkType::create($marketing, $video, new CatalogName('editointi'), 1))->toThrow(ServiceNotInUnit::class);
|
||||
});
|
||||
|
||||
it('deactivates, activates and swaps order', function () {
|
||||
$first = ServiceUnit::reconstitute(1, new CatalogName('A'), false, true, 1);
|
||||
$second = ServiceUnit::reconstitute(2, new CatalogName('B'), false, true, 2);
|
||||
|
||||
$first->deactivate();
|
||||
$first->swapOrderWith($second);
|
||||
|
||||
expect($first->isActive())->toBeFalse()
|
||||
->and($first->sortOrder())->toBe(2)
|
||||
->and($second->sortOrder())->toBe(1);
|
||||
|
||||
$first->activate();
|
||||
expect($first->isActive())->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user