feat: offer the questionnaire for placements ended within a rolling window
This commit is contained in:
1 parent
9d0cdd7f52
commit
3c34cfa76a
8 files changed
+65
-55
No files matched your search
@@ -112,6 +112,18 @@ class QuestionnaireCatalogTest extends TestCase
|
||||
$this->assertSame('Alte Frage', $catalog->get('sample', 1)->getQuestion('answer')->label);
|
||||
}
|
||||
|
||||
public function testTheWindowStartsTheGivenDaysBeforeToday(): void
|
||||
{
|
||||
$this->assertEquals(new \DateTimeImmutable('today -2 days'), QuestionnaireCatalog::windowStart(2));
|
||||
}
|
||||
|
||||
public function testANegativeWindowFailsLoudly(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
QuestionnaireCatalog::windowStart(-1);
|
||||
}
|
||||
|
||||
public function testUnknownQuestionnaireIsRejected(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
@@ -25,8 +25,6 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
use QuestionnaireFixturesTrait;
|
||||
|
||||
private const string GO_LIVE = '2026-01-01';
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private DispositionRepository $repository;
|
||||
@@ -123,6 +121,13 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
$this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending());
|
||||
}
|
||||
|
||||
public function testAnAssignmentEndingOnTheWindowsFirstDayIsPending(): void
|
||||
{
|
||||
$this->escort(dateTo: 'today -30 days');
|
||||
|
||||
$this->assertCount(1, $this->pending());
|
||||
}
|
||||
|
||||
public function testAnAssignmentEndingTodayIsPending(): void
|
||||
{
|
||||
$this->escort(dateTo: 'today');
|
||||
@@ -149,7 +154,7 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
return [
|
||||
'not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))],
|
||||
'ended before go-live' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('2025-12-31'))],
|
||||
'ended before the window' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('today -31 days'))],
|
||||
'skip formalities' => [static fn (Disposition $d) => $d->getAssignment()->setSkipFormalities(true)],
|
||||
'called off' => [static fn (Disposition $d) => $d->setStatus(Disposition::STATUS_CALLED_OFF)],
|
||||
'assignment called off' => [static fn (Disposition $d) => $d->getAssignment()->setStatus(Assignment::STATUS_CALLED_OFF)],
|
||||
@@ -172,6 +177,6 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE));
|
||||
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, QuestionnaireCatalog::windowStart(30));
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
(new DispositionVoter($this->security, null))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
(new DispositionVoter($this->security, 30))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -217,15 +217,20 @@ class DispositionVoterTest extends TestCase
|
||||
{
|
||||
return [
|
||||
'assignment not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))],
|
||||
'ended before go-live' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('2025-12-31'))],
|
||||
'ended before the window' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('today -31 days'))],
|
||||
'skip formalities' => [static fn (Disposition $d) => $d->getAssignment()->setSkipFormalities(true)],
|
||||
'called off' => [static fn (Disposition $d) => $d->setStatus(Disposition::STATUS_CALLED_OFF)],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTheQuestionnaireIsOfferedToNobodyWithoutAGoLiveDate(): void
|
||||
public function testTheQuestionnaireIsStillOfferedOnTheWindowsLastDay(): void
|
||||
{
|
||||
$this->assertQuestionnaire(false, $this->escortDisposition(), goLive: null);
|
||||
$this->assertQuestionnaire(true, $this->escortDisposition(dateTo: 'today -30 days'));
|
||||
}
|
||||
|
||||
public function testTheWindowIsConfigurable(): void
|
||||
{
|
||||
$this->assertQuestionnaire(false, $this->escortDisposition(dateTo: 'today -8 days'), windowDays: 7);
|
||||
}
|
||||
|
||||
public function testAnotherTeamerMayNotFillInTheQuestionnaire(): void
|
||||
@@ -247,18 +252,11 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, (new User())->setTeamer($disposition->getTeamer()), '2026-01-01'),
|
||||
$this->questionnaireVote($disposition, (new User())->setTeamer($disposition->getTeamer()), 30),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAMalformedGoLiveDateFailsLoudly(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new DispositionVoter($this->security, '01.01.2026');
|
||||
}
|
||||
|
||||
private function assertQuestionnaire(bool $expected, Disposition $disposition, ?string $goLive = '2026-01-01', ?User $user = null): void
|
||||
private function assertQuestionnaire(bool $expected, Disposition $disposition, int $windowDays = 30, ?User $user = null): void
|
||||
{
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
@@ -267,20 +265,20 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, $user ?? (new User())->setTeamer($disposition->getTeamer()), $goLive),
|
||||
$this->questionnaireVote($disposition, $user ?? (new User())->setTeamer($disposition->getTeamer()), $windowDays),
|
||||
);
|
||||
}
|
||||
|
||||
private function questionnaireVote(Disposition $disposition, User $user, ?string $goLive): int
|
||||
private function questionnaireVote(Disposition $disposition, User $user, int $windowDays): int
|
||||
{
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token->method('getUser')->willReturn($user);
|
||||
|
||||
return (new DispositionVoter($this->security, $goLive))->vote($token, $disposition, [DispositionVoter::QUESTIONNAIRE]);
|
||||
return (new DispositionVoter($this->security, $windowDays))->vote($token, $disposition, [DispositionVoter::QUESTIONNAIRE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A bus escort that ended yesterday, after the go-live date the tests use.
|
||||
* A bus escort that ended yesterday, well within the 30-day window the tests use.
|
||||
*/
|
||||
private function escortDisposition(string $dateTo = 'yesterday'): Disposition
|
||||
{
|
||||
@@ -296,7 +294,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
private function vote(string $attribute, Disposition $disposition): int
|
||||
{
|
||||
return (new DispositionVoter($this->security, null))->vote(
|
||||
return (new DispositionVoter($this->security, 30))->vote(
|
||||
$this->createStub(TokenInterface::class),
|
||||
$disposition,
|
||||
[$attribute],
|
||||
|
||||
Reference in new issue
Block a user