@@ -347,7 +347,12 @@ public function testModelReturnsOnlyNotCanceledSubscriptionsWithTheScope()
347
347
public function testModelUpdatesGraceDaysEndedAtWhenRenewing ()
348
348
{
349
349
$ subscriber = User::factory ()->create ();
350
+ $ plan = Plan::factory ()->create ([
351
+ 'grace_days ' => $ graceDays = $ this ->faker ()->randomDigitNotNull (),
352
+ ]);
353
+
350
354
$ subscription = Subscription::factory ()
355
+ ->for ($ plan )
351
356
->for ($ subscriber , 'subscriber ' )
352
357
->create ([
353
358
'grace_days_ended_at ' => now ()->subDay (),
@@ -357,21 +362,24 @@ public function testModelUpdatesGraceDaysEndedAtWhenRenewing()
357
362
358
363
$ this ->assertDatabaseHas ('subscriptions ' , [
359
364
'id ' => $ subscription ->id ,
360
- 'grace_days_ended_at ' => $ subscription ->expired_at ->addDays ($ subscription -> plan -> grace_days ),
365
+ 'grace_days_ended_at ' => $ subscription ->expired_at ->addDays ($ graceDays ),
361
366
]);
362
367
}
363
368
364
369
public function testModelLeavesGraceDaysEmptyWhenRenewingIfPlanDoesNotHaveIt ()
365
370
{
366
371
$ subscriber = User::factory ()->create ();
372
+ $ plan = Plan::factory ()->create ([
373
+ 'grace_days ' => 0 ,
374
+ ]);
375
+
367
376
$ subscription = Subscription::factory ()
377
+ ->for ($ plan )
368
378
->for ($ subscriber , 'subscriber ' )
369
379
->create ([
370
380
'grace_days_ended_at ' => null ,
371
381
]);
372
382
373
- $ subscription ->plan ->update (['grace_days ' => 0 ]);
374
-
375
383
$ subscription ->renew ();
376
384
377
385
$ this ->assertDatabaseHas ('subscriptions ' , [
0 commit comments