-
Notifications
You must be signed in to change notification settings - Fork 113
Private tables should always be saved in private db. #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,6 +203,93 @@ | |
| } | ||
| } | ||
|
|
||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||
| @Test func privateTablesStayInPrivateDatabase() async throws { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test failed before the fix because when processing record changes in the private database a failure would be emitted since there were no changes to process. |
||
| let externalZone = CKRecordZone( | ||
| zoneID: CKRecordZone.ID( | ||
| zoneName: "external.zone", | ||
| ownerName: "external.owner" | ||
| ) | ||
| ) | ||
| try await syncEngine.modifyRecordZones(scope: .shared, saving: [externalZone]).notify() | ||
|
|
||
| let remindersListRecord = CKRecord( | ||
| recordType: RemindersList.tableName, | ||
| recordID: RemindersList.recordID(for: 1, zoneID: externalZone.zoneID) | ||
| ) | ||
| remindersListRecord.setValue(1, forKey: "id", at: now) | ||
| remindersListRecord.setValue("Personal", forKey: "title", at: now) | ||
| let share = CKShare( | ||
| rootRecord: remindersListRecord, | ||
| shareID: CKRecord.ID( | ||
| recordName: "share-\(remindersListRecord.recordID.recordName)", | ||
| zoneID: remindersListRecord.recordID.zoneID | ||
| ) | ||
| ) | ||
| _ = try syncEngine.modifyRecords(scope: .shared, saving: [share, remindersListRecord]) | ||
| let freshShare = try syncEngine.shared.database.record(for: share.recordID) as! CKShare | ||
| let freshRemindersListRecord = try syncEngine.shared.database.record( | ||
| for: remindersListRecord.recordID | ||
| ) | ||
|
|
||
| try await syncEngine | ||
| .acceptShare( | ||
| metadata: ShareMetadata( | ||
| containerIdentifier: container.containerIdentifier!, | ||
| hierarchicalRootRecordID: freshRemindersListRecord.recordID, | ||
| rootRecord: freshRemindersListRecord, | ||
| share: freshShare | ||
| ) | ||
| ) | ||
|
|
||
| try await userDatabase.userWrite { db in | ||
| try RemindersListPrivate.insert { | ||
| RemindersListPrivate(remindersListID: 1, position: 42) | ||
| } | ||
| .execute(db) | ||
| } | ||
| try await syncEngine.processPendingRecordZoneChanges(scope: .private) | ||
|
|
||
| assertInlineSnapshot(of: container, as: .customDump) { | ||
| """ | ||
| MockCloudContainer( | ||
| privateCloudDatabase: MockCloudDatabase( | ||
| databaseScope: .private, | ||
| storage: [ | ||
| [0]: CKRecord( | ||
| recordID: CKRecord.ID(1:remindersListPrivates/zone/__defaultOwner__), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that this record is in the private database shows the fix has worked. |
||
| recordType: "remindersListPrivates", | ||
| parent: nil, | ||
| share: nil, | ||
| position: 42, | ||
| remindersListID: 1 | ||
| ) | ||
| ] | ||
| ), | ||
| sharedCloudDatabase: MockCloudDatabase( | ||
| databaseScope: .shared, | ||
| storage: [ | ||
| [0]: CKRecord( | ||
| recordID: CKRecord.ID(share-1:remindersLists/external.zone/external.owner), | ||
| recordType: "cloudkit.share", | ||
| parent: nil, | ||
| share: nil | ||
| ), | ||
| [1]: CKRecord( | ||
| recordID: CKRecord.ID(1:remindersLists/external.zone/external.owner), | ||
| recordType: "remindersLists", | ||
| parent: nil, | ||
| share: CKReference(recordID: CKRecord.ID(share-1:remindersLists/external.zone/external.owner)), | ||
| id: 1, | ||
| title: "Personal" | ||
| ) | ||
| ] | ||
| ) | ||
| ) | ||
| """ | ||
| } | ||
| } | ||
|
|
||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||
| @Test func shareRecordBeforeSync() async throws { | ||
| let error = await #expect(throws: (any Error).self) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main fix. If we are getting parent information for a private table we can make sure the zone is the default zone. We could probably clean this up a bit, I mostly just focused on getting a passing test.