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

Packages/MoonriseKit/Tests/FeedsTests/LaunchTests.swift

59d401dca1a327705632d1e2e20f00f807dee828
moonrise/Packages/MoonriseKit/Tests/FeedsTests/LaunchTests.swift history · blame · raw

40 lines · 2741 bytes

2 symbols in this file
 1import Foundation
 2import Testing
 3@testable import Feeds
 4
 5@Test func decodesBackendLaunches() throws {
 6    // Shape of GET /v1/launches from the local Worker, 2026-10-17.
 7    let data = Data("""
 8    {"fetchedAt":"2026-10-17T23:54:22.559Z","launches":[{"id":"3b430f81","name":"Falcon 9 Block 5 | Bandwagon 5","net":"2026-10-19T10:30:00Z",
 9     "windowStart":"2026-10-19T10:30:00Z","windowEnd":"2026-10-19T11:30:00Z","status":"Go","statusName":"Go for Launch","provider":"SpaceX",
10     "rocket":"Falcon 9 Block 5","mission":"Bandwagon 5","missionType":"Dedicated Rideshare","missionDescription":"Rideshare.","orbit":"LEO",
11     "pad":"Space Launch Complex 40","location":"Cape Canaveral SFS, FL, USA","padLatitude":28.56194122,"padLongitude":-80.57735736},
12     {"id":"x","name":"Electron | HawkEye","net":"2026-10-21T05:00:00Z","windowStart":null,"windowEnd":null,"status":"TBC","statusName":"To Be Confirmed",
13     "provider":"Rocket Lab","rocket":"Electron","mission":null,"missionType":null,"missionDescription":null,"orbit":null,"pad":"LC-1B","location":"Mahia","padLatitude":null,"padLongitude":null}]}
14    """.utf8)
15    let list = try LaunchFeed.decode(data)
16    #expect(list.launches.count == 2)
17    #expect(list.launches[0].rocket == "Falcon 9 Block 5")
18    #expect(list.launches[0].net == (try Date("2026-10-19T10:30:00Z", strategy: .iso8601)))
19    #expect(list.launches[1].mission == nil)
20    #expect(list.fetchedAt != nil)
21    #expect(list.recent == nil)
22    #expect(list.launches[0].elements == nil)
23}
24
25@Test func decodesRecentLaunchesWithElements() throws {
26    // Shape of GET /v1/launches with launch element sets, 2026-10-19.
27    let data = Data("""
28    {"fetchedAt":"2026-10-19T12:00:00.000Z","launches":[],"recent":[{"id":"97c6f5e1","name":"Falcon 9 Block 5 | Starlink Group 15-25",
29     "net":"2026-10-13T00:28:11Z","windowStart":null,"windowEnd":null,"status":"Success","statusName":"Launch Successful","provider":"SpaceX",
30     "rocket":"Falcon 9 Block 5","mission":"Starlink Group 15-25","missionType":"Communications","missionDescription":null,"orbit":"LEO",
31     "pad":"Space Launch Complex 4E","location":"Vandenberg SFB, CA, USA","padLatitude":34.632,"padLongitude":-120.611,
32     "elements":[{"OBJECT_NAME":"Starlink train (Group 15-25)","NORAD_CAT_ID":66001,"EPOCH":"2026-10-18T22:10:01.123456","MEAN_MOTION":15.91,
33      "ECCENTRICITY":0.0001,"INCLINATION":70.0,"RA_OF_ASC_NODE":120.5,"ARG_OF_PERICENTER":90.1,"MEAN_ANOMALY":270.2,"BSTAR":0.0012}],
34     "elementsSource":"gp"}]}
35    """.utf8)
36    let list = try LaunchFeed.decode(data)
37    let launch = try #require(list.recent?.first)
38    #expect(launch.elements?.first?.OBJECT_NAME == "Starlink train (Group 15-25)")
39    #expect(launch.elementsSource == "gp")
40}