-
Notifications
You must be signed in to change notification settings - Fork 62
Make SyncEngine more testable #300
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
base: main
Are you sure you want to change the base?
Changes from all commits
12d24fb
e2ef097
726848f
ecc9dc0
e549af8
8875087
032988a
42944ee
2ab4df1
c89ffe8
76b33ea
6b8a041
8ac8f10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,10 @@ import Testing | |
| .dependency(\.continuousClock, ImmediateClock()), | ||
| .dependency(\.date.now, Date(timeIntervalSince1970: 1_234_567_890)), | ||
| .dependency(\.uuid, .incrementing), | ||
| .dependencies { try $0.bootstrapDatabase() }, | ||
| .dependencies { | ||
| try $0.bootstrapDatabase() | ||
| try await $0.defaultSyncEngine.sendChanges() | ||
|
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. Now users of our library can decide to send all changes to "iCloud" after they bootstrap their database (in reality this sends the records to a completely mocked, in-memory version of iCloud). |
||
| }, | ||
| .snapshots(record: .failed) | ||
| ) | ||
| struct BaseTestSuite {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import Dependencies | ||
| import DependenciesTestSupport | ||
| import Foundation | ||
| import InlineSnapshotTesting | ||
| import SnapshotTestingCustomDump | ||
| import Testing | ||
|
|
@@ -8,6 +10,9 @@ import Testing | |
| extension BaseTestSuite { | ||
| @MainActor | ||
| struct RemindersListsTests { | ||
| @Dependency(\.defaultDatabase) var database | ||
| @Dependency(\.defaultSyncEngine) var syncEngine | ||
|
|
||
| @Test func basics() async throws { | ||
| let model = RemindersListsModel() | ||
| try await model.$remindersLists.load() | ||
|
|
@@ -100,5 +105,54 @@ extension BaseTestSuite { | |
| """ | ||
| } | ||
| } | ||
|
|
||
| @Test func share() async throws { | ||
| let model = RemindersListsModel() | ||
|
|
||
| let personalRemindersList = try #require( | ||
| try await database.read { db in | ||
| try RemindersList.find(UUID(0)).fetchOne(db) | ||
| } | ||
| ) | ||
| let _ = try await syncEngine.share(record: personalRemindersList, configure: { _ in }) | ||
|
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. There isn't a ton we can test in our demo when it comes to sharing, but we can at least see that the act of sharing this list does indeed populate the |
||
|
|
||
| try await model.$remindersLists.load() | ||
| assertInlineSnapshot(of: model.remindersLists, as: .customDump) { | ||
| """ | ||
| [ | ||
| [0]: RemindersListsModel.ReminderListState( | ||
| remindersCount: 4, | ||
| remindersList: RemindersList( | ||
| id: UUID(00000000-0000-0000-0000-000000000000), | ||
| color: 1218047999, | ||
| position: 1, | ||
| title: "Personal" | ||
| ), | ||
| share: CKShare() | ||
| ), | ||
| [1]: RemindersListsModel.ReminderListState( | ||
| remindersCount: 2, | ||
| remindersList: RemindersList( | ||
| id: UUID(00000000-0000-0000-0000-000000000001), | ||
| color: 3985191935, | ||
| position: 2, | ||
| title: "Family" | ||
| ), | ||
| share: nil | ||
| ), | ||
| [2]: RemindersListsModel.ReminderListState( | ||
| remindersCount: 2, | ||
| remindersList: RemindersList( | ||
| id: UUID(00000000-0000-0000-0000-000000000002), | ||
| color: 2992493567, | ||
| position: 3, | ||
| title: "Business" | ||
| ), | ||
| share: nil | ||
| ) | ||
| ] | ||
| """ | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
I think it's a bit noisy to get all the SQL queries in tests, so opting out of that for now.