9eaa9322dc
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>
38 lines
1.5 KiB
PHP
38 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
beforeEach(function () {
|
|
// Чистые счётчики: убираем seed/прошлые данные (FK-порядок: сначала проводки).
|
|
DB::table('balance_transactions')->delete();
|
|
DB::table('tenants')->delete();
|
|
});
|
|
|
|
it('GET /api/admin/dashboard returns finance + health tiles', function () {
|
|
$tenant = DB::table('tenants')->insertGetId([
|
|
'subdomain' => 'acme', 'organization_name' => 'Acme', 'contact_email' => 'a@acme.ru',
|
|
'status' => 'active', 'is_trial' => false, 'balance_rub' => -500, 'balance_leads' => 0,
|
|
'chargeback_unrecovered_rub' => 0, 'created_at' => now(), 'updated_at' => now(),
|
|
]);
|
|
DB::table('balance_transactions')->insert([
|
|
['tenant_id' => $tenant, 'type' => 'topup', 'amount_rub' => 10000, 'created_at' => now()],
|
|
['tenant_id' => $tenant, 'type' => 'lead_charge', 'amount_rub' => -3000, 'created_at' => now()],
|
|
]);
|
|
|
|
$res = $this->getJson('/api/admin/dashboard?period=30d');
|
|
|
|
$res->assertOk();
|
|
$res->assertJsonStructure([
|
|
'finance' => ['topups_rub', 'charges_rub', 'active_clients', 'new_clients', 'negative_balance_count', 'light'],
|
|
'health' => ['light', 'open_incidents', 'last_sync_status'],
|
|
'period',
|
|
]);
|
|
expect($res->json('finance.negative_balance_count'))->toBe(1);
|
|
expect($res->json('finance.light'))->toBe('red');
|
|
});
|