@@ -25,37 +25,95 @@ public function setUp(): void
2525
2626 $ this ->notification = new TestNotification ;
2727
28- $ this ->notifiable = new TestNotifiable ;
28+ $ this ->notifiableInterest = new TestNotifiableInterest ;
29+ $ this ->notifiableInterests = new TestNotifiableInterests ;
30+
31+ $ this ->notifiableUser = new TestNotifiableUser ;
32+ $ this ->notifiableUsers = new TestNotifiableUsers ;
2933 }
3034
3135 /** @test */
32- public function it_can_send_a_notification ()
36+ public function it_can_send_a_notification_to_interest ()
3337 {
34- $ message = $ this ->notification ->toPushNotification ($ this ->notifiable );
38+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableInterest );
3539
3640 $ data = $ message ->toArray ();
3741
3842 $ this ->pusher ->shouldReceive ('publishToInterests ' )->once ()->with (['interest_name ' ], $ data );
3943
40- $ this ->channel ->send ($ this ->notifiable , $ this ->notification );
44+ $ this ->channel ->send ($ this ->notifiableInterest , $ this ->notification );
45+ }
46+
47+ /** @test */
48+ public function it_can_send_a_notification_to_interests ()
49+ {
50+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableInterests );
51+
52+ $ data = $ message ->toArray ();
53+
54+ $ this ->pusher ->shouldReceive ('publishToInterests ' )->once ()->with ([
55+ 'interest_one ' , 'interest_two ' , 'interest_three ' ,
56+ ], $ data );
57+
58+ $ this ->channel ->send ($ this ->notifiableInterests , $ this ->notification );
4159 }
4260
4361 /** @test */
44- public function it_fires_failure_event_on_failure ()
62+ public function it_fires_failure_event_on_interest_failure ()
4563 {
46- $ message = $ this ->notification ->toPushNotification ($ this ->notifiable );
64+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableInterest );
4765
4866 $ data = $ message ->toArray ();
4967
5068 $ this ->pusher ->shouldReceive ('publishToInterests ' )->once ()->with (['interest_name ' ], $ data )->andThrow (new Exception ('Something happened ' ));
5169
5270 $ this ->events ->shouldReceive ('dispatch ' )->once ()->with (Mockery::type (NotificationFailed::class));
5371
54- $ this ->channel ->send ($ this ->notifiable , $ this ->notification );
72+ $ this ->channel ->send ($ this ->notifiableInterest , $ this ->notification );
73+ }
74+
75+ /** @test */
76+ public function it_can_send_a_notification_to_user ()
77+ {
78+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableUser );
79+
80+ $ data = $ message ->toArray ();
81+
82+ $ this ->pusher ->shouldReceive ('publishToUsers ' )->once ()->with (['user_1 ' ], $ data );
83+
84+ $ this ->channel ->send ($ this ->notifiableUser , $ this ->notification );
85+ }
86+
87+ /** @test */
88+ public function it_can_send_a_notification_to_users ()
89+ {
90+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableUsers );
91+
92+ $ data = $ message ->toArray ();
93+
94+ $ this ->pusher ->shouldReceive ('publishToUsers ' )->once ()->with ([
95+ 'user_1 ' , 'user_2 ' , 'user_3 ' ,
96+ ], $ data );
97+
98+ $ this ->channel ->send ($ this ->notifiableUsers , $ this ->notification );
99+ }
100+
101+ /** @test */
102+ public function it_fires_failure_event_on_user_failure ()
103+ {
104+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableUser );
105+
106+ $ data = $ message ->toArray ();
107+
108+ $ this ->pusher ->shouldReceive ('publishToUsers ' )->once ()->with (['user_1 ' ], $ data )->andThrow (new Exception ('Something happened ' ));
109+
110+ $ this ->events ->shouldReceive ('dispatch ' )->once ()->with (Mockery::type (NotificationFailed::class));
111+
112+ $ this ->channel ->send ($ this ->notifiableUser , $ this ->notification );
55113 }
56114}
57115
58- class TestNotifiable
116+ class TestNotifiableInterest
59117{
60118 use Notifiable;
61119
@@ -65,6 +123,40 @@ public function routeNotificationForPusherPushNotifications()
65123 }
66124}
67125
126+ class TestNotifiableInterests
127+ {
128+ use Notifiable;
129+
130+ public function routeNotificationForPusherPushNotifications ()
131+ {
132+ return ['interest_one ' , 'interest_two ' , 'interest_three ' ];
133+ }
134+ }
135+
136+ class TestNotifiableUser
137+ {
138+ use Notifiable;
139+
140+ public $ pushNotificationType = 'users ' ;
141+
142+ public function routeNotificationForPusherPushNotifications ()
143+ {
144+ return 'user_1 ' ;
145+ }
146+ }
147+
148+ class TestNotifiableUsers
149+ {
150+ use Notifiable;
151+
152+ public $ pushNotificationType = 'users ' ;
153+
154+ public function routeNotificationForPusherPushNotifications ()
155+ {
156+ return ['user_1 ' , 'user_2 ' , 'user_3 ' ];
157+ }
158+ }
159+
68160class TestNotification extends Notification
69161{
70162 public function toPushNotification ($ notifiable )
0 commit comments