Files
InvoiceShelf/tests/Feature/RealisticDemoSeederTest.php
T
Darko Gjorgjijoski 5ef7804e60 refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration

* refactor: extract module platform context

* refactor: assign models to domain contexts

* refactor: extract ai platform context

* refactor: extract storage platform context

* refactor: extract mail platform context

* refactor: extract pdf platform context

* refactor: extract operations platform context

* refactor: move installation into operations platform

* refactor: extract money domain context

* refactor: extract taxation domain context

* refactor: extract catalog domain context

* refactor: extract metadata domain context

* refactor: extract reporting domain context

* refactor: extract purchases domain context

* refactor: extract receivables domain context

* refactor: extract accounts domain context

* refactor: complete reporting statement boundary

* refactor: extract contacts domain context

* refactor: extract sales domain context

* refactor: remove legacy application layers

* fix: migrate legacy bouncer role identities
2026-08-05 17:40:03 +02:00

61 lines
2.4 KiB
PHP

<?php
use App\Domains\Accounts\Models\User;
use App\Domains\Contacts\Models\Customer;
use App\Domains\Receivables\Models\Payment;
use App\Domains\Receivables\Models\PaymentAllocation;
use App\Domains\Reporting\Queries\CustomerStatementQuery;
use App\Domains\Sales\Models\Invoice;
use Carbon\Carbon;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Queue;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Queue::fake();
});
test('realistic demo payments are allocated and leave invoice balances consistent', function () {
Artisan::call('db:seed', ['--class' => 'RealisticDemoSeeder', '--force' => true]);
$company = User::where('email', 'demo@invoiceshelf.com')->firstOrFail()->companies()->firstOrFail();
$payments = Payment::query()->where('company_id', $company->id)->with('allocations')->get();
$allocatedInvoices = Invoice::query()
->where('company_id', $company->id)
->whereHas('allocations')
->with('allocations')
->get();
expect($payments)->not->toBeEmpty()
->and($payments->every(fn (Payment $payment) => $payment->allocations->isNotEmpty()))->toBeTrue()
->and(PaymentAllocation::query()->whereIn('payment_id', $payments->modelKeys())->count())->toBe($payments->count());
foreach ($allocatedInvoices as $invoice) {
expect((int) $invoice->due_amount)
->toBe(max(0, (int) $invoice->total - (int) $invoice->allocations->sum('amount')));
}
});
test('realistic demo provides current-month account activity for every customer', function () {
Artisan::call('db:seed', ['--class' => 'RealisticDemoSeeder', '--force' => true]);
$company = User::where('email', 'demo@invoiceshelf.com')->firstOrFail()->companies()->firstOrFail();
$from = Carbon::now()->startOfMonth();
$to = Carbon::now();
$statementQuery = app(CustomerStatementQuery::class);
Customer::query()
->where('company_id', $company->id)
->each(function (Customer $customer) use ($statementQuery, $from, $to): void {
$statement = $statementQuery->statement(
$customer,
CustomerStatementQuery::TYPE_ACTIVITY,
$from,
$to,
);
expect($statement['entries']->total())->toBeGreaterThan(0);
});
});