From 579bb07af38c3b5bffa5a93243448cb40d114cf5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 15 Aug 2025 10:02:15 +1000 Subject: [PATCH] Updates for tests --- app/Providers/StaticServiceProvider.php | 1 - tests/MockAccountData.php | 84 +++++++++++++------------ tests/Unit/AutoBillInvoiceTest.php | 4 +- tests/Unit/Chart/ChartCurrencyTest.php | 12 ++-- tests/Unit/CompanyDocumentsTest.php | 2 +- tests/Unit/EntityTest.php | 13 +--- tests/Unit/GeneratesCounterTest.php | 13 ++-- 7 files changed, 62 insertions(+), 67 deletions(-) diff --git a/app/Providers/StaticServiceProvider.php b/app/Providers/StaticServiceProvider.php index d82675fcaa..07677af7d4 100644 --- a/app/Providers/StaticServiceProvider.php +++ b/app/Providers/StaticServiceProvider.php @@ -263,7 +263,6 @@ class StaticServiceProvider extends ServiceProvider }); - nlog("static service provider registered"); } public function boot() diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index b2cf963e09..6613650998 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -67,6 +67,7 @@ use App\DataMapper\ClientRegistrationFields; use App\Jobs\Company\CreateCompanyTaskStatuses; use App\Repositories\RecurringInvoiceRepository; use App\Factory\InvoiceToRecurringInvoiceFactory; +use App\Repositories\CreditRepository; /** * Class MockAccountData. @@ -211,18 +212,14 @@ trait MockAccountData Artisan::call('db:seed', ['--force' => true]); } - app()->singleton('currencies', function ($app) { $resource = Currency::query()->orderBy('name')->get(); - Cache::forever('currencies', $resource); - return $resource; }); - $this->faker = \Faker\Factory::create(); $fake_email = $this->faker->email(); @@ -566,27 +563,30 @@ trait MockAccountData $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); - CreditInvitation::factory()->create([ - 'user_id' => $user_id, - 'company_id' => $this->company->id, - 'client_contact_id' => $contact->id, - 'credit_id' => $this->credit->id, - ]); + // CreditInvitation::factory()->create([ + // 'user_id' => $user_id, + // 'company_id' => $this->company->id, + // 'client_contact_id' => $contact->id, + // 'credit_id' => $this->credit->id, + // ]); - CreditInvitation::factory()->create([ - 'user_id' => $user_id, - 'company_id' => $this->company->id, - 'client_contact_id' => $contact2->id, - 'credit_id' => $this->credit->id, - ]); + // CreditInvitation::factory()->create([ + // 'user_id' => $user_id, + // 'company_id' => $this->company->id, + // 'client_contact_id' => $contact2->id, + // 'credit_id' => $this->credit->id, + // ]); - $this->credit->setRelation('client', $this->client); - $this->credit->setRelation('company', $this->company); + // $this->credit->setRelation('client', $this->client); + // $this->credit->setRelation('company', $this->company); - $this->credit->save(); + // $this->credit->save(); - $this->credit->service()->createInvitations()->markSent(); + $repo = new CreditRepository(); + $repo->save([], $this->credit); + // $this->credit->service()->createInvitations()->markSent(); + // $this->credit->save(); $this->purchase_order = PurchaseOrderFactory::create($this->company->id, $user_id); $this->purchase_order->vendor_id = $this->vendor->id; @@ -650,19 +650,25 @@ trait MockAccountData $this->credit->ledger()->updateCreditBalance($this->credit->balance)->save(); $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); - CreditInvitation::factory()->create([ - 'user_id' => $user_id, - 'company_id' => $this->company->id, - 'client_contact_id' => $contact->id, - 'credit_id' => $this->credit->id, - ]); + $this->credit->save(); - CreditInvitation::factory()->create([ - 'user_id' => $user_id, - 'company_id' => $this->company->id, - 'client_contact_id' => $contact2->id, - 'credit_id' => $this->credit->id, - ]); + + $repo = new CreditRepository(); + $repo->save([], $this->credit); + + // CreditInvitation::factory()->create([ + // 'user_id' => $user_id, + // 'company_id' => $this->company->id, + // 'client_contact_id' => $contact->id, + // 'credit_id' => $this->credit->id, + // ]); + + // CreditInvitation::factory()->create([ + // 'user_id' => $user_id, + // 'company_id' => $this->company->id, + // 'client_contact_id' => $contact2->id, + // 'credit_id' => $this->credit->id, + // ]); $this->bank_integration = BankIntegration::factory()->create([ 'user_id' => $user_id, @@ -705,17 +711,17 @@ trait MockAccountData 'company_id' => $this->company->id, ]); - $invitations = CreditInvitation::whereCompanyId($this->credit->company_id) - ->whereCreditId($this->credit->id); + // $invitations = CreditInvitation::whereCompanyId($this->credit->company_id) + // ->whereCreditId($this->credit->id); - $this->credit->setRelation('invitations', $invitations); + // $this->credit->setRelation('invitations', $invitations); - $this->credit->service()->markSent(); + // $this->credit->service()->markSent(); - $this->credit->setRelation('client', $this->client); - $this->credit->setRelation('company', $this->company); + // $this->credit->setRelation('client', $this->client); + // $this->credit->setRelation('company', $this->company); - $this->credit->save(); + // $this->credit->save(); $contacts = $this->invoice->client->contacts; diff --git a/tests/Unit/AutoBillInvoiceTest.php b/tests/Unit/AutoBillInvoiceTest.php index 96c27c88ce..d45554e8ef 100644 --- a/tests/Unit/AutoBillInvoiceTest.php +++ b/tests/Unit/AutoBillInvoiceTest.php @@ -22,7 +22,7 @@ use Illuminate\Support\Facades\Artisan; */ class AutoBillInvoiceTest extends TestCase { - // use DatabaseTransactions; + use DatabaseTransactions; use MockAccountData; protected function setUp(): void @@ -30,12 +30,10 @@ class AutoBillInvoiceTest extends TestCase parent::setUp(); $this->makeTestData(); - } public function testAutoBillFunctionality() { - $this->assertEquals('1', $this->client->settings->currency_id); $this->assertEquals($this->client->balance, 10); $this->assertEquals($this->client->paid_to_date, 0); $this->assertEquals($this->client->credit_balance, 10); diff --git a/tests/Unit/Chart/ChartCurrencyTest.php b/tests/Unit/Chart/ChartCurrencyTest.php index 359b790ce7..d3aa9cc381 100644 --- a/tests/Unit/Chart/ChartCurrencyTest.php +++ b/tests/Unit/Chart/ChartCurrencyTest.php @@ -31,7 +31,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; class ChartCurrencyTest extends TestCase { use MockAccountData; - // use DatabaseTransactions; + use DatabaseTransactions; protected function setUp(): void { @@ -111,7 +111,7 @@ class ChartCurrencyTest extends TestCase 'tax_rate1' => 0, 'tax_rate2' => 0, 'tax_rate3' => 0, -'discount' => 0, + 'discount' => 0, ]); $i2 = Invoice::factory()->create([ @@ -134,7 +134,7 @@ class ChartCurrencyTest extends TestCase 'tax_rate1' => 0, 'tax_rate2' => 0, 'tax_rate3' => 0, -'discount' => 0, + 'discount' => 0, ]); $repo = new InvoiceRepository(); @@ -144,14 +144,12 @@ class ChartCurrencyTest extends TestCase $i1->service()->markPaid()->save(); $i2->service()->markPaid()->save(); - -$this->assertEquals(100, $i1->amount); -$this->assertEquals(100, $i2->amount); + $this->assertEquals(100, $i1->amount); + $this->assertEquals(100, $i2->amount); $cs = new ChartService($company, $this->user, true); $results = $cs->totals('1970-01-01', '2050-01-01'); - nlog($results); $this->assertCount(2, $results['currencies']); $this->assertEquals('USD', $results['currencies'][1]); diff --git a/tests/Unit/CompanyDocumentsTest.php b/tests/Unit/CompanyDocumentsTest.php index 34e835b90f..317eaed54a 100644 --- a/tests/Unit/CompanyDocumentsTest.php +++ b/tests/Unit/CompanyDocumentsTest.php @@ -23,7 +23,7 @@ use Tests\TestCase; class CompanyDocumentsTest extends TestCase { use MockAccountData; - // use DatabaseTransactions; + use DatabaseTransactions; protected function setUp(): void { diff --git a/tests/Unit/EntityTest.php b/tests/Unit/EntityTest.php index 5cebbf190f..aeb182055e 100644 --- a/tests/Unit/EntityTest.php +++ b/tests/Unit/EntityTest.php @@ -34,7 +34,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; class EntityTest extends TestCase { use MockAccountData; - // use DatabaseTransactions; + use DatabaseTransactions; public $invoice; @@ -89,17 +89,6 @@ class EntityTest extends TestCase protected function tearDown(): void { - - - // $this->company->company_users->each(function ($company_user) { - // $company_user->user->forceDelete(); - // $company_user->forceDelete(); - // }); - - // // Clean up any resources or reset state if necessary - // $this->account->delete(); - - parent::tearDown(); } } diff --git a/tests/Unit/GeneratesCounterTest.php b/tests/Unit/GeneratesCounterTest.php index 28d904a1de..5b0cad3920 100644 --- a/tests/Unit/GeneratesCounterTest.php +++ b/tests/Unit/GeneratesCounterTest.php @@ -422,13 +422,16 @@ class GeneratesCounterTest extends TestCase public function testInvoiceNumberValue() { - $invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh()); - $this->assertEquals($invoice_number, '0002'); + $this->assertEquals('0002', $this->invoice->fresh()->number); $invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh()); $this->assertEquals($invoice_number, '0003'); + + $invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh()); + + $this->assertEquals($invoice_number, '0004'); } public function testQuoteNumberValue() @@ -605,11 +608,13 @@ class GeneratesCounterTest extends TestCase $invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice); - $this->assertEquals($invoice_number, '0002'); + $this->assertEquals('0002', $this->invoice->fresh()->number); + + $this->assertEquals('0003', $invoice_number); $invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice); - $this->assertEquals($invoice_number, '0003'); + $this->assertEquals('0004', $invoice_number ); } public function testClientNumber()