Tests for invoice deletion

This commit is contained in:
David Bomba 2020-12-05 08:10:31 +11:00
parent de5a5300a2
commit 91fcba628f

View File

@ -11,6 +11,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Factory\InvoiceItemFactory; use App\Factory\InvoiceItemFactory;
use App\Models\Client;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
@ -57,7 +58,10 @@ class DeleteInvoiceTest extends TestCase
$arr = $response->json(); $arr = $response->json();
$client_hash_id = $arr['data']['id']; $client_hash_id = $arr['data']['id'];
$client = Client::find($this->decodePrimaryKey($client_hash_id));
$this->assertEquals($client->balance, 0);
$this->assertEquals($client->paid_to_date, 0);
//create new invoice. //create new invoice.
$line_items = []; $line_items = [];
@ -154,13 +158,31 @@ class DeleteInvoiceTest extends TestCase
$this->assertEquals($invoice_two->amount, 20); $this->assertEquals($invoice_two->amount, 20);
$this->assertEquals($invoice_two->balance, 0); $this->assertEquals($invoice_two->balance, 0);
$this->assertEquals($client->fresh()->paid_to_date, 40);
$this->assertEquals($client->balance, 0);
//hydrate associated payment //hydrate associated payment
$this->assertEquals($payment->amount, 40); $this->assertEquals($payment->amount, 40);
$this->assertEquals($payment->applied, 40); $this->assertEquals($payment->applied, 40);
//delete invoice //delete invoice
$data = [
'ids' => [$invoice_one_hashed_id],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=delete', $data);
$arr = $response->json();
$this->assertTrue($arr['data'][0]['is_deleted']);
$this->assertEquals($client->fresh()->paid_to_date, 20);
$this->assertEquals($payment->fresh()->applied, 20);
$this->assertEquals($payment->fresh()->amount, 20);
//test ledger balance //test ledger balance
//test client balance //test client balance