diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a48746996..e49648d29 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,13 +8,16 @@ use App\Models\User; use App\Notifications\SlowQueryLogged; use App\Observers\UserObserver; +use App\Policies\NotificationPolicy; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Database\Connection; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Events\QueryExecuted; use Illuminate\Http\Request; use Illuminate\Notifications\AnonymousNotifiable; +use Illuminate\Notifications\DatabaseNotification; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\Request as RequestFacade; @@ -41,6 +44,7 @@ public function boot(): void $this->bootEvent(); $this->bootRoute(); + $this->bootPolicies(); } private function bootEloquentMorphs() @@ -102,6 +106,10 @@ public function bootRoute(): void }); require base_path('routes/bindings.php'); + } + public function bootPolicies(): void + { + Gate::policy(DatabaseNotification::class, NotificationPolicy::class); } } diff --git a/tests/Feature/NotificationsTest.php b/tests/Feature/NotificationsTest.php index a8bbdde9f..9f4579f84 100644 --- a/tests/Feature/NotificationsTest.php +++ b/tests/Feature/NotificationsTest.php @@ -74,7 +74,7 @@ "A new reply was added to \"{$thread->subject()}\".", )) ->assertDispatched('NotificationMarkedAsRead'); -}); +})->only(); test('a_non_logged_in_user_cannot_access_notifications', function () { Livewire::test(Notifications::class)->assertForbidden(); diff --git a/tests/Integration/Models/ThreadTest.php b/tests/Integration/Models/ThreadTest.php index 0c149737b..48f96cced 100644 --- a/tests/Integration/Models/ThreadTest.php +++ b/tests/Integration/Models/ThreadTest.php @@ -87,6 +87,9 @@ $threadUpdatedYesterday = createThreadFromYesterday(); $threadFromToday = createThreadFromToday(); $threadFromTwoDaysAgo = createThreadFromTwoDaysAgo(); + + sleep(1); + dispatch_sync(new CreateReply(Str::uuid(), 'Hello world', User::factory()->create(), $threadFromTwoDaysAgo)); $threads = Thread::feed();