|
13 | 13 | use BookStack\Activity\WatchLevels;
|
14 | 14 | use BookStack\Entities\Models\Entity;
|
15 | 15 | use BookStack\Settings\UserNotificationPreferences;
|
| 16 | +use Illuminate\Contracts\Notifications\Dispatcher; |
| 17 | +use Illuminate\Support\Facades\Mail; |
16 | 18 | use Illuminate\Support\Facades\Notification;
|
17 | 19 | use Tests\TestCase;
|
18 | 20 |
|
@@ -365,6 +367,29 @@ public function test_notifications_sent_in_right_language()
|
365 | 367 | }
|
366 | 368 | }
|
367 | 369 |
|
| 370 | + public function test_failed_notifications_dont_block_and_log_errors() |
| 371 | + { |
| 372 | + $logger = $this->withTestLogger(); |
| 373 | + $editor = $this->users->editor(); |
| 374 | + $admin = $this->users->admin(); |
| 375 | + $page = $this->entities->page(); |
| 376 | + $book = $page->book; |
| 377 | + $activityLogger = app()->make(ActivityLogger::class); |
| 378 | + |
| 379 | + $watches = new UserEntityWatchOptions($editor, $book); |
| 380 | + $watches->updateLevelByValue(WatchLevels::UPDATES); |
| 381 | + |
| 382 | + $mockDispatcher = $this->mock(Dispatcher::class); |
| 383 | + $mockDispatcher->shouldReceive('send')->once() |
| 384 | + ->andThrow(\Exception::class, 'Failed to connect to mail server'); |
| 385 | + |
| 386 | + $this->actingAs($admin); |
| 387 | + |
| 388 | + $activityLogger->add(ActivityType::PAGE_UPDATE, $page); |
| 389 | + |
| 390 | + $this->assertTrue($logger->hasErrorThatContains("Failed to send email notification to user [id:{$editor->id}] with error: Failed to connect to mail server")); |
| 391 | + } |
| 392 | + |
368 | 393 | public function test_notifications_not_sent_if_lacking_view_permission_for_related_item()
|
369 | 394 | {
|
370 | 395 | $notifications = Notification::fake();
|
|
0 commit comments