From 543795bc7481757ed09efd0372295fb84ffc7646 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 May 2019 15:36:53 +1000 Subject: [PATCH] Company Ledger Tests --- .../UpdateCompanyLedgerWithPayment.php | 1 + .../UpdateCompanyLedgerInvoiceTest.php | 49 ------------- tests/Integration/UpdateCompanyLedgerTest.php | 70 +++++++++++++++++++ tests/MockAccountData.php | 3 + 4 files changed, 74 insertions(+), 49 deletions(-) delete mode 100644 tests/Integration/UpdateCompanyLedgerInvoiceTest.php create mode 100644 tests/Integration/UpdateCompanyLedgerTest.php diff --git a/app/Jobs/Company/UpdateCompanyLedgerWithPayment.php b/app/Jobs/Company/UpdateCompanyLedgerWithPayment.php index d95c80b9a1b6..02cb93cbd124 100644 --- a/app/Jobs/Company/UpdateCompanyLedgerWithPayment.php +++ b/app/Jobs/Company/UpdateCompanyLedgerWithPayment.php @@ -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*/ diff --git a/tests/Integration/UpdateCompanyLedgerInvoiceTest.php b/tests/Integration/UpdateCompanyLedgerInvoiceTest.php deleted file mode 100644 index 2b0e95f9c3bf..000000000000 --- a/tests/Integration/UpdateCompanyLedgerInvoiceTest.php +++ /dev/null @@ -1,49 +0,0 @@ -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); - - } - - -} \ No newline at end of file diff --git a/tests/Integration/UpdateCompanyLedgerTest.php b/tests/Integration/UpdateCompanyLedgerTest.php new file mode 100644 index 000000000000..9fd00ad2469a --- /dev/null +++ b/tests/Integration/UpdateCompanyLedgerTest.php @@ -0,0 +1,70 @@ +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)); + } + + +} \ No newline at end of file diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 558542f510e1..c533ace569e4 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -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); + }