22
33namespace Tests \Feature \Notifications ;
44
5+ use App \Jobs \SendNewPluginNotifications ;
56use App \Models \Plugin ;
67use App \Models \User ;
78use App \Notifications \NewPluginAvailable ;
89use App \Services \PluginSyncService ;
910use Illuminate \Foundation \Testing \RefreshDatabase ;
10- use Illuminate \Support \Facades \Notification ;
11+ use Illuminate \Support \Facades \Bus ;
1112use Tests \TestCase ;
1213
1314class NewPluginAvailableTest extends TestCase
@@ -23,39 +24,34 @@ protected function setUp(): void
2324 });
2425 }
2526
26- public function test_notification_is_sent_to_opted_in_users_on_first_approval (): void
27+ public function test_notification_job_is_dispatched_on_first_approval (): void
2728 {
28- Notification ::fake ();
29+ Bus ::fake (SendNewPluginNotifications::class );
2930
3031 $ author = User::factory ()->create ();
31- $ optedIn = User::factory ()->create (['receives_new_plugin_notifications ' => true ]);
32- $ optedOut = User::factory ()->create (['receives_new_plugin_notifications ' => false ]);
33-
3432 $ plugin = Plugin::factory ()->pending ()->for ($ author )->create ();
3533 $ admin = User::factory ()->create ();
3634
3735 $ plugin ->approve ($ admin ->id );
3836
39- Notification:: assertSentTo ( $ optedIn , NewPluginAvailable ::class);
40- Notification:: assertNotSentTo ( $ optedOut , NewPluginAvailable::class) ;
41- Notification:: assertNotSentTo ( $ author , NewPluginAvailable::class );
37+ Bus:: assertDispatched (SendNewPluginNotifications ::class, function ( $ job ) use ( $ plugin ) {
38+ return $ job -> plugin -> id === $ plugin -> id ;
39+ } );
4240 }
4341
44- public function test_notification_is_not_sent_on_re_approval (): void
42+ public function test_notification_job_is_not_dispatched_on_re_approval (): void
4543 {
46- Notification ::fake ();
44+ Bus ::fake (SendNewPluginNotifications::class );
4745
4846 $ author = User::factory ()->create ();
49- $ optedIn = User::factory ()->create (['receives_new_plugin_notifications ' => true ]);
50-
5147 $ plugin = Plugin::factory ()->pending ()->for ($ author )->create ([
5248 'approved_at ' => now ()->subDay (),
5349 ]);
5450 $ admin = User::factory ()->create ();
5551
5652 $ plugin ->approve ($ admin ->id );
5753
58- Notification:: assertNotSentTo ( $ optedIn , NewPluginAvailable ::class);
54+ Bus:: assertNotDispatched (SendNewPluginNotifications ::class);
5955 }
6056
6157 public function test_via_returns_empty_array_when_user_opted_out (): void
0 commit comments