Updates for tests

This commit is contained in:
David Bomba 2025-08-15 10:02:15 +10:00
parent cba7e7b2bd
commit 579bb07af3
7 changed files with 62 additions and 67 deletions

View File

@ -263,7 +263,6 @@ class StaticServiceProvider extends ServiceProvider
}); });
nlog("static service provider registered");
} }
public function boot() public function boot()

View File

@ -67,6 +67,7 @@ use App\DataMapper\ClientRegistrationFields;
use App\Jobs\Company\CreateCompanyTaskStatuses; use App\Jobs\Company\CreateCompanyTaskStatuses;
use App\Repositories\RecurringInvoiceRepository; use App\Repositories\RecurringInvoiceRepository;
use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Factory\InvoiceToRecurringInvoiceFactory;
use App\Repositories\CreditRepository;
/** /**
* Class MockAccountData. * Class MockAccountData.
@ -211,18 +212,14 @@ trait MockAccountData
Artisan::call('db:seed', ['--force' => true]); Artisan::call('db:seed', ['--force' => true]);
} }
app()->singleton('currencies', function ($app) { app()->singleton('currencies', function ($app) {
$resource = Currency::query()->orderBy('name')->get(); $resource = Currency::query()->orderBy('name')->get();
Cache::forever('currencies', $resource); Cache::forever('currencies', $resource);
return $resource; return $resource;
}); });
$this->faker = \Faker\Factory::create(); $this->faker = \Faker\Factory::create();
$fake_email = $this->faker->email(); $fake_email = $this->faker->email();
@ -566,27 +563,30 @@ trait MockAccountData
$this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit);
CreditInvitation::factory()->create([ // CreditInvitation::factory()->create([
'user_id' => $user_id, // 'user_id' => $user_id,
'company_id' => $this->company->id, // 'company_id' => $this->company->id,
'client_contact_id' => $contact->id, // 'client_contact_id' => $contact->id,
'credit_id' => $this->credit->id, // 'credit_id' => $this->credit->id,
]); // ]);
CreditInvitation::factory()->create([ // CreditInvitation::factory()->create([
'user_id' => $user_id, // 'user_id' => $user_id,
'company_id' => $this->company->id, // 'company_id' => $this->company->id,
'client_contact_id' => $contact2->id, // 'client_contact_id' => $contact2->id,
'credit_id' => $this->credit->id, // 'credit_id' => $this->credit->id,
]); // ]);
$this->credit->setRelation('client', $this->client); // $this->credit->setRelation('client', $this->client);
$this->credit->setRelation('company', $this->company); // $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 = PurchaseOrderFactory::create($this->company->id, $user_id);
$this->purchase_order->vendor_id = $this->vendor->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->ledger()->updateCreditBalance($this->credit->balance)->save();
$this->credit->number = $this->getNextCreditNumber($this->client, $this->credit); $this->credit->number = $this->getNextCreditNumber($this->client, $this->credit);
CreditInvitation::factory()->create([ $this->credit->save();
'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, $repo = new CreditRepository();
'company_id' => $this->company->id, $repo->save([], $this->credit);
'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' => $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([ $this->bank_integration = BankIntegration::factory()->create([
'user_id' => $user_id, 'user_id' => $user_id,
@ -705,17 +711,17 @@ trait MockAccountData
'company_id' => $this->company->id, 'company_id' => $this->company->id,
]); ]);
$invitations = CreditInvitation::whereCompanyId($this->credit->company_id) // $invitations = CreditInvitation::whereCompanyId($this->credit->company_id)
->whereCreditId($this->credit->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('client', $this->client);
$this->credit->setRelation('company', $this->company); // $this->credit->setRelation('company', $this->company);
$this->credit->save(); // $this->credit->save();
$contacts = $this->invoice->client->contacts; $contacts = $this->invoice->client->contacts;

View File

@ -22,7 +22,7 @@ use Illuminate\Support\Facades\Artisan;
*/ */
class AutoBillInvoiceTest extends TestCase class AutoBillInvoiceTest extends TestCase
{ {
// use DatabaseTransactions; use DatabaseTransactions;
use MockAccountData; use MockAccountData;
protected function setUp(): void protected function setUp(): void
@ -30,12 +30,10 @@ class AutoBillInvoiceTest extends TestCase
parent::setUp(); parent::setUp();
$this->makeTestData(); $this->makeTestData();
} }
public function testAutoBillFunctionality() public function testAutoBillFunctionality()
{ {
$this->assertEquals('1', $this->client->settings->currency_id);
$this->assertEquals($this->client->balance, 10); $this->assertEquals($this->client->balance, 10);
$this->assertEquals($this->client->paid_to_date, 0); $this->assertEquals($this->client->paid_to_date, 0);
$this->assertEquals($this->client->credit_balance, 10); $this->assertEquals($this->client->credit_balance, 10);

View File

@ -31,7 +31,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class ChartCurrencyTest extends TestCase class ChartCurrencyTest extends TestCase
{ {
use MockAccountData; use MockAccountData;
// use DatabaseTransactions; use DatabaseTransactions;
protected function setUp(): void protected function setUp(): void
{ {
@ -111,7 +111,7 @@ class ChartCurrencyTest extends TestCase
'tax_rate1' => 0, 'tax_rate1' => 0,
'tax_rate2' => 0, 'tax_rate2' => 0,
'tax_rate3' => 0, 'tax_rate3' => 0,
'discount' => 0, 'discount' => 0,
]); ]);
$i2 = Invoice::factory()->create([ $i2 = Invoice::factory()->create([
@ -134,7 +134,7 @@ class ChartCurrencyTest extends TestCase
'tax_rate1' => 0, 'tax_rate1' => 0,
'tax_rate2' => 0, 'tax_rate2' => 0,
'tax_rate3' => 0, 'tax_rate3' => 0,
'discount' => 0, 'discount' => 0,
]); ]);
$repo = new InvoiceRepository(); $repo = new InvoiceRepository();
@ -144,14 +144,12 @@ class ChartCurrencyTest extends TestCase
$i1->service()->markPaid()->save(); $i1->service()->markPaid()->save();
$i2->service()->markPaid()->save(); $i2->service()->markPaid()->save();
$this->assertEquals(100, $i1->amount);
$this->assertEquals(100, $i1->amount); $this->assertEquals(100, $i2->amount);
$this->assertEquals(100, $i2->amount);
$cs = new ChartService($company, $this->user, true); $cs = new ChartService($company, $this->user, true);
$results = $cs->totals('1970-01-01', '2050-01-01'); $results = $cs->totals('1970-01-01', '2050-01-01');
nlog($results);
$this->assertCount(2, $results['currencies']); $this->assertCount(2, $results['currencies']);
$this->assertEquals('USD', $results['currencies'][1]); $this->assertEquals('USD', $results['currencies'][1]);

View File

@ -23,7 +23,7 @@ use Tests\TestCase;
class CompanyDocumentsTest extends TestCase class CompanyDocumentsTest extends TestCase
{ {
use MockAccountData; use MockAccountData;
// use DatabaseTransactions; use DatabaseTransactions;
protected function setUp(): void protected function setUp(): void
{ {

View File

@ -34,7 +34,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class EntityTest extends TestCase class EntityTest extends TestCase
{ {
use MockAccountData; use MockAccountData;
// use DatabaseTransactions; use DatabaseTransactions;
public $invoice; public $invoice;
@ -89,17 +89,6 @@ class EntityTest extends TestCase
protected function tearDown(): void 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(); parent::tearDown();
} }
} }

View File

@ -422,13 +422,16 @@ class GeneratesCounterTest extends TestCase
public function testInvoiceNumberValue() 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()); $invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh());
$this->assertEquals($invoice_number, '0003'); $this->assertEquals($invoice_number, '0003');
$invoice_number = $this->getNextInvoiceNumber($this->client->fresh(), $this->invoice->fresh());
$this->assertEquals($invoice_number, '0004');
} }
public function testQuoteNumberValue() public function testQuoteNumberValue()
@ -605,11 +608,13 @@ class GeneratesCounterTest extends TestCase
$invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice); $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); $invoice_number = $this->getNextInvoiceNumber($cliz->fresh(), $this->invoice);
$this->assertEquals($invoice_number, '0003'); $this->assertEquals('0004', $invoice_number );
} }
public function testClientNumber() public function testClientNumber()