2020-04-06 14:32:27 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-04-06 14:32:27 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\Factory\PaymentFactory;
|
|
|
|
use App\Utils\Traits\Invoice\ActionsInvoice;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2020-04-16 10:41:25 +02:00
|
|
|
* @covers App\Utils\Traits\Invoice\ActionsInvoice
|
2020-04-06 14:32:27 +02:00
|
|
|
*/
|
|
|
|
class InvoiceActionsTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use ActionsInvoice;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-04-06 14:32:27 +02:00
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceIsDeletable()
|
|
|
|
{
|
2020-05-19 15:11:24 +02:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
2020-04-08 12:55:28 +02:00
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
2020-04-08 15:31:22 +02:00
|
|
|
$this->assertTrue($this->invoiceCancellable($this->invoice));
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceIsReversable()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->withoutEvents();
|
2020-05-20 00:49:58 +02:00
|
|
|
|
2020-04-06 14:32:27 +02:00
|
|
|
$this->invoice->service()->markPaid()->save();
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
|
|
|
$this->assertFalse($this->invoiceCancellable($this->invoice));
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceIsCancellable()
|
|
|
|
{
|
2020-05-20 00:49:58 +02:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
2020-04-06 14:32:27 +02:00
|
|
|
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
|
|
|
$payment->amount = 40;
|
|
|
|
$payment->client_id = $this->invoice->client_id;
|
|
|
|
$payment->applied = 0;
|
|
|
|
$payment->refunded = 0;
|
|
|
|
$payment->date = now();
|
|
|
|
$payment->save();
|
|
|
|
|
|
|
|
$this->invoice->service()->applyPayment($payment, 5)->save();
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
|
|
|
$this->assertTrue($this->invoiceCancellable($this->invoice));
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceUnactionable()
|
|
|
|
{
|
2020-05-20 00:49:58 +02:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
2020-04-06 14:32:27 +02:00
|
|
|
$this->invoice->delete();
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
$this->assertFalse($this->invoiceReversable($this->invoice));
|
|
|
|
$this->assertFalse($this->invoiceCancellable($this->invoice));
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
}
|