Files
portal/app/tests/Feature/Admin/AdminDashboardFinanceTest.php
T
Дмитрий 9eaa9322dc feat(дашборд): backend Командного центра — summary/finance/health (Этап 1)
3 read-only эндпоинта под группой [saas-admin,admin-db] (cross-tenant через
pgsql_admin): L1 сводка (Финансы+Здоровье), L2 Финансы (KPI+внимание+топ),
L2 Здоровье (6 подсистем+светофор). TDD, 83 admin-теста зелёные. baseline:
+3 Pest getJson false-positive. Без маржи, без новых таблиц.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 12:58:58 +03:00

36 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
uses(DatabaseTransactions::class);
beforeEach(function () {
DB::table('balance_transactions')->delete();
DB::table('tenants')->delete();
});
it('GET /api/admin/dashboard/finance returns KPIs + attention + top tables', function () {
$neg = DB::table('tenants')->insertGetId([
'subdomain' => 'neg', 'organization_name' => 'Negative', 'contact_email' => 'n@x.ru',
'status' => 'active', 'is_trial' => false, 'balance_rub' => -100, 'balance_leads' => 0,
'chargeback_unrecovered_rub' => 0, 'created_at' => now(), 'updated_at' => now(),
]);
DB::table('balance_transactions')->insert([
'tenant_id' => $neg, 'type' => 'topup', 'amount_rub' => 5000, 'created_at' => now(),
]);
$res = $this->getJson('/api/admin/dashboard/finance?period=30d');
$res->assertOk();
$res->assertJsonStructure([
'kpi' => ['topups_rub', 'charges_rub', 'net_inflow_rub', 'negative_balance_count'],
'attention', 'top_by_turnover', 'period',
]);
expect($res->json('kpi.negative_balance_count'))->toBe(1);
expect(collect($res->json('attention'))->pluck('organization_name'))->toContain('Negative');
expect(collect($res->json('top_by_turnover'))->pluck('organization_name'))->toContain('Negative');
});