the browser-facing portion of osu!
at master 71 lines 2.1 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6declare(strict_types=1); 7 8namespace Tests\Jobs; 9 10use App\Jobs\Notifications\BroadcastNotificationBase; 11use App\Jobs\Notifications\ForumTopicReply; 12use App\Mail\UserNotificationDigest as UserNotificationDigestMail; 13use App\Models\Forum\Post; 14use App\Models\Forum\Topic; 15use App\Models\Forum\TopicWatch; 16use App\Models\User; 17use App\Models\UserNotificationOption; 18use Event; 19use Mail; 20use Queue; 21use Tests\TestCase; 22 23class UserNotificationDigestTest extends TestCase 24{ 25 public function testForumTopicReplyNotificationsShouldNotRenotify(): void 26 { 27 $sender = User::factory()->create(); 28 $topic = Topic::factory()->create(); 29 $user = User::factory()->create(); 30 31 $user->notificationOptions()->create([ 32 'name' => UserNotificationOption::FORUM_TOPIC_REPLY, 33 'details' => ['mail' => true], 34 ]); 35 TopicWatch::setState($topic, $user, 'watching_mail'); 36 37 $post = Post::factory()->create([ 38 'poster_id' => $sender, 39 'topic_id' => $topic, 40 ]); 41 42 $this->broadcastAndSendMail(new ForumTopicReply($post, $sender)); 43 Mail::assertSent(UserNotificationDigestMail::class); 44 45 $this->clearMailFake(); 46 47 (new ForumTopicReply($post, $sender))->dispatch(); 48 $this->broadcastAndSendMail(new ForumTopicReply($post, $sender)); 49 // update shouldn't be sent 50 Mail::assertNotSent(UserNotificationDigestMail::class); 51 } 52 53 protected function setUp(): void 54 { 55 parent::setUp(); 56 57 Queue::fake(); 58 Event::fake(); 59 Mail::fake(); 60 } 61 62 private function broadcastAndSendMail(BroadcastNotificationBase $notification): void 63 { 64 $notification->dispatch(); 65 $this->runFakeQueue(); 66 67 // run mail jobs 68 $this->artisan('notifications:send-mail'); 69 $this->runFakeQueue(); 70 } 71}