Files
portal/app/tests/Feature/Admin/AdminDashboardSummaryTest.php
T
Дмитрий f30c6612c0 fix дашборд: достоверность метрик (здоровье/лиды/заказ) + периоды 60/90д
По сверке прод-данных с реальностью (часть чисел вводила в заблуждение):
- Финансы: +периоды 60 и 90 дней (крупные пополнения старше 30д теперь видны).
- Здоровье: «инциденты» больше не считают авто-лог ошибок джоб (summary
  'Автоматически:%') — раньше копилось 975 и держало красный ложно. Теперь:
  open_incidents = только реальные; добавлен job_errors_24h (повторяющиеся
  ошибки джоб за сутки) в подсистему queues.
- Лиды: убраны обманчивый «% доставки» (это было «обработано», не доставлено)
  и «нераспределённые по менеджерам» (менеджеры не используются). Добавлено
  «получено от поставщика сегодня»; доставлено = реально созданные сегодня сделки.
- Заказ: показаны дата снимка и полная картина (всего активных заказов /
  Σ лимита у поставщика) — сверка по снимку больше не выглядит занижено.

Тесты: admin-срез 87 зелёных, unit 3/3, фронт 10/10. stan 0, pint/eslint/
type-check/build чисто.

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

51 lines
2.0 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');
});
it('summary включает плитки leads и supply', function () {
$res = $this->getJson('/api/admin/dashboard?period=30d');
$res->assertOk();
$res->assertJsonStructure([
'finance' => ['light'],
'health' => ['light'],
'leads' => ['light', 'delivered_today', 'received_today', 'stuck', 'unrouted'],
'supply' => ['light', 'demand', 'formula', 'ordered', 'mismatches', 'total_orders', 'total_limit'],
'period',
]);
});