feat: keep questionnaires until submitted, remind teamers daily and take bus feedback per leg

This commit is contained in:
fromme committed 2026-11-10 16:38:51 +01:00
1 parent abf9c1be0b
commit e72616fdbf
37 files changed
+1119 -238

No files matched your search

@@ -8,15 +8,16 @@ use App\Config\QuestionnaireCatalog;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Teamer;
use App\Enum\BusLeg;
use App\Repository\DispositionRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Which questionnaires the dashboard reminds a teamer of. Run against db_test with real rows,
* because the question is which rows come back: the response is joined as an arbitrary entity,
* and a wrong JOIN condition would quietly let a draft, or a response to another questionnaire,
* decide the outcome.
* Which questionnaires the dashboard and the daily reminder mail remind a teamer of. Run against
* db_test with real rows, because the question is which rows come back: the responses are looked up
* in EXISTS subqueries, and a wrong condition there would quietly let a draft, a response to
* another questionnaire, or a second bus leg decide the outcome.
*
* Every test runs inside a transaction that is rolled back, so db_test - shared between
* branches - keeps nothing.
@@ -25,6 +26,8 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
{
use QuestionnaireFixturesTrait;
private const string GO_LIVE = '2026-01-01';
private EntityManagerInterface $entityManager;
private DispositionRepository $repository;
@@ -93,8 +96,8 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
}
/**
* Each questionnaire key belongs in its JOIN condition: in the WHERE clause, the response to
* one questionnaire would stand in for the other's.
* Each questionnaire key belongs in its own EXISTS: the response to one questionnaire must not
* stand in for the other's.
*/
public function testTheBusFeedbackDoesNotStandInForTheTeamerFeedback(): void
{
@@ -121,13 +124,42 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
$this->assertSame([['disposition' => $disposition, 'draft' => false]], $this->pending());
}
public function testAnAssignmentEndingOnTheWindowsFirstDayIsPending(): void
/**
* Only submitting ends it, however long ago the trip ended.
*/
public function testAnUnfinishedQuestionnaireStaysPendingLongAfterTheTrip(): void
{
$this->escort(dateTo: 'today -30 days');
$this->escort(dateTo: self::GO_LIVE);
$this->assertCount(1, $this->pending());
}
/**
* Two leg drafts are one placement on the dashboard, not two rows.
*/
public function testBothLegDraftsListThePlacementOnce(): void
{
$disposition = $this->escort();
$this->respond($disposition, submit: true);
$this->respond($disposition, submit: false, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::OUTBOUND);
$this->respond($disposition, submit: false, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::RETURN);
$this->assertSame([['disposition' => $disposition, 'draft' => true]], $this->pending());
}
/**
* An escort who rode only the return bus has a single leg response; it settles the bus
* feedback.
*/
public function testASubmittedReturnLegSettlesTheBusFeedback(): void
{
$disposition = $this->escort();
$this->respond($disposition, submit: true);
$this->respond($disposition, submit: true, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK, leg: BusLeg::RETURN);
$this->assertSame([], $this->pending());
}
public function testAnAssignmentEndingTodayIsPending(): void
{
$this->escort(dateTo: 'today');
@@ -154,7 +186,7 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
{
return [
'not over yet' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('tomorrow'))],
'ended before the window' => [static fn (Disposition $d) => $d->getAssignment()->getDestination()->setDateTo(new \DateTimeImmutable('today -31 days'))],
'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)],
'assignment called off' => [static fn (Disposition $d) => $d->getAssignment()->setStatus(Assignment::STATUS_CALLED_OFF)],
@@ -170,6 +202,66 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
$this->assertSame([], $this->pending());
}
/**
* The mail starts the day after the trip: on its last day the teamer is only just back.
*/
public function testTheReminderStartsTheDayAfterTheTrip(): void
{
$this->withUser($this->teamer);
$yesterday = $this->escort(dateTo: 'yesterday');
$this->escort(dateTo: 'today');
$this->assertSame([$yesterday], $this->reminded());
}
public function testTheReminderCoversEveryTeamerAndKeepsGoingUntilSubmitted(): void
{
$this->withUser($this->teamer);
$other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d');
$this->entityManager->persist($other);
$this->withUser($other);
$old = $this->escort(dateTo: self::GO_LIVE);
$draft = $this->escort(teamer: $other);
$this->respond($draft, submit: false);
$done = $this->escort();
$this->respond($done, submit: true);
$this->respond($done, submit: true, questionnaire: QuestionnaireCatalog::BUS_FEEDBACK);
$reminded = $this->reminded();
$this->assertContains($old, $reminded);
$this->assertContains($draft, $reminded);
$this->assertNotContains($done, $reminded);
}
/**
* A teamer who cannot log in cannot submit, and would be mailed every day forever.
*
* @param \Closure(Teamer, ?\App\Entity\User): mixed $change
*/
#[\PHPUnit\Framework\Attributes\DataProvider('notReminded')]
public function testTeamersWhoCannotLogInAreNotReminded(bool $withUser, \Closure $change): void
{
$user = $withUser ? $this->withUser($this->teamer) : null;
$change($this->teamer, $user);
$this->escort();
$this->assertSame([], $this->reminded());
}
/**
* @return array<string, array{bool, \Closure(Teamer, ?\App\Entity\User): mixed}>
*/
public static function notReminded(): array
{
return [
'no user account' => [false, static fn () => null],
'user blocked' => [true, static fn (Teamer $t, $user) => $user->setDisabledAt(new \DateTimeImmutable('yesterday'))],
'teamer deleted' => [true, static fn (Teamer $t) => $t->setDeleted()],
];
}
/**
* @return list<array{disposition: Disposition, draft: bool}>
*/
@@ -177,6 +269,16 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
{
$this->entityManager->flush();
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, QuestionnaireCatalog::windowStart(30));
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE));
}
/**
* @return list<Disposition>
*/
private function reminded(): array
{
$this->entityManager->flush();
return $this->repository->findQuestionnaireReminders(new \DateTimeImmutable(self::GO_LIVE), new \DateTimeImmutable('today'));
}
}