@@ -72,9 +72,8 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: XCTestCase {
72
72
/// - When:
73
73
/// - User is not signed in, then user can successfully save a note to local store
74
74
/// - User remains signed out, then user can successfully retrieve the saved note, with empty owner field
75
- /// - User signs in, then the sync engine is started and reconciles local store with the ownerId
76
- /// - User retrieves the note again and now it contains the ownerId
77
- /// - User signs out, the local store is cleared, then retrieving note returns nil
75
+ /// - User signs in, retrieves note, sync engine is started and reconciles local store with the ownerId
76
+ /// - The note now it contains the ownerId
78
77
func testUnauthenticatedSavesToLocalStoreIsReconciledWithCloudStoreAfterAuthentication( ) throws {
79
78
let savedLocalNote = saveNote ( content: " owner saved note " )
80
79
let queriedNoteOptional = queryNote ( byId: savedLocalNote. id)
@@ -84,17 +83,6 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: XCTestCase {
84
83
}
85
84
XCTAssertNil ( note. owner)
86
85
87
- let syncStartedInvoked = expectation ( description: " Sync started after sign In " )
88
- let syncStartedListener = Amplify . Hub. listen (
89
- to: . dataStore,
90
- eventName: HubPayload . EventName. DataStore. syncStarted) { _ in
91
- syncStartedInvoked. fulfill ( )
92
- }
93
- guard try HubListenerTestUtilities . waitForListener ( with: syncStartedListener, timeout: 5.0 ) else {
94
- XCTFail ( " syncStartedListener not registered " )
95
- return
96
- }
97
-
98
86
let syncReceivedInvoked = expectation ( description: " Received SyncReceived event " )
99
87
var remoteNoteOptional : SocialNote ?
100
88
let syncReceivedListener = Amplify . Hub. listen ( to: . dataStore, eventName: syncReceived) { payload in
@@ -115,54 +103,27 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: XCTestCase {
115
103
116
104
signIn ( username: user1. username, password: user1. password)
117
105
118
- wait ( for: [ syncStartedInvoked] , timeout: TestCommonConstants . networkTimeout)
119
106
wait ( for: [ syncReceivedInvoked] , timeout: TestCommonConstants . networkTimeout)
120
- Amplify . Hub. removeListener ( syncStartedListener)
121
107
Amplify . Hub. removeListener ( syncReceivedListener)
122
108
guard let remoteNote = remoteNoteOptional else {
123
109
XCTFail ( " Should have received a SyncReceived event with the remote note reconciled to local store " )
124
110
return
125
111
}
126
112
XCTAssertNotNil ( remoteNote. owner)
127
-
128
- let clearCompletedInvoked = expectation ( description: " received clearCompleted invoked " )
129
- let clearCompletedListener = Amplify . Hub. listen ( to: . dataStore, eventName: clearCompleted) { _ in
130
- clearCompletedInvoked. fulfill ( )
131
- }
132
- guard try HubListenerTestUtilities . waitForListener ( with: clearCompletedListener, timeout: 5.0 ) else {
133
- XCTFail ( " clearCompletedListener not registered " )
134
- return
135
- }
136
-
137
- signOut ( )
138
- wait ( for: [ clearCompletedInvoked] , timeout: TestCommonConstants . networkTimeout)
139
-
140
- let localNoteOptional = queryNote ( byId: savedLocalNote. id)
141
- XCTAssertNil ( localNoteOptional)
142
113
}
143
114
144
- /// A signed in user (the owner) creates some data in local store will be synced to cloud. After signing out ,
115
+ /// A signed in user (the owner) creates some data in local store will be synced to cloud. After `DataStore.clear` ,
145
116
/// the data can no longer be retrieved. Signing back in with another user will update the local store with all
146
117
/// the data that can be read by that the user in the sync process. Then other user can read the owner's data.
147
118
///
148
119
/// - Given: A DataStore plugin configured with auth enabled SocialNote model that can be read others.
149
120
/// - When:
150
- /// - The owner user is signed in, then user can save a note successfully
151
- /// - Owner signs out, then retrieving the note returns nil
121
+ /// - The owner user is signed in, user saves a note, syncReceived successfully
122
+ /// - Owner signs out, `DataStore.clear`, then retrieving the note returns nil
152
123
/// - The other user signs in, sync engine is started and does a full sync
153
124
/// - The other user is able to retrieve the owner's note
154
125
func testOwnerCreatedDataCanBeReadByOtherUsersForReadableModel( ) throws {
155
- let syncStartedInvoked = expectation ( description: " Sync started after sign In " )
156
- let syncStartedListener = Amplify . Hub. listen ( to: . dataStore, eventName: syncStarted) { _ in
157
- syncStartedInvoked. fulfill ( )
158
- }
159
- guard try HubListenerTestUtilities . waitForListener ( with: syncStartedListener, timeout: 5.0 ) else {
160
- XCTFail ( " syncStartedListener not registered " )
161
- return
162
- }
163
126
signIn ( username: user1. username, password: user1. password)
164
- wait ( for: [ syncStartedInvoked] , timeout: TestCommonConstants . networkTimeout)
165
- Amplify . Hub. removeListener ( syncStartedListener)
166
127
167
128
let id = UUID ( ) . uuidString
168
129
let localNote = SocialNote ( id: id, content: " owner created content " , owner: nil )
@@ -207,17 +168,19 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: XCTestCase {
207
168
return
208
169
}
209
170
210
- let clearCompletedInvoked = expectation ( description: " received clearCompleted invoked " )
211
- let clearCompletedListener = Amplify . Hub. listen ( to: . dataStore, eventName: clearCompleted) { _ in
212
- clearCompletedInvoked. fulfill ( )
213
- }
214
- guard try HubListenerTestUtilities . waitForListener ( with: clearCompletedListener, timeout: 5.0 ) else {
215
- XCTFail ( " clearCompletedListener not registered " )
216
- return
217
- }
218
171
signOut ( )
172
+
173
+ let clearCompletedInvoked = expectation ( description: " clear completed " )
174
+ Amplify . DataStore. clear { result in
175
+ switch result {
176
+ case . success:
177
+ clearCompletedInvoked. fulfill ( )
178
+ case . failure( let error) :
179
+ XCTFail ( " Failed to clear \( error) " )
180
+ }
181
+ }
182
+
219
183
wait ( for: [ clearCompletedInvoked] , timeout: TestCommonConstants . networkTimeout)
220
- Amplify . Hub. removeListener ( clearCompletedListener)
221
184
222
185
let localNoteOptional = queryNote ( byId: id)
223
186
XCTAssertNil ( localNoteOptional)
@@ -264,18 +227,5 @@ class AWSDataStoreCategoryPluginAuthIntegrationTests: XCTestCase {
264
227
}
265
228
266
229
XCTAssertEqual ( owner, remoteNoteOwner)
267
-
268
- let clearCompletedInvoked2 = expectation ( description: " received clearCompleted invoked " )
269
- let clearCompletedListener2 = Amplify . Hub. listen ( to: . dataStore, eventName: clearCompleted) { _ in
270
- clearCompletedInvoked2. fulfill ( )
271
- }
272
- guard try HubListenerTestUtilities . waitForListener ( with: clearCompletedListener2, timeout: 5.0 ) else {
273
- XCTFail ( " clearCompletedListener not registered " )
274
- return
275
- }
276
-
277
- signOut ( )
278
- wait ( for: [ clearCompletedInvoked2] , timeout: TestCommonConstants . networkTimeout)
279
- Amplify . Hub. removeListener ( clearCompletedListener2)
280
230
}
281
231
}
0 commit comments