import { describe, expect, test } from "bun:test"; import { decodeSatellitePayload, inferSatelliteFootprintPolicy, parseTleOrbitalElements, SATELLITE_COMPACT_FORMAT, } from "../public/earth/js/satellite-catalog.js"; const ISS_TLE_LINE1 = "1 25544U 98067A 26001.50000000 .00016717 00000-0 10270-3 0 9995"; const ISS_TLE_LINE2 = "2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537"; describe("satellite-catalog compact decoder & TLE parser", () => { test("parses orbital elements accurately from standard TLE lines", () => { const parsed = parseTleOrbitalElements(ISS_TLE_LINE1, ISS_TLE_LINE2); expect(parsed.classification_type).toBe("U"); expect(parsed.international_designator).toBe("98067A"); expect(parsed.epoch).toBe("2026-01-01T12:00:00.000Z"); expect(parsed.bstar).toBeCloseTo(0.0001027, 8); expect(parsed.inclination).toBeCloseTo(51.6416, 4); expect(parsed.raan).toBeCloseTo(247.4627, 4); expect(parsed.eccentricity).toBeCloseTo(0.0006703, 7); expect(parsed.arg_of_perigee).toBeCloseTo(130.536, 4); expect(parsed.mean_anomaly).toBeCloseTo(325.0288, 4); expect(parsed.mean_motion).toBeCloseTo(15.72125391, 8); }); test("maps footprint policy per constellation group", () => { expect(inferSatelliteFootprintPolicy("starlink")).toBe("starlink_ground_footprint"); expect(inferSatelliteFootprintPolicy("iridium-next")).toBe("iridium_coverage_ring"); expect(inferSatelliteFootprintPolicy("leo")).toBe("none"); }); test("decodes compact rows with TLE and fallback rows without TLE", () => { const features = decodeSatellitePayload({ format: SATELLITE_COMPACT_FORMAT, count: 2, satellites: [ [101, 25544, "ISS (ZARYA)", "starlink", ISS_TLE_LINE1, ISS_TLE_LINE2], [ 102, 55000, "CUSTOM-SAT", "iridium-next", null, null, [86.4, 10.2, 0.001, 45.0, 90.0, 14.3, "2026-02-01T00:00:00Z", "24010A", "U", 0.0002], ], ], }); expect(features).toHaveLength(2); expect(features[0].id).toBe(25544); expect(features[0].properties.norad_cat_id).toBe(25544); expect(features[0].properties.footprint_policy).toBe("starlink_ground_footprint"); expect(features[0].properties.inclination).toBeCloseTo(51.6416, 4); expect(features[0].properties.tle_line1).toBe(ISS_TLE_LINE1); expect(features[0].properties.data_type).toBe("satellite_tle"); expect(features[1].properties.footprint_policy).toBe("iridium_coverage_ring"); expect(features[1].properties.inclination).toBe(86.4); expect(features[1].properties.international_designator).toBe("24010A"); expect(features[1].properties.bstar).toBe(0.0002); }); test("passes through legacy GeoJSON FeatureCollection payloads unchanged", () => { const legacyFeature = { type: "Feature", id: 25544, geometry: { type: "Point", coordinates: [0, 0, 0] }, properties: { norad_cat_id: 25544, name: "ISS (ZARYA)" }, }; const features = decodeSatellitePayload({ type: "FeatureCollection", features: [legacyFeature], }); expect(features).toEqual([legacyFeature]); }); });