1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/tests/Unit/RecurringDatesTest.php

94 lines
2.9 KiB
PHP
Raw Normal View History

2020-09-13 12:20:11 +02:00
<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
2020-09-14 13:11:46 +02:00
*/
2020-09-13 12:20:11 +02:00
namespace Tests\Unit;
use App\Factory\RecurringInvoiceFactory;
use App\Models\RecurringInvoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2020-11-25 15:19:52 +01:00
use Illuminate\Support\Carbon;
2020-09-13 12:20:11 +02:00
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
2020-09-24 02:57:44 +02:00
* @covers \App\Models\RecurringInvoice
2020-09-13 12:20:11 +02:00
*/
class RecurringDatesTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
protected function setUp() :void
2020-09-13 12:20:11 +02:00
{
parent::setUp();
$this->makeTestData();
}
public function testRecurringDatesDraftInvoice()
{
$recurring_invoice = RecurringInvoiceFactory::create($this->company->id, $this->user->id);
$recurring_invoice->line_items = $this->buildLineItems();
$recurring_invoice->client_id = $this->client->id;
$recurring_invoice->save();
$recurring_invoice->calc()->getInvoice();
$this->assertEquals(0, count($recurring_invoice->recurringDates()));
}
public function testRecurringDatesPendingInvoice()
{
$recurring_invoice = RecurringInvoiceFactory::create($this->company->id, $this->user->id);
$recurring_invoice->line_items = $this->buildLineItems();
$recurring_invoice->client_id = $this->client->id;
$recurring_invoice->status_id = RecurringInvoice::STATUS_PENDING;
$recurring_invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$recurring_invoice->remaining_cycles = 5;
2020-09-14 13:11:46 +02:00
$recurring_invoice->due_date_days = '5';
2020-09-13 12:20:11 +02:00
$recurring_invoice->next_send_date = now();
$recurring_invoice->save();
$recurring_invoice->calc()->getInvoice();
$this->assertEquals(5, count($recurring_invoice->recurringDates()));
}
public function testRecurringDatesPendingInvoiceWithNoDueDate()
{
$recurring_invoice = RecurringInvoiceFactory::create($this->company->id, $this->user->id);
$recurring_invoice->line_items = $this->buildLineItems();
$recurring_invoice->client_id = $this->client->id;
$recurring_invoice->status_id = RecurringInvoice::STATUS_PENDING;
$recurring_invoice->frequency_id = RecurringInvoice::FREQUENCY_MONTHLY;
$recurring_invoice->remaining_cycles = 5;
$recurring_invoice->due_date_days = null;
$recurring_invoice->next_send_date = now();
2020-09-13 12:20:11 +02:00
$recurring_invoice->save();
$recurring_invoice->calc()->getInvoice();
$this->assertEquals(5, count($recurring_invoice->recurringDates()));
}
2020-09-24 02:57:44 +02:00
public function testCompareDatesLogic()
{
$date = now()->startOfDay()->format('Y-m-d');
$this->assertTrue(Carbon::parse($date)->lte(now()->startOfDay()));
}
2020-09-13 12:20:11 +02:00
}