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/ll2.test.ts

b327e0d6e7ab67511c5bade3f3c3a93834f6e9ca
moonrise/server/test/ll2.test.ts history · blame · raw

58 lines · 2509 bytes

 1import assert from "node:assert/strict";
 2import { test } from "node:test";
 3import { normalize, PREVIOUS_URL } from "../src/ll2.ts";
 4
 5// Trimmed from /2.3.0/launches/upcoming/?mode=normal on 2026-10-17.
 6const raw = {
 7  id: "3b430f81-0ff1-4d85-8a1a-cef0de326198",
 8  name: "Falcon 9 Block 5 | Bandwagon 5 (Dedicated Mid-Inclination Rideshare)",
 9  net: "2026-10-19T10:30:00Z",
10  window_start: "2026-10-19T10:30:00Z",
11  window_end: "2026-10-19T11:30:00Z",
12  last_updated: "2026-10-17T20:00:00Z",
13  status: { id: 1, name: "Go for Launch", abbrev: "Go" },
14  launch_service_provider: { name: "SpaceX", abbrev: "SpX" },
15  rocket: { configuration: { name: "Falcon 9", full_name: "Falcon 9 Block 5" } },
16  mission: { name: "Bandwagon 5", type: "Dedicated Rideshare", description: " Rideshare. ", orbit: { abbrev: "LEO" } },
17  pad: { name: "Space Launch Complex 40", latitude: "28.56194122", longitude: "-80.57735736", location: { name: "Cape Canaveral SFS, FL, USA" } },
18};
19
20test("normalizes a launch", () => {
21  const l = normalize(raw);
22  assert.equal(l.rocket, "Falcon 9 Block 5");
23  assert.equal(l.status, "Go");
24  assert.equal(l.orbit, "LEO");
25  assert.equal(l.missionDescription, "Rideshare.");
26  assert.equal(l.padLatitude, 28.56194122);
27});
28
29test("tolerates a missing mission", () => {
30  const l = normalize({ ...raw, mission: null });
31  assert.equal(l.mission, null);
32  assert.equal(l.orbit, null);
33});
34
35// Trimmed from /2.3.0/launches/previous/?mode=normal on 2026-10-19.
36const launched = {
37  id: "97c6f5e1-299e-4652-b72d-9618ac047076",
38  name: "Falcon 9 Block 5 | Starlink Group 15-25",
39  net: "2026-10-13T00:28:11Z",
40  window_start: "2026-10-12T23:00:00Z",
41  window_end: "2026-10-13T03:00:00Z",
42  last_updated: "2026-10-13T10:10:50Z",
43  launch_designator: "2026-232",
44  status: { name: "Launch Successful", abbrev: "Success" },
45  launch_service_provider: { name: "SpaceX" },
46  rocket: { configuration: { name: "Falcon 9", full_name: "Falcon 9 Block 5" } },
47  mission: { name: "Starlink Group 15-25", type: "Communications", orbit: { abbrev: "LEO" } },
48  pad: { name: "Space Launch Complex 4E", latitude: 34.632, longitude: -120.611, location: { name: "Vandenberg SFB, CA, USA" } },
49};
50
51test("keeps the international designator once launched", () => {
52  assert.equal(normalize(launched).designator, "2026-232");
53  assert.equal(normalize(raw).designator, null);
54});
55
56test("previous launches are fetched ten at a time", () => {
57  assert.match(PREVIOUS_URL, /\/launches\/previous\/\?limit=10&mode=normal$/);
58});