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/LiveEventTests.swift

04b2b1d914788057bcd20945b876847386eb8f65
moonrise/Packages/MoonriseKit/Tests/FeedsTests/LiveEventTests.swift history · blame · raw

26 lines · 1329 bytes

2 symbols in this file
 1import Foundation
 2import Testing
 3@testable import Feeds
 4
 5@Test func decodesLiveCoverage() throws {
 6    let json = Data("""
 7    {"event":{"id":"artemis-1","title":"Artemis I","horizonsId":"-1023","launch":"2022-11-16T06:47:44Z","end":"2022-12-11T17:40:00Z",
 8      "phases":[{"at":"2022-11-16T06:47:44Z","label":"Launch"},{"at":"2022-11-21T12:44:00Z","label":"Outbound lunar flyby"}]},
 9     "at":"2022-11-21T12:00:00.000Z","points":[[1668588420,-3171.3,10537.8,1526.1],[1669031220,300000,200000,10000]]}
10    """.utf8)
11    let c = try #require(try LiveCoverage.decode(json))
12    #expect(c.event.title == "Artemis I")
13    #expect(c.points.count == 2)
14    #expect(c.phase.current?.label == "Launch")
15    #expect(c.phase.next?.label == "Outbound lunar flyby")
16    #expect(abs(c.distanceKm! - (300000.0 * 300000 + 200000 * 200000 + 10000 * 10000).squareRoot()) < 1e-6)
17    #expect(try LiveCoverage.decode(Data(#"{"event":null}"#.utf8)) == nil)
18}
19
20@Test func decodesLiveArtemisReplay() throws {
21    // GET /v1/live?at=2022-11-21T13:00:00Z, saved 2026-10-18.
22    let url = try #require(Bundle.module.url(forResource: "Fixtures/live-artemis1", withExtension: "json"))
23    let c = try #require(try LiveCoverage.decode(Data(contentsOf: url)))
24    #expect(c.points.count > 200)
25    #expect(c.phase.current?.label == "Outbound lunar flyby")
26}