mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Test for recurring updates
This commit is contained in:
parent
c2b4210241
commit
3857b1dc3e
@ -54,6 +54,7 @@ class Account extends BaseModel
|
||||
'promo_expires',
|
||||
'discount_expires',
|
||||
'trial_started',
|
||||
'plan_expires'
|
||||
];
|
||||
|
||||
const PLAN_FREE = 'free';
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Services\Subscription\SubscriptionService;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -77,4 +78,39 @@ class Subscription extends BaseModel
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function nextDateByInterval($date, $frequency_id)
|
||||
{
|
||||
|
||||
switch ($frequency_id) {
|
||||
|
||||
case RecurringInvoice::FREQUENCY_DAILY:
|
||||
return $date->addDay();
|
||||
case RecurringInvoice::FREQUENCY_WEEKLY:
|
||||
return $date->addWeek();
|
||||
case RecurringInvoice::FREQUENCY_TWO_WEEKS:
|
||||
return $date->addWeeks(2);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_WEEKS:
|
||||
return $date->addWeeks(4);
|
||||
case RecurringInvoice::FREQUENCY_MONTHLY:
|
||||
return $date->addMonthNoOverflow();
|
||||
case RecurringInvoice::FREQUENCY_TWO_MONTHS:
|
||||
return $date->addMonthsNoOverflow(2);
|
||||
case RecurringInvoice::FREQUENCY_THREE_MONTHS:
|
||||
return $date->addMonthsNoOverflow(3);
|
||||
case RecurringInvoice::FREQUENCY_FOUR_MONTHS:
|
||||
return $date->addMonthsNoOverflow(4);
|
||||
case RecurringInvoice::FREQUENCY_SIX_MONTHS:
|
||||
return $date->addMonthsNoOverflow(6);
|
||||
case RecurringInvoice::FREQUENCY_ANNUALLY:
|
||||
return $date->addYear();
|
||||
case RecurringInvoice::FREQUENCY_TWO_YEARS:
|
||||
return $date->addYears(2);
|
||||
case RecurringInvoice::FREQUENCY_THREE_YEARS:
|
||||
return $date->addYears(3);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,13 +10,16 @@
|
||||
*/
|
||||
namespace Tests\Feature\Ninja;
|
||||
|
||||
use App\Factory\SubscriptionFactory;
|
||||
use App\Models\Account;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -72,4 +75,17 @@ class PlanTest extends TestCase
|
||||
$this->assertEquals($filtered_plans->count(), 2);
|
||||
}
|
||||
|
||||
public function testSubscriptionDateIncrement()
|
||||
{
|
||||
$subscription = SubscriptionFactory::create($this->company->id, $this->user->id);
|
||||
$subscription->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
|
||||
$subscription->save();
|
||||
|
||||
$date = Carbon::parse('2020-01-01')->startOfDay();
|
||||
|
||||
$next_date = $subscription->nextDateByInterval($date, RecurringInvoice::FREQUENCY_MONTHLY);
|
||||
|
||||
$this->assertEquals($date->addMonthNoOverflow()->startOfDay(), $next_date->startOfDay());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user