Company Ledger Tests

This commit is contained in:
David Bomba 2019-05-16 15:36:53 +10:00
parent 8b3432f350
commit 543795bc74
4 changed files with 74 additions and 49 deletions

View File

@ -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*/

View File

@ -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);
}
}

View 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));
}
}

View File

@ -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);
}