Add filter for preventions to yearly mail
This commit is contained in:
parent
5361c3930f
commit
9628ba34d2
|
@ -29,7 +29,8 @@ class YearlyRememberAction
|
||||||
}
|
}
|
||||||
|
|
||||||
$noticePreventions = $member->preventions($expireDate)
|
$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) {
|
if ($noticePreventions->count() === 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -45,7 +46,8 @@ class YearlyRememberAction
|
||||||
}
|
}
|
||||||
|
|
||||||
$preventions = $member->preventions()
|
$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) {
|
if ($preventions->count() === 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Prevention\Data;
|
namespace App\Prevention\Data;
|
||||||
|
|
||||||
use App\Prevention\Enums\Prevention;
|
use App\Prevention\Enums\Prevention;
|
||||||
|
use App\Prevention\PreventionSettings;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Spatie\LaravelData\Data;
|
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') . ')')
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,10 @@ uses(DatabaseTransactions::class);
|
||||||
uses(CreatesFormFields::class);
|
uses(CreatesFormFields::class);
|
||||||
uses(EndToEndTestCase::class);
|
uses(EndToEndTestCase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id')])->save();
|
||||||
|
});
|
||||||
|
|
||||||
function createForm(): Form
|
function createForm(): Form
|
||||||
{
|
{
|
||||||
return Form::factory()->fields([
|
return Form::factory()->fields([
|
||||||
|
@ -284,6 +288,17 @@ it('testItDoesntRememberParticipantThatHasNoMail', function () {
|
||||||
Mail::assertNotSent(PreventionRememberMail::class);
|
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 () {
|
it('doesnt send yearly mail when member has no mail', function () {
|
||||||
Mail::fake();
|
Mail::fake();
|
||||||
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);
|
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);
|
||||||
|
|
Loading…
Reference in New Issue