field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraViewerCalendarTests.swift (2751B)


      1 import Foundation
      2 @testable import TeraApp
      3 import TeraKitBindings
      4 import XCTest
      5 
      6 final class TeraViewerCalendarTests: XCTestCase {
      7   func testGeneratedPageRetainsExactContextAndRejectsUnsupportedReaders() throws {
      8     let context = FfiViewerCalendarContext(
      9       schemaVersion: 1, asOfUnixS: 1_788_569_400, timeZone: "America/Vancouver",
     10       civilDate: FfiCivilDate(year: 2026, month: 9, day: 4)
     11     )
     12     let page = FfiTodayPageRecord(
     13       calendar: context, projectionGeneration: 9, schemaVersion: 2,
     14       asOfUnixS: context.asOfUnixS, items: [], nextCursor: "opaque"
     15     )
     16     let restored = try FfiConverterTypeFfiTodayPageRecord_lift(FfiConverterTypeFfiTodayPageRecord_lower(page))
     17     XCTAssertEqual(restored, page)
     18     let native = try restored.appValue()
     19     XCTAssertEqual(native.calendar.civilDate.canonical, "2026-09-04")
     20     XCTAssertEqual(native.calendar.timeZoneID, "America/Vancouver")
     21     for index in 0 ..< 7 {
     22       var invalid = page
     23       switch index {
     24       case 0: invalid.schemaVersion = 1
     25       case 1: invalid.calendar.schemaVersion = 2
     26       case 2: invalid.calendar.timeZone = "Invalid/Zone"
     27       case 3: invalid.calendar.civilDate.day = 32
     28       case 4: invalid.asOfUnixS += 1
     29       case 5: invalid.calendar.asOfUnixS = .max
     30       default: invalid.calendar.asOfUnixS = 0
     31       }
     32       XCTAssertThrowsError(try invalid.appValue())
     33     }
     34   }
     35 
     36   func testInstalledRuntimeDerivesLocalDateAndRejectsOldCursor() async throws {
     37     let fixture = try MediaOwnershipFixture()
     38     defer { fixture.remove() }
     39     let runtime = try await fixture.runtime()
     40     let context = FfiLocalNetworkRecord(
     41       schemaVersion: 1, id: "nearby", label: "Nearby", relayUrls: ["wss://relay.example"],
     42       locality: nil, followedAuthors: [], generation: 1
     43     )
     44     let page = try await runtime.phase1TodayPage(
     45       context: context, limit: 20, asOfUnixS: 1_788_569_400, cursor: nil,
     46       viewerTimeZone: "America/Vancouver"
     47     )
     48     XCTAssertEqual(try page.appValue().calendar.civilDate.canonical, "2026-09-04")
     49     let current = try await runtime.phase1TodayReconcile(
     50       context: context, asOfUnixS: page.asOfUnixS, cardIds: [],
     51       expectedGeneration: page.projectionGeneration, viewerTimeZone: page.calendar.timeZone
     52     )
     53     XCTAssertEqual(current.calendar, page.calendar)
     54     do {
     55       _ = try await runtime.phase1TodayPage(
     56         context: context, limit: 20, asOfUnixS: nil, cursor: "rrtc2:00", viewerTimeZone: nil
     57       )
     58       XCTFail("An incompatible cursor requires an explicit fresh read")
     59     } catch let TeraAppError.Failure(report) {
     60       XCTAssertEqual(report.code, "today_cursor_invalid")
     61       XCTAssertEqual(report.recoveryActions, ["restart_pagination"])
     62     }
     63     _ = try await runtime.shutdown()
     64   }
     65 }