Files
coolify/tests/Feature/TrafficAnalytics/AnalyticsFormattingTest.php
T
Aditya Tripathi a5cfa7c238 feat(traffic): add global analytics page with status time series
Replace the server-scoped Analytics Livewire component with an
app-wide one that filters by server/application and supports live
refresh. Add a per-bucket status-class time series endpoint/data
class for a stacked-area chart, falling back to the donut when the
Sentinel build doesn't support it. Decorate top-path rows with their
owning domain, expand breakdown dimensions to agent/ip/useragent, and
raise path/breakdown result limits. Capture X-Forwarded-For,
User-Agent, and Referer headers in traefik access logs (now enabled
in dev too) so IP, browser, and referrer breakdowns work. Add
flag-image and referer-host helpers for geo/referrer rendering.
2026-08-12 08:50:58 +00:00

35 lines
1.5 KiB
PHP

<?php
// Presentation helpers for the analytics views (items: flags, referrer favicons,
// device capitalization).
it('maps woothee device categories to friendly capitalized labels', function () {
expect(deviceLabel('pc'))->toBe('Desktop');
expect(deviceLabel('smartphone'))->toBe('Mobile');
expect(deviceLabel('mobilephone'))->toBe('Mobile');
expect(deviceLabel('crawler'))->toBe('Bot');
expect(deviceLabel('tablet'))->toBe('Tablet');
expect(deviceLabel(''))->toBe('Unknown');
expect(deviceLabel(null))->toBe('Unknown');
});
it('extracts a bare host from referer URLs and bare hosts, dropping www', function () {
expect(refererHost('https://www.google.com/search?q=x'))->toBe('google.com');
expect(refererHost('http://news.ycombinator.com'))->toBe('news.ycombinator.com');
expect(refererHost('example.com'))->toBe('example.com');
expect(refererHost(''))->toBeNull();
expect(refererHost(null))->toBeNull();
});
it('builds a duckduckgo favicon url for a host', function () {
expect(refererFaviconUrl('example.com'))->toBe('https://icons.duckduckgo.com/ip3/example.com.ico');
});
it('builds a flagcdn image url for valid ISO codes only', function () {
expect(countryFlagUrl('US'))->toBe('https://flagcdn.com/24x18/us.png');
expect(countryFlagUrl('de', '48x36'))->toBe('https://flagcdn.com/48x36/de.png');
expect(countryFlagUrl('ZZZ'))->toBeNull();
expect(countryFlagUrl(''))->toBeNull();
expect(countryFlagUrl(null))->toBeNull();
});