From 579dc1dc01606f50166696c3f92841ff5894f482 Mon Sep 17 00:00:00 2001 From: Peter Baettig Date: Fri, 13 Mar 2020 12:41:37 +0100 Subject: [PATCH] fix some more definitions --- database/factories/SubscriptionFactory.php | 7 +++++-- database/migrations/2019_10_01_123211_plan.php | 7 +++---- .../AbstractPlanTypeDateProcessor.php | 2 +- tests/feature/SubscribeTest.php | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/database/factories/SubscriptionFactory.php b/database/factories/SubscriptionFactory.php index f7649ef..b3ab113 100644 --- a/database/factories/SubscriptionFactory.php +++ b/database/factories/SubscriptionFactory.php @@ -13,8 +13,11 @@ 'price' => $faker->randomElement([9900,29900,59900]), 'currency' => 'CHF', 'is_recurring' => $faker->randomElement([true,false]), - 'payment_tolerance_ends_at' => Carbon::now()->addDay()->endOfDay() - ]; + 'payment_tolerance_ends_at' => Carbon::now(), + 'starts_at' => Carbon::now(), + 'expires_at' => Carbon::parse('+10 days'), + 'test_ends_at' => Carbon::now() + ]; }); $factory->state(Subscription::class, 'paid', static function() { diff --git a/database/migrations/2019_10_01_123211_plan.php b/database/migrations/2019_10_01_123211_plan.php index e03241c..8569c41 100644 --- a/database/migrations/2019_10_01_123211_plan.php +++ b/database/migrations/2019_10_01_123211_plan.php @@ -1,6 +1,5 @@ boolean('is_recurring')->default(true); - $table->timestamp('test_ends_at')->nullable()->default(Carbon::now()); + $table->timestamp('test_ends_at'); $table->timestamp('payment_tolerance_ends_at'); $table->timestamp('paid_at')->nullable(); - $table->timestamp('starts_at')->nullable(); + $table->timestamp('starts_at'); $table->timestamp('renewed_at')->nullable(); - $table->timestamp('expires_at')->nullable(); + $table->timestamp('expires_at'); $table->timestamp('cancelled_at')->nullable(); $table->timestamp('refunded_at')->nullable(); diff --git a/src/Models/PlanTypeDateProcessors/AbstractPlanTypeDateProcessor.php b/src/Models/PlanTypeDateProcessors/AbstractPlanTypeDateProcessor.php index ff9da4a..7c2a968 100644 --- a/src/Models/PlanTypeDateProcessors/AbstractPlanTypeDateProcessor.php +++ b/src/Models/PlanTypeDateProcessors/AbstractPlanTypeDateProcessor.php @@ -59,7 +59,7 @@ protected function applyGeneralStartDateCorrections(): void private function applyGeneralTestEndDateCorrections(): void { if (!$this->testingDays || $this->testingDays === 0) { - $this->testEndsDate = null; + $this->testEndsDate = Carbon::now(); } if ($this->testingDays && $this->testingDays > 0) { $this->testEndsDate = $this->testEndsDate->addDays($this->testingDays); diff --git a/tests/feature/SubscribeTest.php b/tests/feature/SubscribeTest.php index 4b0b94a..6fa63ae 100644 --- a/tests/feature/SubscribeTest.php +++ b/tests/feature/SubscribeTest.php @@ -41,6 +41,7 @@ public function can_subscribe_to_a_recurring_yearly_plan(): void /** @var Subscription $subscription */ $subscription = $this->user->active_or_last_subscription; $this->assertEqualsWithDelta(Carbon::now(), $subscription->starts_at, 1); + $this->assertEqualsWithDelta(Carbon::now(), $subscription->test_ends_at, 1); $this->assertEqualsWithDelta(Carbon::now()->addYear()->endOfDay(), $subscription->expires_at, 1); $this->assertTrue($plan->is($subscription->plan)); $this->assertEquals($plan->price, $subscription->price);