quality / changes (push) Successful in 9s
quality / commitlint (push) Skipped
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 6s
quality / web (push) Successful in 1m29s
quality / api (push) Successful in 1m10s
CD / quality (push) Successful in 2m54s
CD / publish (push) Successful in 42s
Собрать панель, списки и настройки в одной оболочке, чтобы статусы, очередь и свежесть данных были видны на доменах, сервисах и группах. Co-authored-by: Cursor <cursoragent@cursor.com>
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { deriveSystemAttention, isCertExpiringWithin } from './system-attention'
|
|
|
|
const NOW = Date.parse('2026-11-02T00:00:00.000Z')
|
|
|
|
function inDays(days: number) {
|
|
return new Date(NOW + days * 86_400_000).toISOString()
|
|
}
|
|
|
|
describe('deriveSystemAttention', () => {
|
|
it('считает Down и деградацию в группах и без группы', () => {
|
|
const attention = deriveSystemAttention({
|
|
now: NOW,
|
|
readyIsSuccess: true,
|
|
readyIsError: false,
|
|
readyStatus: 'ready',
|
|
services: {
|
|
groups: [
|
|
{
|
|
services: [
|
|
{ id: 1, name: 'Альфа', health_status: 'down' },
|
|
{ id: 2, name: 'Бета', health_status: 'up' },
|
|
],
|
|
},
|
|
],
|
|
ungrouped: [{ id: 3, name: 'Гамма', health_status: 'degraded' }],
|
|
},
|
|
})
|
|
|
|
expect(attention.servicesDown).toBe(1)
|
|
expect(attention.servicesDegraded).toBe(1)
|
|
expect(attention.incidents.map((item) => item.title)).toEqual(['Альфа', 'Гамма'])
|
|
expect(attention.incidents[0]).toMatchObject({
|
|
tone: 'destructive',
|
|
href: { to: '/services/$serviceId', serviceId: '1' },
|
|
})
|
|
})
|
|
|
|
it('берёт сертификаты с остатком не больше 14 дней, включая истёкшие', () => {
|
|
expect(isCertExpiringWithin(inDays(14), 14, NOW)).toBe(true)
|
|
expect(isCertExpiringWithin(inDays(14.01), 14, NOW)).toBe(false)
|
|
expect(isCertExpiringWithin(inDays(-1), 14, NOW)).toBe(true)
|
|
|
|
const attention = deriveSystemAttention({
|
|
now: NOW,
|
|
readyIsSuccess: false,
|
|
readyIsError: false,
|
|
certificates: [
|
|
{ id: 10, hostname: 'soon.example', expires_at: inDays(3), service_id: 7 },
|
|
{ id: 11, hostname: 'later.example', expires_at: inDays(20), service_id: 7 },
|
|
{ id: 12, hostname: 'dead.example', expires_at: inDays(-2), service_id: null },
|
|
{ id: 13, hostname: 'unknown.example', expires_at: null },
|
|
],
|
|
certSummary: [
|
|
['warning', 2],
|
|
['expired', 1],
|
|
['ok', 4],
|
|
],
|
|
notifications: [
|
|
{ kind: 'sync', title: 'Sync failed', message: 'timeout' },
|
|
{ kind: 'info', title: 'Готово', message: 'ok' },
|
|
],
|
|
domains: [{ group_id: null }, { group_id: 1 }],
|
|
})
|
|
|
|
expect(attention.certsExpiring).toBe(2)
|
|
expect(attention.certWarnings).toBe(3)
|
|
expect(attention.failedJobs).toBe(1)
|
|
expect(attention.ungroupedCount).toBe(1)
|
|
expect(attention.incidents.map((item) => item.title)).toEqual([
|
|
'dead.example',
|
|
'soon.example',
|
|
])
|
|
expect(attention.incidents[0]?.href).toEqual({ to: '/certificates' })
|
|
expect(attention.incidents[1]?.href).toEqual({
|
|
to: '/services/$serviceId',
|
|
serviceId: '7',
|
|
})
|
|
})
|
|
})
|