diff --git a/WorkoutsTests/SplitDocumentCodableTests.swift b/WorkoutsTests/SplitDocumentCodableTests.swift new file mode 100644 index 0000000..4a5846e --- /dev/null +++ b/WorkoutsTests/SplitDocumentCodableTests.swift @@ -0,0 +1,45 @@ +import Foundation +import Testing +import IndieSync +@testable import Workouts + +/// Round-trips `SplitDocument` through `DocumentCoder` — the exact JSON codec +/// (ISO-8601 dates, sorted keys, pretty-printed) `DocumentFileStore` uses to +/// write and read every document in this app's iCloud container. +struct SplitDocumentCodableTests { + /// A whole-second epoch so ISO-8601 round-trips (no fractional-second loss). + private static let stableTimestamp = Date(timeIntervalSince1970: 1_700_000_000) + + @Test func encodeDecodeRoundTrip() throws { + let exercise = ExerciseDocument( + id: ULID.make(), + name: "Bench Press", + order: 0, + sets: 4, + reps: 10, + weight: 135, + loadType: 0, + durationSeconds: 0, + weightLastUpdated: Self.stableTimestamp, + weightReminderWeeks: 4 + ) + let original = SplitDocument( + schemaVersion: SplitDocument.currentSchemaVersion, + id: ULID.make(), + name: "Push Day", + color: "blue", + systemImage: "dumbbell.fill", + order: 0, + createdAt: Self.stableTimestamp, + updatedAt: Self.stableTimestamp, + exercises: [exercise], + activityType: nil + ) + + let data = try DocumentCoder.encode(original) + let decoded = try DocumentCoder.decode(SplitDocument.self, from: data) + + #expect(decoded == original) + #expect(decoded.relativePath == "Splits/\(original.id).json") + } +} diff --git a/project.yml b/project.yml index 86a8de4..fcc88da 100644 --- a/project.yml +++ b/project.yml @@ -72,7 +72,23 @@ targets: TARGETED_DEVICE_FAMILY: "1" DEVELOPMENT_ASSET_PATHS: "\"Workouts/Preview Content\"" scheme: - testTargets: [] + testTargets: + - WorkoutsTests + + # ---- unit tests (domain model / codec, against the iOS app target) -------- + WorkoutsTests: + type: bundle.unit-test + platform: iOS + sources: + - WorkoutsTests + dependencies: + - target: Workouts + - package: IndieSync + settings: + base: + PRODUCT_BUNDLE_IDENTIFIER: dev.rzen.indie.WorkoutsTests + GENERATE_INFOPLIST_FILE: true + SWIFT_STRICT_CONCURRENCY: complete # ---- watchOS app (no iCloud; syncs through the phone via WatchConnectivity) - Workouts Watch App: