Add filter for preventions to yearly mail

This commit is contained in:
philipp lang 2025-05-30 02:02:32 +02:00
parent 5361c3930f
commit 9628ba34d2
3 changed files with 25 additions and 2 deletions

View File

@ -29,7 +29,8 @@ class YearlyRememberAction
}
$noticePreventions = $member->preventions($expireDate)
->filter(fn($prevention) => $prevention->expiresAt($expireDate));
->filter(fn($prevention) => $prevention->expiresAt($expireDate))
->filter(fn($p) => $p->appliesToSettings($settings));
if ($noticePreventions->count() === 0) {
continue;
@ -45,7 +46,8 @@ class YearlyRememberAction
}
$preventions = $member->preventions()
->filter(fn($prevention) => $prevention->expiresAt(now()));
->filter(fn($prevention) => $prevention->expiresAt(now()))
->filter(fn($p) => $p->appliesToSettings($settings));
if ($preventions->count() === 0) {
continue;

View File

@ -3,6 +3,7 @@
namespace App\Prevention\Data;
use App\Prevention\Enums\Prevention;
use App\Prevention\PreventionSettings;
use Carbon\Carbon;
use Spatie\LaravelData\Data;
@ -22,4 +23,9 @@ class PreventionData extends Data
fn($str) => $str->append(' (fällig am ' . $this->expires->format('d.m.Y') . ')')
);
}
public function appliesToSettings(PreventionSettings $settings): bool
{
return in_array($this->type->name, $settings->preventAgainst);
}
}

View File

@ -27,6 +27,10 @@ uses(DatabaseTransactions::class);
uses(CreatesFormFields::class);
uses(EndToEndTestCase::class);
beforeEach(function () {
app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id')])->save();
});
function createForm(): Form
{
return Form::factory()->fields([
@ -284,6 +288,17 @@ it('testItDoesntRememberParticipantThatHasNoMail', function () {
Mail::assertNotSent(PreventionRememberMail::class);
});
it('doesnt remember when prevent against doesnt match', function () {
Mail::fake();
app(PreventionSettings::class)->fill(['preventAgainst' => []])->save();
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]);
sleep(2);
YearlyRememberAction::run();
Mail::assertNotSent(YearlyMail::class);
});
it('doesnt send yearly mail when member has no mail', function () {
Mail::fake();
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);