|
4 | 4 | import Foundation
|
5 | 5 | import InlineSnapshotTesting
|
6 | 6 | import SQLiteData
|
| 7 | + import SQLiteDataTestSupport |
7 | 8 | import SnapshotTestingCustomDump
|
8 | 9 | import Testing
|
9 | 10 |
|
|
65 | 66 | }
|
66 | 67 | }
|
67 | 68 |
|
| 69 | + // * CloudKit sends record for table we do not recognize. |
| 70 | + // * CloudKit deletes that record |
| 71 | + // => Local sync metadata should be deleted for that record. |
| 72 | + @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
| 73 | + @Test func cloudKitSendsNonExistentTable() async throws { |
| 74 | + let record = CKRecord( |
| 75 | + recordType: UnrecognizedTable.tableName, |
| 76 | + recordID: UnrecognizedTable.recordID(for: 1) |
| 77 | + ) |
| 78 | + record.setValue(1, forKey: "id", at: now) |
| 79 | + try await syncEngine.modifyRecords(scope: .private, saving: [record]).notify() |
| 80 | + |
| 81 | + assertQuery(SyncMetadata.select(\.recordName), database: syncEngine.metadatabase) { |
| 82 | + """ |
| 83 | + ┌────────────────────────┐ |
| 84 | + │ "1:unrecognizedTables" │ |
| 85 | + └────────────────────────┘ |
| 86 | + """ |
| 87 | + } |
| 88 | + |
| 89 | + try await syncEngine.modifyRecords(scope: .private, deleting: [record.recordID]).notify() |
| 90 | + |
| 91 | + assertQuery(SyncMetadata.select(\.recordName), database: syncEngine.metadatabase) { |
| 92 | + """ |
| 93 | + (No results) |
| 94 | + """ |
| 95 | + } |
| 96 | + assertInlineSnapshot(of: container, as: .customDump) { |
| 97 | + """ |
| 98 | + MockCloudContainer( |
| 99 | + privateCloudDatabase: MockCloudDatabase( |
| 100 | + databaseScope: .private, |
| 101 | + storage: [] |
| 102 | + ), |
| 103 | + sharedCloudDatabase: MockCloudDatabase( |
| 104 | + databaseScope: .shared, |
| 105 | + storage: [] |
| 106 | + ) |
| 107 | + ) |
| 108 | + """ |
| 109 | + } |
| 110 | + } |
| 111 | + |
68 | 112 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
|
69 | 113 | @Test func metadataRowWithNoCorrespondingRecordRow() async throws {
|
70 | 114 | try await userDatabase.userWrite { db in
|
|
223 | 267 | }
|
224 | 268 |
|
225 | 269 | @Table struct UnrecognizedTable {
|
226 |
| - let id: UUID |
| 270 | + let id: Int |
227 | 271 | }
|
228 | 272 | #endif
|
0 commit comments