2020-04-06 22:32:27 +10:00
|
|
|
<?php
|
2020-09-14 21:11:46 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2021-01-04 08:54:54 +11:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 21:11:46 +10:00
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2020-04-06 22:32:27 +10: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 18:41:25 +10:00
|
|
|
* @covers App\Utils\Traits\Invoice\ActionsInvoice
|
2020-04-06 22:32:27 +10:00
|
|
|
*/
|
|
|
|
|
class InvoiceActionsTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use MockAccountData;
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
use ActionsInvoice;
|
|
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
2020-09-06 19:38:10 +10:00
|
|
|
|
2020-04-06 22:32:27 +10:00
|
|
|
$this->makeTestData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvoiceIsDeletable()
|
|
|
|
|
{
|
2020-05-19 23:11:24 +10:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
2020-04-08 20:55:28 +10:00
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
2020-04-08 23:31:22 +10:00
|
|
|
$this->assertTrue($this->invoiceCancellable($this->invoice));
|
2020-04-06 22:32:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvoiceIsReversable()
|
|
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
$this->withoutEvents();
|
2020-05-20 08:49:58 +10:00
|
|
|
|
2020-04-06 22:32:27 +10:00
|
|
|
$this->invoice->service()->markPaid()->save();
|
|
|
|
|
|
2020-04-08 20:48:31 +10:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
|
|
|
|
$this->assertFalse($this->invoiceCancellable($this->invoice));
|
2020-04-06 22:32:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvoiceIsCancellable()
|
|
|
|
|
{
|
2020-05-20 08:49:58 +10:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
|
2020-04-06 22:32:27 +10: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 20:48:31 +10:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
|
$this->assertTrue($this->invoiceReversable($this->invoice));
|
|
|
|
|
$this->assertTrue($this->invoiceCancellable($this->invoice));
|
2020-04-06 22:32:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testInvoiceUnactionable()
|
|
|
|
|
{
|
2020-05-20 08:49:58 +10:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
|
2020-04-06 22:32:27 +10:00
|
|
|
$this->invoice->delete();
|
|
|
|
|
|
2020-04-08 20:48:31 +10:00
|
|
|
$this->assertFalse($this->invoiceDeletable($this->invoice));
|
|
|
|
|
$this->assertFalse($this->invoiceReversable($this->invoice));
|
|
|
|
|
$this->assertFalse($this->invoiceCancellable($this->invoice));
|
2020-04-06 22:32:27 +10:00
|
|
|
}
|
|
|
|
|
}
|