mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Company Ledger Tests
This commit is contained in:
parent
8b3432f350
commit
543795bc74
@ -51,6 +51,7 @@ class UpdateCompanyLedgerWithPayment
|
||||
public function handle()
|
||||
{
|
||||
$balance = 0;
|
||||
|
||||
$this->adjustment = $this->adjustment * -1;
|
||||
|
||||
/* Get the last record for the client and set the current balance*/
|
||||
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Integration;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Jobs\Invoice\MarkPaid;
|
||||
use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Jobs\Company\UpdateCompanyLedgerWithInvoice
|
||||
*/
|
||||
class UpdateCompanyLedgerInvoiceTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testUpdatedInvoiceEventFires()
|
||||
{
|
||||
|
||||
$this->invoice->status_id = Invoice::STATUS_PAID;
|
||||
$this->invoice->save();
|
||||
|
||||
// $this->expectsEvents(InvoiceWasUpdated::class);
|
||||
$activities = Activity::whereInvoiceId($this->invoice->id)->get();
|
||||
|
||||
$this->assertEquals(count($activities), 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
70
tests/Integration/UpdateCompanyLedgerTest.php
Normal file
70
tests/Integration/UpdateCompanyLedgerTest.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Integration;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Jobs\Invoice\MarkPaid;
|
||||
use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateCompanyLedgerTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Jobs\Company\UpdateCompanyLedgerWithPayment
|
||||
*/
|
||||
public function testPaymentIsPresentInLedger()
|
||||
{
|
||||
|
||||
$invoice = MarkPaid::dispatchNow($this->invoice);
|
||||
|
||||
|
||||
$ledger = CompanyLedger::whereClientId($invoice->client_id)
|
||||
->whereCompanyId($invoice->company_id)
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
|
||||
$payment = $ledger->adjustment * -1;
|
||||
|
||||
$this->assertEquals($invoice->amount, $payment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Jobs\Company\UpdateCompanyLedgerWithInvoice
|
||||
*/
|
||||
public function testInvoiceIsPresentInLedger()
|
||||
{
|
||||
$this->invoice->save();
|
||||
|
||||
$ledger = CompanyLedger::whereCompanyLedgerableId($this->invoice->id)
|
||||
->whereCompanyLedgerableType(Invoice::class)
|
||||
->get();
|
||||
|
||||
$this->assertEquals(1, count($ledger));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -15,6 +15,7 @@ use App\Factory\ClientFactory;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Helpers\Invoice\InvoiceCalc;
|
||||
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
@ -82,6 +83,8 @@ trait MockAccountData
|
||||
|
||||
$this->invoice->save();
|
||||
|
||||
UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->invoice->amount);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user