import { describe, expect, it } from "vitest"; import { accessAddressDetails, groupAccessAddresses } from "./access-address-groups"; describe("groupAccessAddresses", () => { it("collapses repeated observations from the same network into one recent summary", () => { const groups = groupAccessAddresses([ { id: "old", ipAddress: "198.51.100.21", source: "web", classification: "clear", observedAt: new Date("2026-08-01T10:00:00Z"), intelligence: null }, { id: "new", ipAddress: "198.51.100.240", source: "game", classification: "clear", observedAt: new Date("2026-08-01T12:00:00Z"), intelligence: { provider: "proxycheck" } }, { id: "other", ipAddress: "203.0.113.9", source: "web", classification: "vpn", observedAt: new Date("2026-08-01T11:00:00Z"), intelligence: null }, ]); expect(groups).toHaveLength(2); expect(groups[0]).toMatchObject({ network: "198.51.100.0/24", latestAddress: "198.51.100.240", sources: ["game", "web"], count: 2, classification: "clear", intelligence: { provider: "proxycheck" }, }); expect(groups[0]?.latestObservedAt.toISOString()).toBe("2026-08-01T12:00:00.000Z"); }); it("presents the latest enriched location and classification with observation fallbacks", () => { expect(accessAddressDetails({ classification: "vpn", intelligence: { classification: "vpn", location: { city: "Toronto", region: "Ontario", countryCode: "CA" }, }, })).toEqual({ location: "Toronto, Ontario, CA", classification: "vpn" }); expect(accessAddressDetails({ classification: "hosting", intelligence: null })).toEqual({ location: "Location unavailable", classification: "hosting", }); }); });