crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

PerGameZoneTests.swift (2213B)


      1 import CloudKit
      2 import Foundation
      3 import Testing
      4 
      5 @testable import Crossmate
      6 
      7 @Suite("PerGameZone")
      8 struct PerGameZoneTests {
      9 
     10     @Test("zoneID uses game UUID as zone name")
     11     func zoneIDZoneName() {
     12         let id = UUID(uuidString: "12345678-1234-1234-1234-123456789ABC")!
     13         let zone = RecordSerializer.zoneID(for: id)
     14         #expect(zone.zoneName == "game-12345678-1234-1234-1234-123456789ABC")
     15     }
     16 
     17     @Test("zoneID defaults to CKCurrentUserDefaultName for owner")
     18     func zoneIDDefaultOwner() {
     19         let id = UUID()
     20         let zone = RecordSerializer.zoneID(for: id)
     21         #expect(zone.ownerName == CKCurrentUserDefaultName)
     22     }
     23 
     24     @Test("zoneID accepts explicit ownerName for shared games")
     25     func zoneIDExplicitOwner() {
     26         let id = UUID()
     27         let zone = RecordSerializer.zoneID(for: id, ownerName: "_someOwnerID")
     28         #expect(zone.ownerName == "_someOwnerID")
     29     }
     30 
     31     @Test("recordName(forGameID:) embedded in zoneID zoneName")
     32     func gameRecordNameMatchesZoneName() {
     33         let id = UUID()
     34         let zoneName = RecordSerializer.zoneID(for: id).zoneName
     35         let recordName = RecordSerializer.recordName(forGameID: id)
     36         #expect(zoneName == recordName)
     37     }
     38 
     39     @Test("zoneInfo reports unconfirmed local game zones")
     40     @MainActor
     41     func zoneInfoReportsCloudConfirmation() {
     42         let persistence = makeTestPersistence()
     43         let ctx = persistence.viewContext
     44         let id = UUID()
     45         let zoneName = "game-\(id.uuidString)"
     46         let entity = GameEntity(context: ctx)
     47         entity.id = id
     48         entity.title = "Local"
     49         entity.createdAt = Date()
     50         entity.updatedAt = Date()
     51         entity.ckRecordName = zoneName
     52         entity.ckZoneName = zoneName
     53         entity.databaseScope = 0
     54         try? ctx.save()
     55 
     56         let engine = SyncEngine(
     57             container: CKContainer(identifier: "iCloud.net.inqk.crossmate.v3"),
     58             persistence: persistence
     59         )
     60         #expect(engine.zoneInfo(forGameID: id, in: ctx)?.isCloudConfirmed == false)
     61 
     62         entity.ckSystemFields = Data([0x01])
     63         try? ctx.save()
     64         #expect(engine.zoneInfo(forGameID: id, in: ctx)?.isCloudConfirmed == true)
     65     }
     66 }