From 10542000c29fc0aa22a3453b2bbc0ce3354cfd0d Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Fri, 2 Oct 2026 16:01:25 +0200 Subject: [PATCH] test(notifications): cover a migrated unreachable marker that is older than the throttle window Co-Authored-By: Claude Opus 5.5 --- .../NotificationThrottlesMigrationTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Feature/NotificationThrottlesMigrationTest.php b/tests/Feature/NotificationThrottlesMigrationTest.php index 04a641205d..bf6e8ae8cc 100644 --- a/tests/Feature/NotificationThrottlesMigrationTest.php +++ b/tests/Feature/NotificationThrottlesMigrationTest.php @@ -5,9 +5,11 @@ use App\Models\ScheduledDatabaseBackup; use App\Models\Server; use App\Models\Team; use App\Notifications\Database\BackupMissing; +use App\Notifications\Server\Reachable; use App\Notifications\Server\Unreachable; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Schema; uses(RefreshDatabase::class); @@ -66,3 +68,31 @@ it('moves the old notification markers into notification_throttles and back', fu $migration->up(); }); + +it('keeps a migrated unreachable marker until the server is reachable again, however long ago it was set', function () { + Notification::fake(); + $team = Team::factory()->create(); + $team->emailNotificationSettings()->update([ + 'use_instance_email_settings' => true, + 'server_unreachable_email_notifications' => true, + 'server_reachable_email_notifications' => true, + ]); + $server = Server::factory()->create(['team_id' => $team->id]); + + $migration = require database_path('migrations/2026_09_29_083244_create_notification_throttles_table.php'); + $migration->down(); + DB::table('servers')->where('id', $server->id)->update(['unreachable_notification_sent' => true, 'updated_at' => now()]); + $migration->up(); + + $server->settings()->update(['is_reachable' => false]); + $server->forceFill(['unreachable_count' => 5])->save(); + + $this->travel(400)->days(); + $server->fresh()->isReachableChanged(); + Notification::assertNothingSent(); + + $server->settings()->update(['is_reachable' => true]); + $server->fresh()->isReachableChanged(); + Notification::assertSentTo($team, Reachable::class); + expect(NotificationThrottle::wasSent($server, Unreachable::class))->toBeFalse(); +});