fix: draw only active placements on the timeline and keep trips overlapping its dates
This commit is contained in:
1 parent
5ca9b812c3
commit
4e50f23558
6 files changed
+216
-32
No files matched your search
@@ -6,7 +6,10 @@ namespace App\Tests\Repository;
|
||||
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Disposition;
|
||||
use App\Model\AssignmentFilterDto;
|
||||
use App\Model\TimelineFilterDto;
|
||||
use App\Repository\AssignmentRepository;
|
||||
use Carbon\CarbonPeriodImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
@@ -47,14 +50,45 @@ class AssignmentRepositoryTest extends KernelTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The timeline keeps every trip touching its window, so a team on site stays visible when
|
||||
* the window starts today.
|
||||
*/
|
||||
public function testTimelineDateFilterKeepsOverlappingTrips(): void
|
||||
{
|
||||
$filterDto = (new TimelineFilterDto())
|
||||
->setPeriod(CarbonPeriodImmutable::create('2026-11-12', '2026-12-31'))
|
||||
;
|
||||
|
||||
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
|
||||
|
||||
$this->assertStringContainsString('destination.dateTo >= :dateFrom', $dql);
|
||||
$this->assertStringContainsString('destination.dateFrom <= :dateTo', $dql);
|
||||
}
|
||||
|
||||
public function testListDateFilterKeepsTripsInsideTheDates(): void
|
||||
{
|
||||
$filterDto = (new AssignmentFilterDto())
|
||||
->setDateFrom(new \DateTimeImmutable('2026-11-12'))
|
||||
->setDateTo(new \DateTimeImmutable('2026-12-31'))
|
||||
;
|
||||
|
||||
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
|
||||
|
||||
$this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql);
|
||||
$this->assertStringContainsString('destination.dateTo <= :dateTo', $dql);
|
||||
}
|
||||
|
||||
private function createAvailableAssignmentsIdsQuery(): Query
|
||||
{
|
||||
return $this->getRepository()->getAvailableAssignmentsIdsQuery();
|
||||
}
|
||||
|
||||
private function getRepository(): AssignmentRepository
|
||||
{
|
||||
/** @var EntityManagerInterface $entityManager */
|
||||
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
/** @var AssignmentRepository $repository */
|
||||
$repository = $entityManager->getRepository(Assignment::class);
|
||||
|
||||
return $repository->getAvailableAssignmentsIdsQuery();
|
||||
return $entityManager->getRepository(Assignment::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user