52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Families;
|
|
|
|
use App\Services\Families\FamilyFinanceService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
class FamilyFinanceServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_load_financials_for_parents_returns_summary(): void
|
|
{
|
|
DB::table('invoices')->insert([
|
|
'parent_id' => 1,
|
|
'invoice_number' => 'INV-1',
|
|
'status' => 'open',
|
|
'total_amount' => 100,
|
|
'paid_amount' => 20,
|
|
'balance' => 80,
|
|
'issue_date' => now()->toDateString(),
|
|
'due_date' => now()->addDays(5)->toDateString(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('payments')->insert([
|
|
'parent_id' => 1,
|
|
'invoice_id' => 1,
|
|
'total_amount' => 100,
|
|
'paid_amount' => 20,
|
|
'balance' => 80,
|
|
'number_of_installments' => 1,
|
|
'payment_method' => 'cash',
|
|
'payment_date' => now()->toDateString(),
|
|
'status' => 'completed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$service = new FamilyFinanceService();
|
|
$result = $service->loadFinancialsForParents([1]);
|
|
|
|
$this->assertSame(1, $result['summary']['invoices_count']);
|
|
$this->assertSame(100.0, $result['summary']['total_amount']);
|
|
$this->assertNotEmpty($result['invoices']);
|
|
$this->assertNotEmpty($result['payments']);
|
|
}
|
|
}
|