fix: ignore malformed bar analytics date keys (#1556)

* fix: ignore malformed bar analytics date keys

* style: apply prettier formatting to dynamic imports
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-06-20 16:23:22 -04:00
1 parent b811cacaef
commit e37a87c3a2
2 files changed
+41 -9

No files matched your search

@@ -228,6 +228,24 @@ describe('computeBarAnalyticsFromDaily — monthToDate', () => {
expect(a.last30d.cost).toBe(20); // rolling 30d still populated
});
it('ignores malformed aggregate date keys instead of throwing', () => {
const a = computeBarAnalyticsFromDaily(
[daily({ date: 'May 1 2026', totalCost: 10 }), daily({ date: '2026-06-08', totalCost: 4 })],
[
hourly({ hour: 'May 1 2026 00:00', requestCount: 5 }),
hourly({ hour: '2026-06-08 09:00', requestCount: 3 }),
],
NOW
);
expect(a.today.cost).toBe(4);
expect(a.today.requests).toBe(3);
expect(a.allTime.cost).toBe(4);
expect(a.allTime.requests).toBe(3);
expect(a.lastActivityAt).toBe(new Date(2026, 5, 8).toISOString());
expect(a.daysSinceLastActivity).toBe(0);
});
it('returns zeroed monthToDate for empty daily and hourly input', () => {
const a = computeBarAnalyticsFromDaily([], [], NOW);
expect(a.monthToDate).toEqual({ cost: 0, requests: 0 });