diff --git a/src/Notifications/CheckFailedNotification.php b/src/Notifications/CheckFailedNotification.php index 63a5771..99da4a1 100644 --- a/src/Notifications/CheckFailedNotification.php +++ b/src/Notifications/CheckFailedNotification.php @@ -21,6 +21,7 @@ class CheckFailedNotification extends Notification implements ShouldQueue public function __construct(protected Check $check, protected Result $result) { + // } public function getDriver(string $alias): string diff --git a/tests/Feature/NotificationTest.php b/tests/Feature/NotificationTest.php new file mode 100644 index 0000000..175db0a --- /dev/null +++ b/tests/Feature/NotificationTest.php @@ -0,0 +1,79 @@ +failed('failed'); + } +}; + +it('sends a notification if a check has failed', function () use ($failed) { + + config()->set('ok.notifications.via.mail.to', 'test@example.com'); + + $check = $failed->setNotificationInterval(1); + + $event = new CheckFailed($check, $check->run()); + + Notification::fake(); + + Cache::driver('file')->forget('laravel-ok::notifications::'.$check::class); + + event($event); + + Notification::assertSentTimes( + CheckFailedNotification::class, 1 + ); +}); + +it('doesn\'t send a notification if the notification interval has not yet passed', function () use ($failed) { + config()->set('ok.notifications.via.mail.to', 'test@example.com'); + + $check = $failed->setNotificationInterval(30); + + $event = new CheckFailed($check, $check->run()); + + Notification::fake(); + + Cache::driver('file')->forget('laravel-ok::notifications::'.$check::class); + + event($event); + + event($event); + + Notification::assertSentTimes( + CheckFailedNotification::class, 1 + ); +}); + +it('does send a notification when the notification interval has passed', function () use ($failed) { + config()->set('ok.notifications.via.mail.to', 'test@example.com'); + + $check = $failed->setNotificationInterval(30); + + $event = new CheckFailed($check, $check->run()); + + Notification::fake(); + + Cache::driver('file')->forget('laravel-ok::notifications::'.$check::class); + + event($event); + + travel(30)->minutes(); + + event($event); + + Notification::assertSentTimes( + CheckFailedNotification::class, 2 + ); +});