2020-04-08 15:31:22 +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
|
|
|
*
|
2022-06-08 06:25:44 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2020-04-08 15:31:22 +02:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Services\Invoice\HandleCancellation
|
|
|
|
*/
|
|
|
|
class CancelInvoiceTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MockAccountData;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCancelInvoice()
|
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
$this->assertTrue($this->invoice->invoiceCancellable($this->invoice));
|
2020-04-08 15:31:22 +02:00
|
|
|
|
|
|
|
$client_balance = $this->client->balance;
|
|
|
|
$invoice_balance = $this->invoice->balance;
|
|
|
|
|
|
|
|
$this->assertEquals(Invoice::STATUS_SENT, $this->invoice->status_id);
|
|
|
|
|
2021-08-31 02:16:26 +02:00
|
|
|
$this->invoice->fresh()->service()->handleCancellation()->save();
|
2020-04-08 15:31:22 +02:00
|
|
|
|
2021-07-03 05:47:15 +02:00
|
|
|
$this->assertEquals(0, $this->invoice->fresh()->balance);
|
|
|
|
$this->assertEquals($this->client->fresh()->balance, ($client_balance - $invoice_balance));
|
|
|
|
$this->assertNotEquals($client_balance, $this->client->fresh()->balance);
|
2021-08-31 02:16:26 +02:00
|
|
|
$this->assertEquals(Invoice::STATUS_CANCELLED, $this->invoice->fresh()->status_id);
|
2020-04-08 15:31:22 +02:00
|
|
|
}
|
|
|
|
}
|