Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/RemindersTests/Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Testing
try $0.bootstrapDatabase()
try await $0.defaultSyncEngine.sendChanges()
},
.snapshots(record: .failed)
.snapshots(record: .missing)
)
struct BaseTestSuite {}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLiteData/CloudKit/CloudKitSharing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"""
)
}
try await metadatabase.write { db in
try await userDatabase.write { db in
try SyncMetadata
.where { $0.recordName.eq(recordName) }
.update {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLiteData/CloudKit/SyncEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@

private func refreshLastKnownServerRecord(_ record: CKRecord) async {
await withErrorReporting(.sqliteDataCloudKitFailure) {
try await metadatabase.write { db in
try await userDatabase.write { db in
let metadata = try SyncMetadata.find(record.recordID).fetchOne(db)
func updateLastKnownServerRecord() throws {
try SyncMetadata
Expand Down
2 changes: 1 addition & 1 deletion Tests/SQLiteDataTests/AssertQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Testing
@MainActor
@Suite(
.dependency(\.defaultDatabase, try .database()),
.snapshots(record: .failed),
.snapshots(record: .missing),
)
struct AssertQueryTests {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
Expand Down
66 changes: 66 additions & 0 deletions Tests/SQLiteDataTests/CloudKitTests/MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,72 @@
"""
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.attachMetadatabase(true))
func observation() async throws {
let remindersList = RemindersList(id: 1, title: "Personal")
try await userDatabase.userWrite { db in
try db.seed { remindersList }
}
try await syncEngine.processPendingRecordZoneChanges(scope: .private)

@FetchAll(
SyncMetadata
.select {
RecordNameAndIsShared.Columns(
recordName: $0.recordName,
isShared: $0.share.isNot(nil)
)
},
database: userDatabase.database
)
var rows
try await $rows.load()
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: false)])

_ = try await syncEngine.share(record: remindersList) { _ in }

try await Task.sleep(for: .seconds(0.5))
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails without these changes.

}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.attachMetadatabase(true))
func observation_GeneratedColumn() async throws {
let remindersList = RemindersList(id: 1, title: "Personal")
try await userDatabase.userWrite { db in
try db.seed { remindersList }
}
try await syncEngine.processPendingRecordZoneChanges(scope: .private)

@FetchAll(
SyncMetadata
.select {
RecordNameAndIsShared.Columns(
recordName: $0.recordName,
isShared: $0.isShared
)
},
database: userDatabase.database
)
var rows
try await $rows.load()
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: false)])

_ = try await syncEngine.share(record: remindersList) { _ in }

try await Task.sleep(for: .seconds(0.5))
withKnownIssue("Query observation does not work with generated columns right now") {
#expect(rows == [RecordNameAndIsShared(recordName: "1:remindersLists", isShared: true)])
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation of generated columns does not currently work.

}
}
}


@Selection struct RecordNameAndIsShared: Equatable {
let recordName: String
let isShared: Bool
}
#endif