134 lines
4.5 KiB
PHP
134 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service\Assignment;
|
|
|
|
use App\Entity\Application;
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Destination;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\JobProfile;
|
|
use App\Entity\Teamer;
|
|
use App\Model\TimelineItem;
|
|
use App\Service\Assignment\TimelineService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TimelineServiceTest extends TestCase
|
|
{
|
|
public function testCalledOffDispositionsAreNotDrawnAndFreeTheirSlot(): void
|
|
{
|
|
$assignment = $this->assignment(2);
|
|
$this->dispose($assignment, 'Anna', Disposition::STATUS_CONFIRMED);
|
|
$this->dispose($assignment, 'Bert', Disposition::STATUS_CALLED_OFF);
|
|
|
|
$items = $this->sortByType($this->items($assignment));
|
|
|
|
$this->assertCount(2, $items);
|
|
$this->assertSame('Anna Probe', $items[0]->getTeamerName());
|
|
$this->assertSame(TimelineItem::TYPE_ASSIGNMENT, $items[1]->getType());
|
|
}
|
|
|
|
public function testVacancyIsOpenWithoutApplicationsEvenWhenPartlyStaffed(): void
|
|
{
|
|
$assignment = $this->assignment(2);
|
|
$this->dispose($assignment, 'Anna', Disposition::STATUS_CONFIRMED);
|
|
$assignment->setStaffingStatus(Assignment::STATUS_PARTLY_STAFFED);
|
|
|
|
$vacancy = $this->sortByType($this->items($assignment))[1];
|
|
|
|
$this->assertSame(TimelineItem::TYPE_ASSIGNMENT, $vacancy->getType());
|
|
$this->assertSame(TimelineItem::STATE_OPEN, $vacancy->getState());
|
|
}
|
|
|
|
public function testVacancyIsPendingWithAValidApplication(): void
|
|
{
|
|
$assignment = $this->assignment(1);
|
|
$assignment->addApplication(new Application($assignment, $this->teamer('Carla')));
|
|
|
|
$this->assertSame(TimelineItem::STATE_PENDING, $this->items($assignment)[0]->getState());
|
|
}
|
|
|
|
public function testVacancyIgnoresRejectedApplications(): void
|
|
{
|
|
$assignment = $this->assignment(1);
|
|
$application = new Application($assignment, $this->teamer('Carla'));
|
|
$application->setStatus(Application::STATUS_REJECTED);
|
|
$assignment->addApplication($application);
|
|
|
|
$this->assertSame(TimelineItem::STATE_OPEN, $this->items($assignment)[0]->getState());
|
|
}
|
|
|
|
/**
|
|
* Paid had no colour in the template and rendered like a vacancy.
|
|
*/
|
|
public function testDispositionStates(): void
|
|
{
|
|
$expected = [
|
|
Disposition::STATUS_NEW => TimelineItem::STATE_PENDING,
|
|
Disposition::STATUS_CHECKING_CONTRACT => TimelineItem::STATE_PENDING,
|
|
Disposition::STATUS_CONFIRMED => TimelineItem::STATE_STAFFED,
|
|
Disposition::STATUS_ENDED => TimelineItem::STATE_STAFFED,
|
|
Disposition::STATUS_CHECKING_INVOICE => TimelineItem::STATE_STAFFED,
|
|
Disposition::STATUS_PAID => TimelineItem::STATE_STAFFED,
|
|
Disposition::STATUS_COMPLETED => TimelineItem::STATE_STAFFED,
|
|
];
|
|
|
|
foreach ($expected as $status => $state) {
|
|
$assignment = $this->assignment(1);
|
|
$this->dispose($assignment, 'Anna', $status);
|
|
|
|
$this->assertSame($state, $this->items($assignment)[0]->getState(), $status);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return list<TimelineItem>
|
|
*/
|
|
private function items(Assignment $assignment): array
|
|
{
|
|
$rows = (new TimelineService())->preprocess([$assignment]);
|
|
|
|
return array_merge(...array_map('array_values', $rows['DGS']));
|
|
}
|
|
|
|
/**
|
|
* @param list<TimelineItem> $items
|
|
*
|
|
* @return list<TimelineItem> dispositions first
|
|
*/
|
|
private function sortByType(array $items): array
|
|
{
|
|
usort($items, fn (TimelineItem $a, TimelineItem $b) => strcmp($b->getType(), $a->getType()));
|
|
|
|
return $items;
|
|
}
|
|
|
|
private function assignment(int $slots): Assignment
|
|
{
|
|
$destination = (new Destination())
|
|
->setHotelCode('DGS01')
|
|
->setDateFrom(new \DateTimeImmutable('2026-12-05'))
|
|
->setDateTo(new \DateTimeImmutable('2026-12-12'))
|
|
;
|
|
|
|
return (new Assignment())
|
|
->setDestination($destination)
|
|
->setJobProfile((new JobProfile())->setName('Reiseleitung'))
|
|
->setAvailableDispositions($slots)
|
|
;
|
|
}
|
|
|
|
private function dispose(Assignment $assignment, string $firstName, string $status): void
|
|
{
|
|
$disposition = new Disposition(new Application($assignment, $this->teamer($firstName)));
|
|
$disposition->setStatus($status);
|
|
$assignment->addDisposition($disposition);
|
|
}
|
|
|
|
private function teamer(string $firstName): Teamer
|
|
{
|
|
return (new Teamer())->setFirstName($firstName)->setLastName('Probe');
|
|
}
|
|
}
|