|
4 | 4 |
|
5 | 5 | use App\Jobs\Cleanup; |
6 | 6 | use App\Models\Asset; |
| 7 | +use App\Models\Role; |
7 | 8 | use App\Models\Tenant; |
8 | 9 | use App\Models\Trial; |
9 | 10 | use App\Models\User; |
10 | 11 | use Carbon\Carbon; |
11 | 12 | use Illuminate\Support\Facades\DB; |
12 | 13 | use Tests\TestCaseWithDb; |
| 14 | +use Wave\Plan; |
13 | 15 | use Wave\Subscription; |
14 | 16 |
|
15 | 17 | class CleanupTrialAssetsTest extends TestCaseWithDb |
16 | 18 | { |
| 19 | + private function makeUserPaying(User $user) |
| 20 | + { |
| 21 | + $role = Role::firstOrCreate(['name' => Role::STANDARD_PLAN, 'guard_name' => 'web']); |
| 22 | + $plan = Plan::create([ |
| 23 | + 'name' => 'Basic Plan', |
| 24 | + 'description' => 'A basic plan', |
| 25 | + 'features' => 'Feature 1, Feature 2', |
| 26 | + 'active' => 1, |
| 27 | + 'role_id' => $role->id, |
| 28 | + 'monthly_price' => 9.99, |
| 29 | + 'yearly_price' => 99.99, |
| 30 | + 'onetime_price' => 0, |
| 31 | + 'default' => 0, |
| 32 | + 'currency' => 'EUR', |
| 33 | + ]); |
| 34 | + Subscription::create([ |
| 35 | + 'billable_id' => $user->id, |
| 36 | + 'billable_type' => 'user', |
| 37 | + 'plan_id' => $plan->id, |
| 38 | + 'status' => 'active', |
| 39 | + 'vendor_slug' => 'slug', |
| 40 | + 'vendor_product_id' => 'prod', |
| 41 | + 'vendor_transaction_id' => 'trans', |
| 42 | + 'vendor_customer_id' => 'cust', |
| 43 | + 'vendor_subscription_id' => 'sub', |
| 44 | + 'cycle' => 'month', |
| 45 | + ]); |
| 46 | + } |
| 47 | + |
17 | 48 | public function test_cleanup_deletes_old_trial_assets_without_subscription() |
18 | 49 | { |
19 | 50 | // Disable foreign key checks for this test or create necessary relations |
@@ -49,19 +80,7 @@ public function test_cleanup_sets_trial_id_to_null_if_subscription_exists() |
49 | 80 | $tenant = Tenant::create(['name' => 'Subscribed Tenant']); |
50 | 81 | $user = User::factory()->create(['tenant_id' => $tenant->id]); |
51 | 82 |
|
52 | | - // Create a subscription for the user |
53 | | - Subscription::create([ |
54 | | - 'billable_type' => get_class($user), |
55 | | - 'billable_id' => $user->id, |
56 | | - 'plan_id' => 1, // Assume plan 1 exists or use a real ID |
57 | | - 'status' => 'active', |
58 | | - 'vendor_slug' => 'paddle', |
59 | | - 'vendor_product_id' => 'prod_123', |
60 | | - 'vendor_transaction_id' => 'trans_123', |
61 | | - 'vendor_customer_id' => 'cust_123', |
62 | | - 'vendor_subscription_id' => 'sub_123', |
63 | | - 'cycle' => 'month', |
64 | | - ]); |
| 83 | + $this->makeUserPaying($user); |
65 | 84 |
|
66 | 85 | $oldTrial = Trial::create([ |
67 | 86 | 'hash' => 'subscribed_trial', |
|
0 commit comments