From 9fc85485048bd72d064f0eb70c6c5a3f2f593964 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 20 Nov 2024 11:10:24 +0100 Subject: [PATCH] Fix: Dont remember past events --- app/Form/Actions/PreventionRememberAction.php | 7 ++++++- tests/Feature/Member/PreventionTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/Form/Actions/PreventionRememberAction.php b/app/Form/Actions/PreventionRememberAction.php index 9385ded0..7426a5c2 100644 --- a/app/Form/Actions/PreventionRememberAction.php +++ b/app/Form/Actions/PreventionRememberAction.php @@ -17,7 +17,12 @@ class PreventionRememberAction public function handle(): void { - $query = Participant::whereHas('form', fn ($form) => $form->where('needs_prevention', true)) + $query = Participant::whereHas( + 'form', + fn ($form) => $form + ->where('needs_prevention', true) + ->where('from', '>=', now()) + ) ->where( fn ($q) => $q ->where('last_remembered_at', '<=', now()->subWeeks(2)) diff --git a/tests/Feature/Member/PreventionTest.php b/tests/Feature/Member/PreventionTest.php index 6a277c67..bb25d46b 100644 --- a/tests/Feature/Member/PreventionTest.php +++ b/tests/Feature/Member/PreventionTest.php @@ -39,6 +39,18 @@ class PreventionTest extends TestCase $this->assertEquals(now()->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d')); } + public function testItDoesntRememberPastEvents(): void + { + Mail::fake(); + $form = $this->createForm(); + $participant = $this->createParticipant($form); + $form->update(['from' => now()->subDay()]); + + PreventionRememberAction::run(); + + $this->assertNull($participant->fresh()->last_remembered_at); + } + public function testItDoesntRememberWhenConditionDoesntMatch(): void { Mail::fake();