|
| 1 | +#if canImport(CloudKit) |
| 2 | + import CloudKit |
| 3 | + import ConcurrencyExtras |
| 4 | + import CustomDump |
| 5 | + import InlineSnapshotTesting |
| 6 | + import OrderedCollections |
| 7 | + import SQLiteData |
| 8 | + import SQLiteDataTestSupport |
| 9 | + import SnapshotTestingCustomDump |
| 10 | + import Testing |
| 11 | + |
| 12 | + extension BaseCloudKitTests { |
| 13 | + @MainActor |
| 14 | + @Suite(.attachMetadatabase(true)) |
| 15 | + final class AttachedMetadatabaseTests: BaseCloudKitTests, @unchecked Sendable { |
| 16 | + @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
| 17 | + @Test func basics() async throws { |
| 18 | + let remindersList = RemindersList(id: 1, title: "Personal") |
| 19 | + try await userDatabase.userWrite { db in |
| 20 | + try db.seed { |
| 21 | + remindersList |
| 22 | + } |
| 23 | + } |
| 24 | + try await syncEngine.processPendingRecordZoneChanges(scope: .private) |
| 25 | + |
| 26 | + assertQuery( |
| 27 | + RemindersList |
| 28 | + .leftJoin(SyncMetadata.all) { $0.syncMetadataID.eq($1.id) }, |
| 29 | + database: userDatabase.database |
| 30 | + ) { |
| 31 | + """ |
| 32 | + ┌─────────────────────┬────────────────────────────────────────────────────────────────────┐ |
| 33 | + │ RemindersList( │ SyncMetadata( │ |
| 34 | + │ id: 1, │ id: SyncMetadata.ID( │ |
| 35 | + │ title: "Personal" │ recordPrimaryKey: "1", │ |
| 36 | + │ ) │ recordType: "remindersLists" │ |
| 37 | + │ │ ), │ |
| 38 | + │ │ zoneName: "zone", │ |
| 39 | + │ │ ownerName: "__defaultOwner__", │ |
| 40 | + │ │ recordName: "1:remindersLists", │ |
| 41 | + │ │ parentRecordID: nil, │ |
| 42 | + │ │ parentRecordName: nil, │ |
| 43 | + │ │ lastKnownServerRecord: CKRecord( │ |
| 44 | + │ │ recordID: CKRecord.ID(1:remindersLists/zone/__defaultOwner__), │ |
| 45 | + │ │ recordType: "remindersLists", │ |
| 46 | + │ │ parent: nil, │ |
| 47 | + │ │ share: nil │ |
| 48 | + │ │ ), │ |
| 49 | + │ │ _lastKnownServerRecordAllFields: CKRecord( │ |
| 50 | + │ │ recordID: CKRecord.ID(1:remindersLists/zone/__defaultOwner__), │ |
| 51 | + │ │ recordType: "remindersLists", │ |
| 52 | + │ │ parent: nil, │ |
| 53 | + │ │ share: nil, │ |
| 54 | + │ │ id: 1, │ |
| 55 | + │ │ title: "Personal" │ |
| 56 | + │ │ ), │ |
| 57 | + │ │ share: nil, │ |
| 58 | + │ │ _isDeleted: false, │ |
| 59 | + │ │ hasLastKnownServerRecord: true, │ |
| 60 | + │ │ isShared: false, │ |
| 61 | + │ │ userModificationTime: 0 │ |
| 62 | + │ │ ) │ |
| 63 | + └─────────────────────┴────────────────────────────────────────────────────────────────────┘ |
| 64 | + """ |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | +#endif |
0 commit comments