@@ -21,15 +21,7 @@ class HandleCustomerSubscriptionCreatedJobTest extends TestCase
21
21
/** @test */
22
22
public function it_dispatches_the_create_anystack_license_job_with_correct_data ()
23
23
{
24
- $ mockCustomer = Customer::constructFrom ([
25
- 'id ' => 'cus_S9dhoV2rJK2Auy ' ,
26
-
27
- 'name ' => 'John Doe ' ,
28
- ]);
29
-
30
- $ this ->mockStripeClient ($ mockCustomer );
31
-
32
- dispatch_sync (new CreateUserFromStripeCustomer ($ mockCustomer ));
24
+ $ this ->createTestData ('John Doe ' );
33
25
34
26
Bus::fake ();
35
27
@@ -54,15 +46,7 @@ public function it_dispatches_the_create_anystack_license_job_with_correct_data(
54
46
*/
55
47
public function it_extracts_customer_name_parts_correctly ($ fullName , $ expectedFirstName , $ expectedLastName )
56
48
{
57
- $ mockCustomer = Customer::constructFrom ([
58
- 'id ' => 'cus_S9dhoV2rJK2Auy ' ,
59
-
60
- 'name ' => $ fullName ,
61
- ]);
62
-
63
- $ this ->mockStripeClient ($ mockCustomer );
64
-
65
- dispatch_sync (new CreateUserFromStripeCustomer ($ mockCustomer ));
49
+ $ this ->createTestData ($ fullName );
66
50
67
51
$ webhookCall = new WebhookHandled ($ this ->getTestWebhookPayload ());
68
52
@@ -117,6 +101,37 @@ public function it_fails_when_customer_has_no_email()
117
101
Bus::assertNotDispatched (CreateAnystackLicenseJob::class);
118
102
}
119
103
104
+ protected function createTestData (?string $ customerName )
105
+ {
106
+ $ mockCustomer = Customer::constructFrom ([
107
+ 'id ' => $ this ->getTestWebhookPayload ()['data ' ]['object ' ]['customer ' ],
108
+ 'email ' =>
$ email =
'[email protected] ' ,
109
+ 'name ' => $ customerName ,
110
+ ]);
111
+
112
+ $ this ->mockStripeClient ($ mockCustomer );
113
+
114
+ dispatch_sync (new CreateUserFromStripeCustomer ($ mockCustomer ));
115
+
116
+ $ user = User::query ()->where ('email ' , $ email )->firstOrFail ();
117
+
118
+ $ subscription = \Laravel \Cashier \Subscription::factory ()
119
+ ->for ($ user , 'user ' )
120
+ ->create ([
121
+ 'stripe_id ' => $ this ->getTestWebhookPayload ()['data ' ]['object ' ]['id ' ],
122
+ 'stripe_status ' => 'active ' ,
123
+ 'stripe_price ' => $ this ->getTestWebhookPayload ()['data ' ]['object ' ]['items ' ]['data ' ][0 ]['price ' ]['id ' ],
124
+ 'quantity ' => 1 ,
125
+ ]);
126
+ $ subscriptionItem = \Laravel \Cashier \SubscriptionItem::factory ()
127
+ ->for ($ subscription , 'subscription ' )
128
+ ->create ([
129
+ 'stripe_id ' => $ this ->getTestWebhookPayload ()['data ' ]['object ' ]['items ' ]['data ' ][0 ]['id ' ],
130
+ 'stripe_price ' => $ this ->getTestWebhookPayload ()['data ' ]['object ' ]['items ' ]['data ' ][0 ]['price ' ]['id ' ],
131
+ 'quantity ' => 1 ,
132
+ ]);
133
+ }
134
+
120
135
protected function getTestWebhookPayload (): array
121
136
{
122
137
return [
0 commit comments