@@ -16,7 +16,6 @@ import AWSPluginsCore
16
16
17
17
// swiftlint:disable cyclomatic_complexity
18
18
// swiftlint:disable type_body_length
19
- // swiftlint:disable file_length
20
19
class DataStoreConsecutiveUpdatesTests : SyncEngineIntegrationTestBase {
21
20
/// - Given: API has been setup with `Post` model registered
22
21
/// - When: A Post is saved and then immediately updated
@@ -58,14 +57,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
58
57
}
59
58
60
59
if mutationEvent. mutationType == GraphQLMutationType . update. rawValue {
61
- // this should be removed once the bug is fixed
62
- // the bug is the update mutation event is being sent to the API with nil version,
63
- // causing a successful response with the existing post data
64
- XCTAssertEqual ( post, newPost)
65
-
66
- // this is the expected behavior which is currently failing
67
- // XCTAssertEqual(post, updatedPost)
68
-
60
+ XCTAssertEqual ( post, updatedPost)
69
61
XCTAssertEqual ( mutationEvent. version, 2 )
70
62
updateSyncReceived. fulfill ( )
71
63
return
@@ -110,13 +102,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
110
102
return
111
103
}
112
104
113
- // this should be removed once the bug is fixed
114
- // the bug is the update mutation event is being sent to the API with nil version,
115
- // causing a successful response with the existing post data
116
- XCTAssertEqual ( queryResultAfterSync, newPost)
117
-
118
- // this is the expected behavior which is currently failing
119
- // XCTAssertEqual(queryResultAfterSync, updatedPost)
105
+ XCTAssertEqual ( queryResultAfterSync, updatedPost)
120
106
121
107
let queryRequest =
122
108
GraphQLRequest< MutationSyncResult?> . query( modelName: updatedPost. modelName, byId: updatedPost. id)
@@ -131,17 +117,9 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
131
117
return
132
118
}
133
119
134
- // this should be removed once the bug is fixed
135
- // the bug is the update mutation event is being sent to the API with nil version,
136
- // causing a successful response with the existing post data
137
- XCTAssertEqual ( post. model [ " title " ] as? String , newPost. title)
138
- XCTAssertEqual ( post. model [ " content " ] as? String , newPost. content)
139
- XCTAssertEqual ( post. model [ " rating " ] as? Double , newPost. rating)
140
-
141
- // this is the expected behavior which is currently failing
142
- // XCTAssertEqual(post.title, updatedPost.title)
143
- // XCTAssertEqual(post.content, updatedPost.content)
144
- // XCTAssertEqual(post.rating, updatedPost.rating)
120
+ XCTAssertEqual ( post. model [ " title " ] as? String , updatedPost. title)
121
+ XCTAssertEqual ( post. model [ " content " ] as? String , updatedPost. content)
122
+ XCTAssertEqual ( post. model [ " rating " ] as? Double , updatedPost. rating)
145
123
XCTAssertEqual ( post. syncMetadata. version, 2 )
146
124
apiQuerySuccess. fulfill ( )
147
125
case . failure( let error) :
@@ -167,11 +145,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
167
145
status: . published)
168
146
169
147
let saveSyncReceived = expectation ( description: " Received create mutation event on subscription for Post " )
170
- // this can be uncommented out once the bug is fixed
171
- // currently the API request for delete mutation is sent with nil version, which
172
- // fails with error message "Conflict resolver rejects mutation."
173
- // because the request failed, subscription does not receive the delete event, and hub event is never fired
174
- // let deleteSyncReceived = expectation(description: "Received delete mutation event on subscription for Post")
148
+ let deleteSyncReceived = expectation ( description: " Received delete mutation event on subscription for Post " )
175
149
176
150
let hubListener = Amplify . Hub. listen (
177
151
to: . dataStore,
@@ -194,8 +168,8 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
194
168
195
169
if mutationEvent. mutationType == GraphQLMutationType . delete. rawValue {
196
170
XCTAssertEqual ( post, newPost)
197
- // can be uncommented once delete mutation response is success
198
- // deleteSyncReceived.fulfill()
171
+ XCTAssertEqual ( mutationEvent . version , 2 )
172
+ deleteSyncReceived. fulfill ( )
199
173
return
200
174
}
201
175
}
@@ -227,19 +201,11 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
227
201
let queryResult = queryPost ( byId: newPost. id)
228
202
XCTAssertNil ( queryResult)
229
203
230
- wait ( for: [ saveSyncReceived] , timeout: networkTimeout)
231
- // can be uncommented once delete mutation response is success
232
- // wait(for: [deleteSyncReceived], timeout: networkTimeout)
204
+ wait ( for: [ saveSyncReceived, deleteSyncReceived] , timeout: networkTimeout)
233
205
234
206
// query the deleted post in eventual consistent state
235
207
let queryResultAfterSync = queryPost ( byId: newPost. id)
236
-
237
- // this should be removed once the bug is fixed, the post should actually be deleted
238
- XCTAssertNotNil ( queryResultAfterSync)
239
- XCTAssertEqual ( queryResultAfterSync, newPost)
240
-
241
- // this is the actual behavior which is currently failing
242
- // XCTAssertNil(post)
208
+ XCTAssertNil ( queryResultAfterSync)
243
209
244
210
let queryRequest =
245
211
GraphQLRequest< MutationSyncResult?> . query( modelName: newPost. modelName, byId: newPost. id)
@@ -257,13 +223,8 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
257
223
XCTAssertEqual ( post. model [ " title " ] as? String , newPost. title)
258
224
XCTAssertEqual ( post. model [ " content " ] as? String , newPost. content)
259
225
XCTAssertEqual ( post. model [ " rating " ] as? Double , newPost. rating)
260
- // the post should actually be deleted, but this is currently failing
261
- XCTAssertFalse ( post. syncMetadata. deleted)
262
-
263
- // can be uncommented once delete mutation response is success
264
- // currently the API request for delete mutation is sent with nil version, which
265
- // fails with error message "Conflict resolver rejects mutation."
266
- // XCTAssertTrue(post.syncMetadata.deleted)
226
+ XCTAssertTrue ( post. syncMetadata. deleted)
227
+ XCTAssertEqual ( post. syncMetadata. version, 2 )
267
228
apiQuerySuccess. fulfill ( )
268
229
case . failure( let error) :
269
230
XCTFail ( " Error: \( error) " )
@@ -333,6 +294,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
333
294
XCTAssertEqual ( post, updatedPost)
334
295
// this needs to be commented out once the bug is fixed
335
296
// deleteSyncReceived.fulfill()
297
+ // XCTAssertEqual(mutationEvent.version, 3)
336
298
return
337
299
}
338
300
}
@@ -415,6 +377,7 @@ class DataStoreConsecutiveUpdatesTests: SyncEngineIntegrationTestBase {
415
377
// currently the API request for delete mutation is sent with version 1, which
416
378
// fails with error message "Conflict resolver rejects mutation."
417
379
// XCTAssertTrue(post.syncMetadata.deleted)
380
+ // XCTAssertEqual(post.syncMetadata.version, 3)
418
381
apiQuerySuccess. fulfill ( )
419
382
case . failure( let error) :
420
383
XCTFail ( " Error: \( error) " )
0 commit comments