feat: let the teamer fill in the questionnaire after a bus escort
This commit is contained in:
1 parent
df6734c939
commit
2a041d25a0
3 files changed
+166
-4
No files matched your search
@@ -6,6 +6,7 @@ namespace App\Tests\Security\Voter;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
@@ -158,7 +159,7 @@ class DispositionVoterTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
(new DispositionVoter($this->security))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
(new DispositionVoter($this->security, null))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -173,9 +174,119 @@ class DispositionVoterTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testTheTeamerMayFillInTheQuestionnaireAfterAnEscort(): void
|
||||
{
|
||||
$this->assertQuestionnaire(true, $this->escortDisposition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ending today already counts as over, as in DispositionRepository's feedback queries.
|
||||
*/
|
||||
public function testTheQuestionnaireOpensOnTheLastDay(): void
|
||||
{
|
||||
$this->assertQuestionnaire(true, $this->escortDisposition(dateTo: 'today'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Closure(Disposition): mixed $change
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('questionnaireDenials')]
|
||||
public function testTheQuestionnaireIsDenied(\Closure $change): void
|
||||
{
|
||||
$disposition = $this->escortDisposition();
|
||||
$change($disposition);
|
||||
|
||||
$this->assertQuestionnaire(false, $disposition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{\Closure(Disposition): mixed}>
|
||||
*/
|
||||
public static function questionnaireDenials(): array
|
||||
{
|
||||
return [
|
||||
'no bus escort' => [static fn (Disposition $d) => $d->getAssignment()->setPickup(0)],
|
||||
'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'))],
|
||||
'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
|
||||
{
|
||||
$this->assertQuestionnaire(false, $this->escortDisposition(), goLive: null);
|
||||
}
|
||||
|
||||
public function testAnotherTeamerMayNotFillInTheQuestionnaire(): void
|
||||
{
|
||||
$this->assertQuestionnaire(false, $this->escortDisposition(), user: (new User())->setTeamer(new Teamer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The office reads submitted responses through ROLE_ADMINISTRATIVE; filling one in on the
|
||||
* teamer's behalf is not a thing.
|
||||
*/
|
||||
public function testTheOfficeMayNotFillInTheQuestionnaire(): void
|
||||
{
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
->willReturnCallback(fn (string $role): bool => 'ROLE_ADMINISTRATIVE' === $role)
|
||||
;
|
||||
$disposition = $this->escortDisposition();
|
||||
|
||||
$this->assertSame(
|
||||
VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, (new User())->setTeamer($disposition->getTeamer()), '2026-01-01'),
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
$this->security
|
||||
->method('isGranted')
|
||||
->willReturnCallback(fn (string $role): bool => 'ROLE_TEAMER' === $role)
|
||||
;
|
||||
|
||||
$this->assertSame(
|
||||
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
|
||||
$this->questionnaireVote($disposition, $user ?? (new User())->setTeamer($disposition->getTeamer()), $goLive),
|
||||
);
|
||||
}
|
||||
|
||||
private function questionnaireVote(Disposition $disposition, User $user, ?string $goLive): int
|
||||
{
|
||||
$token = $this->createStub(TokenInterface::class);
|
||||
$token->method('getUser')->willReturn($user);
|
||||
|
||||
return (new DispositionVoter($this->security, $goLive))->vote($token, $disposition, [DispositionVoter::QUESTIONNAIRE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A bus escort that ended yesterday, after the go-live date the tests use.
|
||||
*/
|
||||
private function escortDisposition(string $dateTo = 'yesterday'): Disposition
|
||||
{
|
||||
$destination = (new Destination())->setDateTo(new \DateTimeImmutable($dateTo));
|
||||
$assignment = (new Assignment())
|
||||
->setDestination($destination)
|
||||
->setPickup(4711)
|
||||
->setSkipFormalities(false)
|
||||
;
|
||||
|
||||
return (new Disposition(new Application($assignment, new Teamer())))->setStatus(Disposition::STATUS_ENDED);
|
||||
}
|
||||
|
||||
private function vote(string $attribute, Disposition $disposition): int
|
||||
{
|
||||
return (new DispositionVoter($this->security))->vote(
|
||||
return (new DispositionVoter($this->security, null))->vote(
|
||||
$this->createStub(TokenInterface::class),
|
||||
$disposition,
|
||||
[$attribute],
|
||||
|
||||
Reference in new issue
Block a user