Skip to content

Commit

Permalink
Merge pull request laravel#33 from core45/main
Browse files Browse the repository at this point in the history
  • Loading branch information
sandervanhooft committed Dec 18, 2021
2 parents da6b6a9 + 04138cb commit 42b6de1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Subscription.php
Expand Up @@ -37,6 +37,7 @@
* @property string owner_type
* @property string next_plan
* @property string plan
* @property string name
* @property int quantity
* @property mixed scheduled_order_item_id
* @property OrderItem scheduledOrderItem
Expand Down Expand Up @@ -211,6 +212,7 @@ public function swap(string $plan, $invoiceNow = true)

$applyNewSettings = function () use ($newPlan) {
$this->plan = $newPlan->name();
$this->name = $newPlan->name();
};

$this->restartCycleWithModifications($applyNewSettings, now(), $invoiceNow);
Expand Down
7 changes: 6 additions & 1 deletion tests/SwapSubscriptionPlanTest.php
Expand Up @@ -47,6 +47,7 @@ public function canSwapToAnotherPlan()
$subscription = $subscription->swap('weekly-20-1')->fresh();

$this->assertEquals('weekly-20-1', $subscription->plan);
$this->assertEquals('weekly-20-1', $subscription->name);

$this->assertCarbon($now->copy(), $subscription->cycle_started_at);
$this->assertCarbon($now->copy()->addWeek(), $subscription->cycle_ends_at);
Expand Down Expand Up @@ -110,6 +111,7 @@ public function swappingACancelledSubscriptionResumesIt()
factory(Subscription::class)->make([
'ends_at' => now()->addWeek(),
'plan' => 'monthly-20-1',
'name' => 'monthly-20-1',
])
);
$subscription->cancel();
Expand All @@ -134,6 +136,7 @@ public function canSwapNextCycle()
$subscription = $subscription->swapNextCycle('weekly-20-1')->fresh();

$this->assertEquals('monthly-10-1', $subscription->plan);
$this->assertEquals('monthly-10-1', $subscription->name);
$this->assertEquals('weekly-20-1', $subscription->next_plan);

// Check that the billing cycle remains intact
Expand All @@ -157,6 +160,7 @@ public function canSwapNextCycle()
Event::assertNotDispatched(SubscriptionPlanSwapped::class);

$this->assertEquals('monthly-10-1', $subscription->plan);
$this->assertEquals('monthly-10-1', $subscription->name);
$this->assertEquals('weekly-20-1', $subscription->next_plan);

Subscription::processOrderItem($new_order_item);
Expand All @@ -165,6 +169,7 @@ public function canSwapNextCycle()

$this->assertNull($subscription->next_plan);
$this->assertEquals('weekly-20-1', $subscription->plan);
$this->assertEquals('weekly-20-1', $subscription->name);

// Assert that the subscription cycle reflects the new plan
$cycle_should_have_started_at = $cycle_should_end_at->copy();
Expand Down Expand Up @@ -196,7 +201,7 @@ protected function getUserWithZeroBalance()
protected function getSubscriptionForUser($user)
{
return $user->subscriptions()->save(factory(Subscription::class)->make([
"name" => "dummy name",
"name" => "monthly-10-1",
"plan" => "monthly-10-1",
"cycle_started_at" => now()->subWeeks(2),
"cycle_ends_at" => now()->subWeeks(2)->addMonth(),
Expand Down

0 comments on commit 42b6de1

Please sign in to comment.