krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

server/test/aurora.test.ts

04b2b1d914788057bcd20945b876847386eb8f65
moonrise/server/test/aurora.test.ts history · blame · raw

43 lines · 1675 bytes

 1import assert from "node:assert/strict";
 2import { test } from "node:test";
 3import { actionableKp, alertBands, bandFor, eventKey, isNight, ovalEdge, visibleFrom } from "../src/aurora.ts";
 4
 5test("oval edge follows the NOAA chart", () => {
 6  assert.equal(ovalEdge(0), 66.5);
 7  assert.ok(Math.abs(ovalEdge(5) - 56.3) < 0.1);
 8  assert.ok(Math.abs(visibleFrom(5) - 50.3) < 0.1);
 9});
10
11test("bands", () => {
12  assert.equal(bandFor(52.4), 50);
13  assert.equal(bandFor(49.9), 45);
14  assert.equal(bandFor(-52.4), -55);
15});
16
17test("Kp 5 alerts bands reaching 50.3° geomagnetic, both hemispheres", () => {
18  assert.deepEqual(alertBands(5, [40, 45, 50, 55, -45, -55]), [50, 55, -55]);
19  // Kp 2: visible from 56.4°, which the 55–60° band reaches.
20  assert.deepEqual(alertBands(2, [45, 50, 55]), [55]);
21});
22
23test("night is 20:00 to 04:00 local", () => {
24  const t = new Date("2026-10-18T02:00:00Z"); // 21:00 CDT
25  assert.equal(isNight(t, -300), true);
26  assert.equal(isNight(new Date("2026-10-17T18:00:00Z"), -300), false); // 13:00 CDT
27  assert.equal(isNight(new Date("2026-10-18T08:30:00Z"), -300), true); // 03:30 CDT
28});
29
30test("event key splits the UTC day in two", () => {
31  assert.equal(eventKey(new Date("2026-10-18T02:00:00Z")), "2026-10-18a");
32  assert.equal(eventKey(new Date("2026-10-18T13:00:00Z")), "2026-10-18b");
33});
34
35test("actionable Kp takes the forecast for the next 3 hours", () => {
36  const now = new Date("2026-10-18T01:00:00Z");
37  const f = [
38    { start: new Date("2026-10-18T00:00:00Z"), kp: 4 },
39    { start: new Date("2026-10-18T03:00:00Z"), kp: 6 },
40    { start: new Date("2026-10-18T09:00:00Z"), kp: 8 },
41  ];
42  assert.equal(actionableKp(2, f, now), 6);
43});