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
@@ -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