1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/tests/Feature/CancelInvoiceTest.php

65 lines
1.7 KiB
PHP
Raw Normal View History

<?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
*
2022-06-08 06:25:44 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-09-14 13:11:46 +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()
{
$this->assertTrue($this->invoice->invoiceCancellable($this->invoice));
$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();
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);
}
}