44
55use App \Enums \Subscription ;
66use App \Jobs \CreateAnystackLicenseJob ;
7+ use App \Models \User ;
78use App \Notifications \LicenseKeyGenerated ;
89use Illuminate \Foundation \Testing \RefreshDatabase ;
910use Illuminate \Support \Facades \Cache ;
@@ -45,8 +46,13 @@ protected function setUp(): void
4546 /** @test */
4647 public function it_creates_contact_and_license_on_anystack ()
4748 {
49+ $ user = User::factory ()->create ([
50+ 51+ 'name ' => 'John Doe ' ,
52+ ]);
53+
4854 $ job = new CreateAnystackLicenseJob (
49- 55+ $ user ,
5056 Subscription::Max,
5157 'John ' ,
5258 'Doe '
@@ -79,8 +85,13 @@ public function it_creates_contact_and_license_on_anystack()
7985 /** @test */
8086 public function it_stores_license_key_in_cache ()
8187 {
88+ $ user = User::factory ()->create ([
89+ 90+ 'name ' => 'John Doe ' ,
91+ ]);
92+
8293 $ job = new CreateAnystackLicenseJob (
83- 94+ $ user ,
8495 Subscription::Max,
8596 'John ' ,
8697 'Doe '
@@ -94,20 +105,24 @@ public function it_stores_license_key_in_cache()
94105 /** @test */
95106 public function it_sends_license_key_notification ()
96107 {
108+ $ user = User::factory ()->create ([
109+ 110+ 'name ' => 'John Doe ' ,
111+ ]);
112+
97113 $ job = new CreateAnystackLicenseJob (
98- 114+ $ user ,
99115 Subscription::Max,
100116 'John ' ,
101117 'Doe '
102118 );
103119
104120 $ job ->handle ();
105121
106- Notification::assertSentOnDemand (
107- LicenseKeyGenerated::class ,
122+ Notification::assertSentTo (
123+ $ user ,
108124 function (LicenseKeyGenerated $ notification , array $ channels , object $ notifiable ) {
109- return $ notifiable->
routes [
'mail ' ] ===
'[email protected] ' &&
110- $ notification ->licenseKey === 'test-license-key-12345 ' &&
125+ return $ notification ->licenseKey === 'test-license-key-12345 ' &&
111126 $ notification ->subscription === Subscription::Max &&
112127 $ notification ->firstName === 'John ' ;
113128 }
@@ -117,9 +132,14 @@ function (LicenseKeyGenerated $notification, array $channels, object $notifiable
117132 /** @test */
118133 public function it_handles_missing_name_components ()
119134 {
135+ $ user = User::factory ()->create ([
136+ 137+ 'name ' => null ,
138+ ]);
139+
120140 // Create and run the job with missing name components
121141 $ job = new CreateAnystackLicenseJob (
122- 142+ $ user ,
123143 Subscription::Max,
124144 );
125145
@@ -135,11 +155,10 @@ public function it_handles_missing_name_components()
135155 });
136156
137157 // Assert notification was sent with null firstName
138- Notification::assertSentOnDemand (
139- LicenseKeyGenerated::class ,
158+ Notification::assertSentTo (
159+ $ user ,
140160 function (LicenseKeyGenerated $ notification , array $ channels , object $ notifiable ) {
141- return $ notifiable->
routes [
'mail ' ] ===
'[email protected] ' &&
142- $ notification ->licenseKey === 'test-license-key-12345 ' &&
161+ return $ notification ->licenseKey === 'test-license-key-12345 ' &&
143162 $ notification ->subscription === Subscription::Max &&
144163 $ notification ->firstName === null ;
145164 }
0 commit comments