Files
coolify/tests/Feature/TrafficAnalytics/TrafficDataTest.php
T
Andras Bacsai f17cdc1c74 feat(analytics): add server analytics page and split settings
Add a per-server Analytics page scoped to that host, move traffic
settings out of Sentinel, and put metrics settings on Charts.
Surface 4xx/5xx on path rows and restyle deployment logs.
2026-09-08 14:20:41 +02:00

39 lines
1.1 KiB
PHP

<?php
use App\Data\Traffic\TrafficOverviewData;
use App\Data\Traffic\TrafficPathData;
it('maps a sentinel overview payload into a DTO', function () {
$json = [
'requests' => 10, 'bytes_in' => 100, 'bytes_out' => 200,
'status' => ['s2xx' => 8, 's3xx' => 1, 's4xx' => 1, 's5xx' => 0],
'latency' => ['p50' => 12.5, 'p95' => 40.0, 'p99' => 90.0],
'unique_visitors' => 5,
];
$dto = TrafficOverviewData::fromSentinel($json);
expect($dto->requests)->toBe(10);
expect($dto->s4xx)->toBe(1);
expect($dto->latencyP95)->toBe(40.0);
expect($dto->uniqueVisitors)->toBe(5);
});
it('produces a zeroed overview', function () {
expect(TrafficOverviewData::zero()->requests)->toBe(0);
});
it('maps per-path error counters from sentinel', function () {
$dto = TrafficPathData::fromSentinel([
'path' => '/api/checkout',
'app' => 'app-1',
'requests' => 20,
'bytes_out' => 1000,
's4xx' => 3,
's5xx' => 2,
'p50' => 10,
'p95' => 30,
]);
expect($dto->s4xx)->toBe(3)
->and($dto->s5xx)->toBe(2);
});