@@ -25,37 +25,95 @@ public function setUp(): void
25
25
26
26
$ this ->notification = new TestNotification ;
27
27
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 ;
29
33
}
30
34
31
35
/** @test */
32
- public function it_can_send_a_notification ()
36
+ public function it_can_send_a_notification_to_interest ()
33
37
{
34
- $ message = $ this ->notification ->toPushNotification ($ this ->notifiable );
38
+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableInterest );
35
39
36
40
$ data = $ message ->toArray ();
37
41
38
42
$ this ->pusher ->shouldReceive ('publishToInterests ' )->once ()->with (['interest_name ' ], $ data );
39
43
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 );
41
59
}
42
60
43
61
/** @test */
44
- public function it_fires_failure_event_on_failure ()
62
+ public function it_fires_failure_event_on_interest_failure ()
45
63
{
46
- $ message = $ this ->notification ->toPushNotification ($ this ->notifiable );
64
+ $ message = $ this ->notification ->toPushNotification ($ this ->notifiableInterest );
47
65
48
66
$ data = $ message ->toArray ();
49
67
50
68
$ this ->pusher ->shouldReceive ('publishToInterests ' )->once ()->with (['interest_name ' ], $ data )->andThrow (new Exception ('Something happened ' ));
51
69
52
70
$ this ->events ->shouldReceive ('dispatch ' )->once ()->with (Mockery::type (NotificationFailed::class));
53
71
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 );
55
113
}
56
114
}
57
115
58
- class TestNotifiable
116
+ class TestNotifiableInterest
59
117
{
60
118
use Notifiable;
61
119
@@ -65,6 +123,40 @@ public function routeNotificationForPusherPushNotifications()
65
123
}
66
124
}
67
125
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
+
68
160
class TestNotification extends Notification
69
161
{
70
162
public function toPushNotification ($ notifiable )
0 commit comments