server/test/swpc.test.ts
28 lines · 1180 bytes
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { decode, next24h } from "../src/swpc.ts";
4
5// Shapes copied from the live SWPC feeds on 2026-10-17.
6const now = [
7 { time_tag: "2026-10-17T23:32:00", kp_index: 0, estimated_kp: 0.33, kp: "0P" },
8 { time_tag: "2026-10-17T23:33:00", kp_index: 0, estimated_kp: 0.67, kp: "1M" },
9];
10const forecast = [
11 { time_tag: "2026-10-17T18:00:00", kp: 2.33, observed: "observed", noaa_scale: null },
12 { time_tag: "2026-10-18T00:00:00", kp: 3.67, observed: "predicted", noaa_scale: null },
13 { time_tag: "2026-10-18T09:00:00", kp: 5.33, observed: "predicted", noaa_scale: "G1" },
14 { time_tag: "2026-10-19T21:00:00", kp: 7.0, observed: "predicted", noaa_scale: "G3" },
15];
16
17test("decodes latest Kp and forecast", () => {
18 const w = decode(now, forecast);
19 assert.equal(w.kpNow, 0.67);
20 assert.equal(w.observedAt, "2026-10-17T23:33:00.000Z");
21 assert.equal(w.forecast.length, 4);
22 assert.equal(w.forecast[0].predicted, false);
23});
24
25test("next 24 h maximum ignores observed and later rows", () => {
26 const w = decode(now, forecast);
27 assert.equal(next24h(w, new Date("2026-10-17T23:34:00Z")), 5.33);
28});