From 77d7000df3be7f90ebb9662b536852b975868466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 11 Nov 2026 14:36:18 +0100 Subject: [PATCH] fix: remind house managers of their own pending list at the teamer reminder pace --- src/Repository/DestinationRepository.php | 11 ++ src/Repository/UserRepository.php | 22 +++ src/Service/Cron/FeedbackReminderService.php | 113 ++++++----- .../Cron/QuestionnaireReminderService.php | 16 +- src/Service/Cron/ReminderCadence.php | 29 +++ .../email/reminder_pending_feedback.html.twig | 27 ++- tests/Email/MailerTest.php | 2 +- .../ReminderPendingFeedbackTemplateTest.php | 41 ++++ .../HouseManagerReminderQueryTest.php | 108 +++++++++++ .../Cron/FeedbackReminderServiceTest.php | 178 ++++++++++++++++++ tests/Service/Cron/ReminderCadenceTest.php | 41 ++++ 11 files changed, 515 insertions(+), 73 deletions(-) create mode 100644 src/Service/Cron/ReminderCadence.php create mode 100644 tests/Email/ReminderPendingFeedbackTemplateTest.php create mode 100644 tests/Repository/HouseManagerReminderQueryTest.php create mode 100644 tests/Service/Cron/FeedbackReminderServiceTest.php create mode 100644 tests/Service/Cron/ReminderCadenceTest.php diff --git a/src/Repository/DestinationRepository.php b/src/Repository/DestinationRepository.php index db2d008..433d702 100644 --- a/src/Repository/DestinationRepository.php +++ b/src/Repository/DestinationRepository.php @@ -8,6 +8,7 @@ use App\Entity\Destination; use App\Entity\Disposition; use App\Entity\QuestionnaireResponse; use App\Entity\Teamer; +use App\Entity\User; use App\Enum\QuestionnaireResponseStatus; use App\Model\DestinationFilterDto; use App\Repository\Traits\QueryHelperTrait; @@ -169,6 +170,16 @@ class DestinationRepository extends ServiceEntityRepository ; } + /** + * getPendingForHouseManagerQuery() for one house manager. + * + * @return list + */ + public function findPendingForHouseManager(User $houseManager, \DateTimeImmutable $goLive, \DateTimeImmutable $endedBy): array + { + return $this->getPendingForHouseManagerQuery($houseManager->getHotelCodes(), $goLive, $endedBy, $houseManager->getTeamer())->getResult(); + } + /** * The ended travels a house manager still owes something for, one row per travel: the * questionnaire is not submitted (only for travels ended on or after $goLive), or a placement diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 6caff4b..0cf7460 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -121,6 +121,28 @@ class UserRepository extends ServiceEntityRepository ; } + /** + * The house managers the nightly reminder may write to: not deleted and not blocked - a blocked + * account cannot log in to do what it is reminded of. Hotel codes and muted notifications are + * the caller's to check. + * + * @return User[] + */ + public function findHouseManagersToRemind(): array + { + $qb = $this->createQueryBuilder('user'); + + return $qb + ->where('JSON_CONTAINS(user.roles, :role) = 1') + ->andWhere($qb->expr()->isNull('user.deletedAt')) + ->andWhere($qb->expr()->isNull('user.disabledAt')) + ->setParameter('role', json_encode('ROLE_HOUSE_MANAGER')) + ->orderBy('user.id') + ->getQuery() + ->getResult() + ; + } + public function getAutocompletionData(string $search, string $role): array { $qb = $this->createQueryBuilder('user'); diff --git a/src/Service/Cron/FeedbackReminderService.php b/src/Service/Cron/FeedbackReminderService.php index be4e4f6..b18dd8b 100644 --- a/src/Service/Cron/FeedbackReminderService.php +++ b/src/Service/Cron/FeedbackReminderService.php @@ -2,18 +2,25 @@ namespace App\Service\Cron; -use App\BusProNet\DataProvider\HotelDataProvider; use App\Config\QuestionnaireCatalog; use App\Email\Mailer; use App\Entity\Destination; +use App\Enum\QuestionnaireResponseStatus; use App\Repository\DestinationRepository; use App\Repository\UserRepository; use Psr\Log\LoggerInterface; /** - * Reminds house managers, daily, of the travels they still owe something for: the questionnaire - * about the travel or a teamer's rating - the house manager's pending list - * (DestinationRepository::getPendingForHouseManagerQuery()). + * Reminds house managers of the travels they still owe something for: the questionnaire about the + * travel or a teamer's rating. + * + * Each house manager gets exactly their dashboard's pending list + * (DestinationRepository::getPendingForHouseManagerQuery() with their own hotel codes and teamer), + * so they are never reminded of a rating they cannot give - their own placement on a travel - and + * the mail never disagrees with what they find after logging in. + * + * At the pace of ReminderCadence, like the teamer questionnaire reminder: a house manager is mailed + * on a night when any of their pending travels is due, and the mail lists all of them. */ class FeedbackReminderService { @@ -21,7 +28,6 @@ class FeedbackReminderService public function __construct( private readonly DestinationRepository $destinationRepository, - private readonly HotelDataProvider $hotelDataProvider, private readonly UserRepository $userRepository, private readonly Mailer $mailer, private readonly LoggerInterface $logger, @@ -30,74 +36,65 @@ class FeedbackReminderService $this->goLive = QuestionnaireCatalog::parseGoLive($houseManagerQuestionnaireGoLive); } - public function sendFeedbackReminders(): string + public function sendFeedbackReminders(?\DateTimeImmutable $today = null): string { - /** @var list $pendingTravels */ - $pendingTravels = array_column( - $this->destinationRepository->getPendingForHouseManagerQuery(null, $this->goLive, new \DateTimeImmutable('today'))->getResult(), - 0, - ); + $today = ($today ?? new \DateTimeImmutable('today'))->setTime(0, 0); + $count = 0; - $sortedFeedbacks = []; - - foreach ($pendingTravels as $destination) { - // Get hotel by bus pro id - $hotelBusProId = $destination->getHotelBusProId(); - $hotel = $this->hotelDataProvider->get($hotelBusProId); - - if (null === $hotel) { - $this->logger->error('Could not find hotel by bus pro id '.$hotelBusProId); + foreach ($this->userRepository->findHouseManagersToRemind() as $houseManager) { + if (true === $houseManager->isMuteNotifications() || [] === $houseManager->getHotelCodes()) { continue; } - // Get hotel code to find hotel manager later - $hotelCode = $hotel->getCode(); + // ended yesterday or earlier, like the teamer reminder: the day a travel ends is not yet + // the time to ask about it + $pending = $this->destinationRepository->findPendingForHouseManager($houseManager, $this->goLive, $today->modify('-1 day')); + $due = array_filter($pending, fn (array $row): bool => ReminderCadence::isDue($row[0]->getDateTo(), $today)); - if (false === array_key_exists($hotelCode, $sortedFeedbacks)) { - $sortedFeedbacks[$hotelCode] = []; - } - - // Sort feedback by hotel base code - $sortedFeedbacks[$hotelCode][] = $destination; - } - - // find hotel managers by hotel codes starting or ending with base code - $hotelCodes = array_keys($sortedFeedbacks); - $hotelBaseCodes = []; - foreach ($hotelCodes as $hotelCode) { - $hotelBaseCodes[] = substr($hotelCode, 0, 3); - $hotelBaseCodes[] = substr($hotelCode, -3, 3); - } - - $hotelManagers = $this - ->userRepository - ->getUsersByRoleAndHotelCode('ROLE_HOUSE_MANAGER', $hotelBaseCodes) - ; - - if (0 === count($hotelManagers)) { - return 'No feedback reminders to be sent to hotel managers'; - } - - foreach ($hotelManagers as $manager) { - if (true === $manager->isMuteNotifications()) { + if ([] === $due) { continue; } - $feedbackKeys = array_filter(array_keys($sortedFeedbacks), function (string $key) use ($manager) { - return $manager->hasHotelCodeMatch($key); - }); - $feedbacksForManager = array_filter($sortedFeedbacks, function ($key) use ($feedbackKeys) { - return in_array($key, $feedbackKeys); - }, ARRAY_FILTER_USE_KEY); + $this->mailer->createAndSendEmail([ - 'feedbacks' => $feedbacksForManager, + 'travels' => array_map($this->describe(...), $pending), ], [ - 'to' => $manager->getEmail(), + 'to' => $houseManager->getEmail(), 'subject' => 'Reminder: Offene Feedbacks und Fragebögen', 'template' => 'email/reminder_pending_feedback.html.twig', 'transport' => Mailer::MAILJET_TRANSPORT, ]); + + ++$count; } - return 'Sent feedback reminders to '.count($hotelManagers).' hotel managers'; + $message = 'Sent feedback reminders to '.$count.' house managers'; + $this->logger->info($message); + + return $message; + } + + /** + * What the mail says about one pending travel: whether the questionnaire is still owed - only + * for travels ended since it went live, as on the pending page - and how many teamers are left + * to rate. + * + * @param array{0: Destination, questionnaireStatus: ?string, openFeedbacks: int} $row + * + * @return array{destination: Destination, questionnaire: ?string, openRatings: int} + */ + private function describe(array $row): array + { + $destination = $row[0]; + $questionnaire = null; + + if ($destination->getDateTo() >= $this->goLive && QuestionnaireResponseStatus::SUBMITTED->value !== $row['questionnaireStatus']) { + $questionnaire = QuestionnaireResponseStatus::DRAFT->value === $row['questionnaireStatus'] ? 'draft' : 'open'; + } + + return [ + 'destination' => $destination, + 'questionnaire' => $questionnaire, + 'openRatings' => (int) $row['openFeedbacks'], + ]; } } diff --git a/src/Service/Cron/QuestionnaireReminderService.php b/src/Service/Cron/QuestionnaireReminderService.php index a881333..4e68bbf 100644 --- a/src/Service/Cron/QuestionnaireReminderService.php +++ b/src/Service/Cron/QuestionnaireReminderService.php @@ -11,18 +11,14 @@ use Psr\Log\LoggerInterface; /** * Reminds teamers of their unsubmitted questionnaires until they are submitted - a saved draft does - * not count: every night for the first week after the trip, then once a week, so a teamer who never - * submits is not mailed every night for the rest of the season. One mail per teamer on a night when - * any of their placements is due, listing every placement they still owe. + * not count - at the pace of ReminderCadence. One mail per teamer on a night when any of their + * placements is due, listing every placement they still owe. * * Like the other reminders it records nothing: whether a placement is due is a function of the day, * and the cron runs once a day. */ class QuestionnaireReminderService { - /** nights after the trip with a reminder each, before it turns weekly */ - private const int DAILY_NIGHTS = 7; - private readonly \DateTimeImmutable $questionnaireGoLive; /** @@ -77,14 +73,8 @@ class QuestionnaireReminderService return $message; } - /** - * Nights 1 to 7 after the trip, then nights 14, 21, ... The repository only returns - * placements that ended yesterday or earlier. - */ private function isDue(Disposition $disposition, \DateTimeImmutable $today): bool { - $nights = (int) $disposition->getAssignment()->getDestination()->getDateTo()->setTime(0, 0)->diff($today)->days; - - return $nights <= self::DAILY_NIGHTS || 0 === $nights % 7; + return ReminderCadence::isDue($disposition->getAssignment()->getDestination()->getDateTo(), $today); } } diff --git a/src/Service/Cron/ReminderCadence.php b/src/Service/Cron/ReminderCadence.php new file mode 100644 index 0000000..ed7ca2b --- /dev/null +++ b/src/Service/Cron/ReminderCadence.php @@ -0,0 +1,29 @@ +setTime(0, 0)->diff($today->setTime(0, 0))->days; + + return $nights > 0 && ($nights <= self::DAILY_NIGHTS || 0 === $nights % 7); + } +} diff --git a/templates/email/reminder_pending_feedback.html.twig b/templates/email/reminder_pending_feedback.html.twig index f00c5b4..f2ff3f1 100644 --- a/templates/email/reminder_pending_feedback.html.twig +++ b/templates/email/reminder_pending_feedback.html.twig @@ -4,4 +4,29 @@

Reminder zu ausstehenden Feedbacks und Fragebögen

-{% endblock %} \ No newline at end of file +

+ Für diese Reisen steht noch etwas von dir aus: +

+ {% for travel in travels %} + {% set destination = travel.destination %} +

+ {{ destination.dateFrom|date('d.m.Y') }} - {{ destination.dateTo|date('d.m.Y') }}, {{ destination.product }}{% if destination.hotel %} ({{ destination.hotel }}){% endif %}
+ {% if travel.questionnaire == 'draft' %} + Fragebogen als Entwurf gespeichert, noch nicht abgeschickt
+ {% elseif travel.questionnaire == 'open' %} + Fragebogen noch nicht ausgefüllt
+ {% endif %} + {% if travel.openRatings == 1 %} + 1 Teamer:in noch nicht bewertet
+ {% elseif travel.openRatings > 1 %} + {{ travel.openRatings }} Teamer:innen noch nicht bewertet
+ {% endif %} +

+ {% endfor %} +{% endblock %} + +{% block button %} +

+ Zum ausstehenden Feedback +

+{% endblock %} diff --git a/tests/Email/MailerTest.php b/tests/Email/MailerTest.php index 96d5b35..0d8dc57 100644 --- a/tests/Email/MailerTest.php +++ b/tests/Email/MailerTest.php @@ -40,7 +40,7 @@ class MailerTest extends KernelTestCase { self::bootKernel(); - return self::getContainer()->get(Mailer::class)->create(['feedbacks' => []], [ + return self::getContainer()->get(Mailer::class)->create(['travels' => []], [ 'from' => 'test@example.com', 'to' => 'teamer@example.com', 'subject' => 'Betreff', diff --git a/tests/Email/ReminderPendingFeedbackTemplateTest.php b/tests/Email/ReminderPendingFeedbackTemplateTest.php new file mode 100644 index 0000000..c922cee --- /dev/null +++ b/tests/Email/ReminderPendingFeedbackTemplateTest.php @@ -0,0 +1,41 @@ +setProduct('Davos Klosters') + ->setHotel('Schwendi') + ->setDateFrom(new \DateTimeImmutable('2026-11-06')) + ->setDateTo(new \DateTimeImmutable('2026-11-13')) + ; + + // rendered the way the mailer does, which also hands the layout its "email" variable + $email = (new TemplatedEmail()) + ->htmlTemplate('email/reminder_pending_feedback.html.twig') + ->context(['travels' => [ + ['destination' => $destination, 'questionnaire' => 'draft', 'openRatings' => 2], + ]]) + ; + self::getContainer()->get(BodyRendererInterface::class)->render($email); + $html = (string) $email->getHtmlBody(); + + $this->assertStringContainsString('06.11.2026 - 13.11.2026, Davos Klosters (Schwendi)', $html); + $this->assertStringContainsString('Fragebogen als Entwurf gespeichert, noch nicht abgeschickt', $html); + $this->assertStringContainsString('2 Teamer:innen noch nicht bewertet', $html); + $this->assertStringContainsString('/house-manager/pending-feedback', $html); + } +} diff --git a/tests/Repository/HouseManagerReminderQueryTest.php b/tests/Repository/HouseManagerReminderQueryTest.php new file mode 100644 index 0000000..b7c8b5a --- /dev/null +++ b/tests/Repository/HouseManagerReminderQueryTest.php @@ -0,0 +1,108 @@ +entityManager = self::getContainer()->get(EntityManagerInterface::class); + $this->entityManager->getConnection()->beginTransaction(); + + $this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d'); + $this->entityManager->persist($this->teamer); + } + + protected function tearDown(): void + { + $this->entityManager->getConnection()->rollBack(); + parent::tearDown(); + } + + /** + * A house manager who worked on the travel themselves does not rate their own placement, so + * it must not keep the travel pending for them - only someone else's unrated one does. + */ + public function testTheHouseManagersOwnPlacementDoesNotKeepATravelPending(): void + { + $houseManager = $this->houseManager('own@example.org'); + $ownOnly = $this->escort(teamer: $houseManager->getTeamer(), hotel: 'Nur selbst')->getAssignment()->getDestination(); + $withOther = $this->escort(hotel: 'Mit anderen')->getAssignment()->getDestination(); + $this->entityManager->flush(); + + $pending = array_column($this->destinationRepository()->findPendingForHouseManager( + $houseManager, + new \DateTimeImmutable('2099-01-01'), // questionnaire not live: only ratings count + new \DateTimeImmutable('today') + ), 0); + + $this->assertContains($withOther, $pending); + $this->assertNotContains($ownOnly, $pending); + } + + public function testBlockedAndDeletedHouseManagersAreNotReminded(): void + { + $active = $this->houseManager('active@example.org'); + $blocked = $this->houseManager('blocked@example.org')->setDisabledAt(new \DateTimeImmutable()); + $deleted = $this->houseManager('deleted@example.org')->setDeletedAt(new \DateTimeImmutable()); + $this->entityManager->flush(); + + /** @var UserRepository $repository */ + $repository = $this->entityManager->getRepository(User::class); + $reminded = $repository->findHouseManagersToRemind(); + + $this->assertContains($active, $reminded); + $this->assertNotContains($blocked, $reminded); + $this->assertNotContains($deleted, $reminded); + } + + private function houseManager(string $email): User + { + $teamer = (new Teamer())->setFirstName('Hanna')->setLastName('Haus')->setGender('d'); + $user = (new User()) + ->setFirstName('Hanna') + ->setLastName('Haus') + ->setEmail(uniqid('', true).'.'.$email) + ->setRoles(['ROLE_HOUSE_MANAGER']) + ->setHotelCodes(['DKI']) + ->setBusProAddressId(1) + ->setBusProPersonId(1) + ->setTeamer($teamer) + ; + $teamer->setUser($user); + + $this->entityManager->persist($teamer); + $this->entityManager->persist($user); + + return $user; + } + + private function destinationRepository(): DestinationRepository + { + return $this->entityManager->getRepository(Destination::class); + } +} diff --git a/tests/Service/Cron/FeedbackReminderServiceTest.php b/tests/Service/Cron/FeedbackReminderServiceTest.php new file mode 100644 index 0000000..b944212 --- /dev/null +++ b/tests/Service/Cron/FeedbackReminderServiceTest.php @@ -0,0 +1,178 @@ +destinationRepository = $this->createMock(DestinationRepository::class); + $this->userRepository = $this->createMock(UserRepository::class); + $this->mailer = $this->createMock(Mailer::class); + + $this->service = new FeedbackReminderService( + $this->destinationRepository, + $this->userRepository, + $this->mailer, + new NullLogger(), + '2026-11-11' + ); + } + + /** + * Their own hotel codes and their own teamer, so their own placement on a travel is never + * among what they are reminded of; travels ended yesterday or earlier. + */ + public function testEachHouseManagerIsAskedAboutWithTheirOwnCodesAndTeamer(): void + { + $houseManager = $this->houseManager('anna@example.org', ['DKI']); + + $this->userRepository->method('findHouseManagersToRemind')->willReturn([$houseManager]); + $this->destinationRepository + ->expects($this->once()) + ->method('findPendingForHouseManager') + ->with($houseManager, new \DateTimeImmutable('2026-11-11'), new \DateTimeImmutable('2026-11-19')) + ->willReturn([]) + ; + + $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY.' 01:00'))); + } + + public function testMutedHouseManagersAndThoseWithoutHotelCodesAreSkipped(): void + { + $this->userRepository->method('findHouseManagersToRemind')->willReturn([ + $this->houseManager('muted@example.org', ['DKI'])->setMuteNotifications(true), + $this->houseManager('nohouse@example.org', []), + ]); + $this->destinationRepository->expects($this->never())->method('findPendingForHouseManager'); + $this->mailer->expects($this->never())->method('createAndSendEmail'); + + // skipped ones are not counted as reminded + $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); + } + + /** + * The teamer reminder's pace: nothing is due on night 10, so no mail, though the travel is + * still pending. + */ + public function testNoMailOnANightNothingIsDue(): void + { + $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); + $this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($this->travel(10))]); + $this->mailer->expects($this->never())->method('createAndSendEmail'); + + $this->assertSame('Sent feedback reminders to 0 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); + } + + /** + * One travel due tonight brings the whole list along, the one on its quiet night 10 included. + */ + public function testADueTravelBringsTheWholeListAlong(): void + { + $due = $this->travel(14); + $quiet = $this->travel(10); + + $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); + $this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($quiet), $this->row($due)]); + $this->mailer + ->expects($this->once()) + ->method('createAndSendEmail') + ->willReturnCallback(function (array $context, array $options) use ($due, $quiet): void { + $this->assertSame('anna@example.org', $options['to']); + $this->assertSame(Mailer::MAILJET_TRANSPORT, $options['transport']); + $this->assertSame([$quiet, $due], array_column($context['travels'], 'destination')); + }) + ; + + $this->assertSame('Sent feedback reminders to 1 house managers', $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY))); + } + + /** + * The questionnaire is only owed for travels ended since it went live (2026-11-11 here), and + * a draft is told apart from one never started. + */ + public function testEachTravelSaysWhatIsStillOpen(): void + { + $beforeGoLive = $this->travel(14); // ended 2026-11-06 + $draft = $this->travel(7); // ended 2026-11-13 + $untouched = $this->travel(3); // ended 2026-11-17 + $submitted = $this->travel(1); // ended 2026-11-19 + + $this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('anna@example.org', ['DKI'])]); + $this->destinationRepository->method('findPendingForHouseManager')->willReturn([ + $this->row($beforeGoLive, null, 2), + $this->row($draft, 'draft', 0), + $this->row($untouched, null, 1), + $this->row($submitted, 'submitted', 3), + ]); + + $travels = null; + $this->mailer + ->method('createAndSendEmail') + ->willReturnCallback(function (array $context) use (&$travels): void { + $travels = $context['travels']; + }) + ; + + $this->service->sendFeedbackReminders(new \DateTimeImmutable(self::TODAY)); + + $this->assertSame( + [[null, 2], ['draft', 0], ['open', 1], [null, 3]], + array_map(fn (array $travel) => [$travel['questionnaire'], $travel['openRatings']], $travels) + ); + } + + /** + * @param list $hotelCodes + */ + private function houseManager(string $email, array $hotelCodes): User + { + return (new User()) + ->setEmail($email) + ->setRoles(['ROLE_HOUSE_MANAGER']) + ->setHotelCodes($hotelCodes) + ->setTeamer(new Teamer()) + ; + } + + /** + * @return array{0: Destination, questionnaireStatus: ?string, placements: int, openFeedbacks: int} + */ + private function row(Destination $destination, ?string $questionnaireStatus = null, int $openFeedbacks = 1): array + { + return [$destination, 'questionnaireStatus' => $questionnaireStatus, 'placements' => 2, 'openFeedbacks' => $openFeedbacks]; + } + + private function travel(int $endedNightsAgo): Destination + { + $dateTo = (new \DateTimeImmutable(self::TODAY))->modify(sprintf('-%d days', $endedNightsAgo)); + + return (new Destination())->setDateFrom($dateTo->modify('-7 days'))->setDateTo($dateTo); + } +} diff --git a/tests/Service/Cron/ReminderCadenceTest.php b/tests/Service/Cron/ReminderCadenceTest.php new file mode 100644 index 0000000..0ff3437 --- /dev/null +++ b/tests/Service/Cron/ReminderCadenceTest.php @@ -0,0 +1,41 @@ + + */ + public static function nights(): iterable + { + yield 'the day the trip ends' => [0, false]; + yield 'first night after' => [1, true]; + yield 'last daily night' => [7, true]; + yield 'first quiet night' => [8, false]; + yield 'still quiet' => [13, false]; + yield 'two weeks' => [14, true]; + yield 'three weeks' => [21, true]; + yield 'between the weeks' => [22, false]; + yield 'months later' => [70, true]; + } + + #[DataProvider('nights')] + public function testDailyForAWeekThenWeekly(int $nights, bool $due): void + { + $today = new \DateTimeImmutable('2026-11-20'); + + $this->assertSame($due, ReminderCadence::isDue($today->modify(sprintf('-%d days', $nights)), $today)); + } + + public function testTheTimeOfDayDoesNotCount(): void + { + $this->assertTrue(ReminderCadence::isDue(new \DateTimeImmutable('2026-11-13 23:59'), new \DateTimeImmutable('2026-11-20 01:00'))); + } +}