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();