Erinnerungsabstand und taegliche/woechentliche Zusammenfassung einstellbar
System > Betrieb > Benachrichtigungen: offene Meldungen (Doppelbuchungen im Postfach, Portal-Aufgaben) nur einmal oder alle 1/2/3/7 Tage erneut senden; Tages- und/oder Wochenuebersicht mit waehlbarer Uhrzeit, Wochentag und Inhalt (Postfach, Anfragen, Neues, An-/Abreisen, Zahlungen, Portale, Bewertungen). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
70a39315e2
commit
1c757f7429
20 files changed
+842
-22
No files matched your search
@@ -25,6 +25,7 @@
|
||||
use App\Models\InboxMessage;
|
||||
use App\Models\Property;
|
||||
use App\Models\User;
|
||||
use App\Tenancy\TenantContext;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Filament\Actions\CreateAction;
|
||||
@@ -149,6 +150,48 @@ public function test_a_lasting_double_booking_is_reported_once_however_often_the
|
||||
$this->assertSame(2, InboxMessage::count());
|
||||
}
|
||||
|
||||
public function test_an_unread_double_booking_is_repeated_after_the_chosen_interval_until_it_is_read(): void
|
||||
{
|
||||
$this->property->tenant->update(['reminder_interval_days' => 3]);
|
||||
Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12', 'status' => BookingStatus::Confirmed]);
|
||||
$channel = $this->channel('FeWo-direkt');
|
||||
$this->fakeFeed([['x1', '20261107', '20261110']]);
|
||||
(new SyncChannel)->handle($channel);
|
||||
|
||||
$this->travel(2)->days();
|
||||
(new SyncChannel)->handle($channel);
|
||||
Mail::assertSentCount(1);
|
||||
|
||||
$this->travel(1)->days();
|
||||
(new SyncChannel)->handle($channel);
|
||||
(new SyncChannel)->handle($channel);
|
||||
Mail::assertSentCount(2);
|
||||
Mail::assertSent(ChannelConflict::class, fn (ChannelConflict $mail): bool => $mail->conflicts === [] && count($mail->reminders) === 1
|
||||
&& str_starts_with($mail->envelope()->subject, 'Erinnerung'));
|
||||
|
||||
InboxMessage::sole()->update(['read_at' => now()]);
|
||||
$this->travel(4)->days();
|
||||
(new SyncChannel)->handle($channel);
|
||||
Mail::assertSentCount(2);
|
||||
}
|
||||
|
||||
public function test_open_portal_tasks_are_repeated_after_the_chosen_interval(): void
|
||||
{
|
||||
config(['fewo.channels.task_reminder_after_minutes' => 30]);
|
||||
$this->property->tenant->update(['reminder_interval_days' => 1]);
|
||||
app(TenantContext::class)->set($this->property->tenant);
|
||||
ChannelTask::factory()->for($this->channel('Ostseeklar', manual: true))->create(['created_at' => now()->subHour()]);
|
||||
|
||||
$this->assertSame(1, app(RemindChannelTasks::class)->handle());
|
||||
$this->assertSame(0, app(RemindChannelTasks::class)->handle());
|
||||
$this->travel(1)->days();
|
||||
$this->assertSame(1, app(RemindChannelTasks::class)->handle());
|
||||
|
||||
$this->property->tenant->update(['reminder_interval_days' => 0]);
|
||||
$this->travel(5)->days();
|
||||
$this->assertSame(0, app(RemindChannelTasks::class)->handle());
|
||||
}
|
||||
|
||||
public function test_failed_import_is_logged_and_alerted_once_until_it_works_again(): void
|
||||
{
|
||||
$channel = $this->channel('Ostseeklar');
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\SendDigests;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\DigestSection;
|
||||
use App\Filament\Pages\Operations;
|
||||
use App\Mail\Digest;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\InboxMessage;
|
||||
use App\Models\Property;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Tenancy\TenantConfig;
|
||||
use App\Tenancy\TenantContext;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DigestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Tenant $tenant;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config(['fewo.mail_redirect_to' => null]);
|
||||
$this->travelTo(CarbonImmutable::parse('2026-11-02 06:30'));
|
||||
$this->tenant = Tenant::factory()->create(['notification_emails' => 'vermieterin@example.com']);
|
||||
app(TenantContext::class)->set($this->tenant);
|
||||
app(TenantConfig::class)->refresh();
|
||||
$this->property = Property::factory()->create();
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_daily_summary_goes_out_once_from_the_chosen_hour(): void
|
||||
{
|
||||
$this->openRequest();
|
||||
$digests = app(SendDigests::class);
|
||||
|
||||
$this->assertNull($digests->handle($this->tenant));
|
||||
$this->travelTo(CarbonImmutable::parse('2026-11-02 07:00'));
|
||||
$this->assertSame('daily', $digests->handle($this->tenant->fresh()));
|
||||
$this->assertNull($digests->handle($this->tenant->fresh()));
|
||||
|
||||
Mail::assertSent(Digest::class, 1);
|
||||
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->hasTo('vermieterin@example.com') && ! $mail->weekly
|
||||
&& str_starts_with($mail->envelope()->subject, 'Tagesübersicht 02.11.2026: 2 Punkte'));
|
||||
}
|
||||
|
||||
public function test_on_the_weekly_day_only_the_weekly_summary_goes_out(): void
|
||||
{
|
||||
$this->openRequest();
|
||||
$this->tenant->update(['digest_weekly' => true, 'digest_weekday' => 1, 'digest_hour' => 6]);
|
||||
|
||||
$this->assertSame('weekly', app(SendDigests::class)->handle($this->tenant));
|
||||
$this->assertNull(app(SendDigests::class)->handle($this->tenant->fresh()));
|
||||
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->weekly && str_starts_with($mail->envelope()->subject, 'Wochenübersicht KW 45'));
|
||||
Mail::assertSent(Digest::class, 1);
|
||||
|
||||
$this->travel(1)->days();
|
||||
$this->assertSame('daily', app(SendDigests::class)->handle($this->tenant->fresh()));
|
||||
}
|
||||
|
||||
public function test_nothing_to_report_sends_nothing_unless_wanted(): void
|
||||
{
|
||||
$this->tenant->update(['digest_hour' => 6]);
|
||||
|
||||
$this->assertSame('daily', app(SendDigests::class)->handle($this->tenant));
|
||||
Mail::assertNothingSent();
|
||||
|
||||
$this->tenant->update(['digest_when_empty' => true, 'digest_daily_sent_on' => null]);
|
||||
app(SendDigests::class)->handle($this->tenant->fresh());
|
||||
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->sections === [] && str_ends_with($mail->envelope()->subject, 'nichts Neues'));
|
||||
}
|
||||
|
||||
public function test_summary_lists_requests_stays_payments_and_inbox_and_only_the_chosen_sections(): void
|
||||
{
|
||||
$this->openRequest();
|
||||
$this->booking(['arrival' => '2026-11-03', 'departure' => '2026-11-07'], 'Erika Mustermann');
|
||||
$this->booking(['arrival' => '2026-12-01', 'departure' => '2026-12-05', 'balance_due_on' => '2026-10-20', 'created_at' => now()->subWeek()], 'Hans Säumig');
|
||||
InboxMessage::factory()->create(['subject' => 'Mögliche Doppelbuchung über FeWo-direkt', 'body' => '<b>Ostsee</b>']);
|
||||
|
||||
app(SendDigests::class)->send($this->tenant, weekly: false);
|
||||
|
||||
Mail::assertSent(Digest::class, function (Digest $mail): bool {
|
||||
$html = $mail->render();
|
||||
$titles = array_column($mail->sections, 'title');
|
||||
|
||||
return in_array('Offene Anfragen und Angebote', $titles, true)
|
||||
&& in_array('An- und Abreisen heute und morgen', $titles, true)
|
||||
&& in_array('Überfällige Zahlungen', $titles, true)
|
||||
&& str_contains($html, 'Morgen: Anreise')
|
||||
&& str_contains($html, 'Erika Mustermann')
|
||||
&& str_contains($html, 'Hans Säumig')
|
||||
&& str_contains($html, 'Frist bis')
|
||||
&& str_contains($html, '<b>Ostsee</b>')
|
||||
&& ! str_contains($html, '<b>Ostsee</b>');
|
||||
});
|
||||
|
||||
Mail::fake();
|
||||
$this->tenant->update(['digest_sections' => [DigestSection::Inbox->value]]);
|
||||
app(SendDigests::class)->send($this->tenant->fresh(), weekly: false);
|
||||
Mail::assertSent(Digest::class, fn (Digest $mail): bool => array_column($mail->sections, 'section') === [DigestSection::Inbox]);
|
||||
}
|
||||
|
||||
public function test_settings_are_saved_on_the_operations_page_and_a_summary_can_be_sent_right_away(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
Livewire::test(Operations::class)
|
||||
->assertSet('data.reminder_interval_days', 0)
|
||||
->assertSet('data.digest_daily', true)
|
||||
->set('data.reminder_interval_days', 3)
|
||||
->set('data.digest_weekly', true)
|
||||
->set('data.digest_weekday', 5)
|
||||
->set('data.digest_hour', 18)
|
||||
->set('data.digest_sections', [DigestSection::Inbox->value, DigestSection::Portals->value])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->callAction('sendDigest', ['weekly' => 1]);
|
||||
|
||||
$tenant = $this->tenant->fresh();
|
||||
$this->assertSame([3, true, 5, 18], [$tenant->reminder_interval_days, $tenant->digest_weekly, $tenant->digest_weekday, $tenant->digest_hour]);
|
||||
$this->assertSame(['inbox', 'portals'], $tenant->digest_sections);
|
||||
Mail::assertSent(Digest::class, fn (Digest $mail): bool => $mail->weekly);
|
||||
}
|
||||
|
||||
private function openRequest(): Booking
|
||||
{
|
||||
return Booking::factory()->for($this->property)->reserved()->create(['guest_id' => Guest::factory()->create(['first_name' => 'Anna', 'last_name' => 'Anfrage'])->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
private function booking(array $attributes, string $name): Booking
|
||||
{
|
||||
[$first, $last] = explode(' ', $name);
|
||||
|
||||
return Booking::factory()->for($this->property)->create([
|
||||
'status' => BookingStatus::Confirmed,
|
||||
'guest_id' => Guest::factory()->create(['first_name' => $first, 'last_name' => $last])->id,
|
||||
...$attributes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user