Skip to content

Commit d0b5b16

Browse files
author
Di Wu
authored
test(datastore): fix lazy load integration test helper method (#3037)
1 parent c716f73 commit d0b5b16

21 files changed

+419
-400
lines changed

AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginLazyLoadTests/LL1/AWSDataStoreLazyLoadPostComment4V2Tests.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
2323
func testSavePost() async throws {
2424
await setup(withModels: PostComment4V2Models())
2525
let post = Post(title: "title")
26-
try await saveAndWaitForSync(post)
26+
try await createAndWaitForSync(post)
2727
}
2828

2929
func testSaveComment() async throws {
3030
await setup(withModels: PostComment4V2Models())
3131

3232
let post = Post(title: "title")
3333
let comment = Comment(content: "content", post: post)
34-
try await saveAndWaitForSync(post)
35-
try await saveAndWaitForSync(comment)
34+
try await createAndWaitForSync(post)
35+
try await createAndWaitForSync(comment)
3636
}
3737

3838
func testLazyLoad() async throws {
3939
await setup(withModels: PostComment4V2Models())
4040

4141
let post = Post(title: "title")
4242
let comment = Comment(content: "content", post: post)
43-
let savedPost = try await saveAndWaitForSync(post)
44-
let savedComment = try await saveAndWaitForSync(comment)
43+
let savedPost = try await createAndWaitForSync(post)
44+
let savedComment = try await createAndWaitForSync(comment)
4545
try await assertComment(savedComment, canLazyLoad: savedPost)
4646
try await assertPost(savedPost, canLazyLoad: savedComment)
4747
let queriedComment = try await query(for: savedComment)
@@ -55,8 +55,8 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
5555

5656
let post = Post(title: "title")
5757
let comment = Comment(content: "content", post: post)
58-
let savedPost = try await saveAndWaitForSync(post)
59-
let savedComment = try await saveAndWaitForSync(comment)
58+
let savedPost = try await createAndWaitForSync(post)
59+
let savedComment = try await createAndWaitForSync(comment)
6060

6161
guard let encodedComment = try? savedComment.toJSON() else {
6262
XCTFail("Could not encode comment")
@@ -79,8 +79,8 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
7979

8080
let post = Post(title: "title")
8181
let comment = Comment(content: "content", post: post)
82-
let savedPost = try await saveAndWaitForSync(post)
83-
let savedComment = try await saveAndWaitForSync(comment)
82+
let savedPost = try await createAndWaitForSync(post)
83+
let savedComment = try await createAndWaitForSync(comment)
8484
let queriedComment = try await query(for: savedComment)
8585

8686
guard let encodedComment = try? queriedComment.toJSON() else {
@@ -152,14 +152,14 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
152152
func testSaveWithoutPost() async throws {
153153
await setup(withModels: PostComment4V2Models())
154154
let comment = Comment(content: "content")
155-
let savedComment = try await saveAndWaitForSync(comment)
155+
let savedComment = try await createAndWaitForSync(comment)
156156
var queriedComment = try await query(for: savedComment)
157157
assertLazyReference(queriedComment._post,
158158
state: .notLoaded(identifiers: nil))
159159
let post = Post(title: "title")
160-
let savedPost = try await saveAndWaitForSync(post)
160+
let savedPost = try await createAndWaitForSync(post)
161161
queriedComment.setPost(savedPost)
162-
let saveCommentWithPost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
162+
let saveCommentWithPost = try await updateAndWaitForSync(queriedComment)
163163
let queriedComment2 = try await query(for: saveCommentWithPost)
164164
try await assertComment(queriedComment2, canLazyLoad: post)
165165
}
@@ -168,12 +168,12 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
168168
await setup(withModels: PostComment4V2Models())
169169
let post = Post(title: "title")
170170
let comment = Comment(content: "content", post: post)
171-
let savedPost = try await saveAndWaitForSync(post)
172-
let savedComment = try await saveAndWaitForSync(comment)
171+
let savedPost = try await createAndWaitForSync(post)
172+
let savedComment = try await createAndWaitForSync(comment)
173173
let queriedComment = try await query(for: savedComment)
174174
assertLazyReference(queriedComment._post,
175175
state: .notLoaded(identifiers: [.init(name: "id", value: post.identifier)]))
176-
let savedQueriedComment = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
176+
let savedQueriedComment = try await updateAndWaitForSync(queriedComment)
177177
let queriedComment2 = try await query(for: savedQueriedComment)
178178
try await assertComment(queriedComment2, canLazyLoad: savedPost)
179179
}
@@ -183,16 +183,16 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
183183

184184
let post = Post(title: "title")
185185
let comment = Comment(content: "content", post: post)
186-
_ = try await saveAndWaitForSync(post)
187-
let savedComment = try await saveAndWaitForSync(comment)
186+
_ = try await createAndWaitForSync(post)
187+
let savedComment = try await createAndWaitForSync(comment)
188188
var queriedComment = try await query(for: savedComment)
189189
assertLazyReference(queriedComment._post,
190190
state: .notLoaded(identifiers: [.init(name: "id", value: post.identifier)]))
191191

192192
let newPost = Post(title: "title")
193-
_ = try await saveAndWaitForSync(newPost)
193+
_ = try await createAndWaitForSync(newPost)
194194
queriedComment.setPost(newPost)
195-
let saveCommentWithNewPost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
195+
let saveCommentWithNewPost = try await updateAndWaitForSync(queriedComment)
196196
let queriedComment2 = try await query(for: saveCommentWithNewPost)
197197
try await assertComment(queriedComment2, canLazyLoad: newPost)
198198
}
@@ -202,14 +202,14 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
202202

203203
let post = Post(title: "title")
204204
let comment = Comment(content: "content", post: post)
205-
_ = try await saveAndWaitForSync(post)
206-
let savedComment = try await saveAndWaitForSync(comment)
205+
_ = try await createAndWaitForSync(post)
206+
let savedComment = try await createAndWaitForSync(comment)
207207
var queriedComment = try await query(for: savedComment)
208208
assertLazyReference(queriedComment._post,
209209
state: .notLoaded(identifiers: [.init(name: "id", value: post.identifier)]))
210210

211211
queriedComment.setPost(nil)
212-
let saveCommentRemovePost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
212+
let saveCommentRemovePost = try await updateAndWaitForSync(queriedComment)
213213
let queriedCommentNoPost = try await query(for: saveCommentRemovePost)
214214
assertLazyReference(queriedCommentNoPost._post,
215215
state: .notLoaded(identifiers: nil))
@@ -220,8 +220,8 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
220220

221221
let post = Post(title: "title")
222222
let comment = Comment(content: "content", post: post)
223-
let savedPost = try await saveAndWaitForSync(post)
224-
let savedComment = try await saveAndWaitForSync(comment)
223+
let savedPost = try await createAndWaitForSync(post)
224+
let savedComment = try await createAndWaitForSync(comment)
225225
try await deleteAndWaitForSync(savedPost)
226226
try await assertModelDoesNotExist(savedComment)
227227
try await assertModelDoesNotExist(savedPost)
@@ -241,7 +241,7 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
241241
let receivedPost = try? mutationEvent.decodeModel(as: Post.self),
242242
receivedPost.id == post.id {
243243

244-
try await saveAndWaitForSync(comment)
244+
try await createAndWaitForSync(comment)
245245

246246
guard let comments = receivedPost.comments else {
247247
XCTFail("Lazy List does not exist")
@@ -274,7 +274,7 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
274274
await setup(withModels: PostComment4V2Models())
275275
try await startAndWaitForReady()
276276
let post = Post(title: "title")
277-
let savedPost = try await saveAndWaitForSync(post)
277+
let savedPost = try await createAndWaitForSync(post)
278278
let comment = Comment(content: "content", post: post)
279279
let mutationEventReceived = asyncExpectation(description: "Received mutation event")
280280
let mutationEvents = Amplify.DataStore.observe(Comment.self)
@@ -311,7 +311,7 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
311311
Task {
312312
for try await querySnapshot in querySnapshots {
313313
if let receivedPost = querySnapshot.items.first {
314-
try await saveAndWaitForSync(comment)
314+
try await createAndWaitForSync(comment)
315315
guard let comments = receivedPost.comments else {
316316
XCTFail("Lazy List does not exist")
317317
return
@@ -344,7 +344,7 @@ class AWSDataStoreLazyLoadPostComment4V2Tests: AWSDataStoreLazyLoadBaseTest {
344344
try await startAndWaitForReady()
345345

346346
let post = Post(title: "title")
347-
let savedPost = try await saveAndWaitForSync(post)
347+
let savedPost = try await createAndWaitForSync(post)
348348
let comment = Comment(content: "content", post: post)
349349
let snapshotReceived = asyncExpectation(description: "Received query snapshot")
350350
let querySnapshots = Amplify.DataStore.observeQuery(for: Comment.self, where: Comment.keys.id == comment.id)

AmplifyPlugins/DataStore/Tests/DataStoreHostApp/AWSDataStorePluginLazyLoadTests/LL10/AWSDataStoreLazyLoadPostComment7Tests.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
1717
func testSavePost() async throws {
1818
await setup(withModels: PostComment7Models())
1919
let post = Post(postId: UUID().uuidString, title: "title")
20-
try await saveAndWaitForSync(post)
20+
try await createAndWaitForSync(post)
2121
}
2222

2323
func testSaveComment() async throws {
2424
await setup(withModels: PostComment7Models())
2525
try await startAndWaitForReady()
2626
let post = Post(postId: UUID().uuidString, title: "title")
2727
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
28-
let savedPost = try await saveAndWaitForSync(post)
29-
let savedComment = try await saveAndWaitForSync(comment)
28+
let savedPost = try await createAndWaitForSync(post)
29+
let savedComment = try await createAndWaitForSync(comment)
3030
}
3131

3232
func testLazyLoad() async throws {
3333
await setup(withModels: PostComment7Models())
3434

3535
let post = Post(postId: UUID().uuidString, title: "title")
3636
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
37-
let savedPost = try await saveAndWaitForSync(post)
38-
let savedComment = try await saveAndWaitForSync(comment)
37+
let savedPost = try await createAndWaitForSync(post)
38+
let savedComment = try await createAndWaitForSync(comment)
3939
try await assertComment(savedComment, canLazyLoad: savedPost)
4040
try await assertPost(savedPost, canLazyLoad: savedComment)
4141
let queriedComment = try await query(for: savedComment)
@@ -106,14 +106,14 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
106106
func testSaveWithoutPost() async throws {
107107
await setup(withModels: PostComment7Models())
108108
let comment = Comment(commentId: UUID().uuidString, content: "content")
109-
let savedComment = try await saveAndWaitForSync(comment)
109+
let savedComment = try await createAndWaitForSync(comment)
110110
var queriedComment = try await query(for: savedComment)
111111
assertLazyReference(queriedComment._post,
112112
state: .notLoaded(identifiers: nil))
113113
let post = Post(postId: UUID().uuidString, title: "title")
114-
let savedPost = try await saveAndWaitForSync(post)
114+
let savedPost = try await createAndWaitForSync(post)
115115
queriedComment.setPost(savedPost)
116-
let saveCommentWithPost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
116+
let saveCommentWithPost = try await updateAndWaitForSync(queriedComment)
117117
let queriedComment2 = try await query(for: saveCommentWithPost)
118118
try await assertComment(queriedComment2, canLazyLoad: post)
119119
}
@@ -122,15 +122,15 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
122122
await setup(withModels: PostComment7Models())
123123
let post = Post(postId: UUID().uuidString, title: "title")
124124
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
125-
let savedPost = try await saveAndWaitForSync(post)
126-
let savedComment = try await saveAndWaitForSync(comment)
125+
let savedPost = try await createAndWaitForSync(post)
126+
let savedComment = try await createAndWaitForSync(comment)
127127
let queriedComment = try await query(for: savedComment)
128128
assertLazyReference(queriedComment._post,
129129
state: .notLoaded(identifiers: [
130130
.init(name: Post.keys.postId.stringValue, value: post.postId),
131131
.init(name: Post.keys.title.stringValue, value: post.title)
132132
]))
133-
let savedQueriedComment = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
133+
let savedQueriedComment = try await updateAndWaitForSync(queriedComment)
134134
let queriedComment2 = try await query(for: savedQueriedComment)
135135
try await assertComment(queriedComment2, canLazyLoad: savedPost)
136136
}
@@ -140,8 +140,8 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
140140

141141
let post = Post(postId: UUID().uuidString, title: "title")
142142
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
143-
_ = try await saveAndWaitForSync(post)
144-
let savedComment = try await saveAndWaitForSync(comment)
143+
_ = try await createAndWaitForSync(post)
144+
let savedComment = try await createAndWaitForSync(comment)
145145
var queriedComment = try await query(for: savedComment)
146146
assertLazyReference(queriedComment._post,
147147
state: .notLoaded(identifiers: [
@@ -150,9 +150,9 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
150150
]))
151151

152152
let newPost = Post(postId: UUID().uuidString, title: "title")
153-
_ = try await saveAndWaitForSync(newPost)
153+
_ = try await createAndWaitForSync(newPost)
154154
queriedComment.setPost(newPost)
155-
let saveCommentWithNewPost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
155+
let saveCommentWithNewPost = try await updateAndWaitForSync(queriedComment)
156156
let queriedComment2 = try await query(for: saveCommentWithNewPost)
157157
try await assertComment(queriedComment2, canLazyLoad: newPost)
158158
}
@@ -162,8 +162,8 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
162162

163163
let post = Post(postId: UUID().uuidString, title: "title")
164164
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
165-
_ = try await saveAndWaitForSync(post)
166-
let savedComment = try await saveAndWaitForSync(comment)
165+
_ = try await createAndWaitForSync(post)
166+
let savedComment = try await createAndWaitForSync(comment)
167167
var queriedComment = try await query(for: savedComment)
168168
assertLazyReference(queriedComment._post,
169169
state: .notLoaded(identifiers: [
@@ -172,7 +172,7 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
172172
]))
173173

174174
queriedComment.setPost(nil)
175-
let saveCommentRemovePost = try await saveAndWaitForSync(queriedComment, assertVersion: 2)
175+
let saveCommentRemovePost = try await updateAndWaitForSync(queriedComment)
176176
let queriedCommentNoPost = try await query(for: saveCommentRemovePost)
177177
assertLazyReference(queriedCommentNoPost._post,
178178
state: .notLoaded(identifiers: nil))
@@ -183,8 +183,8 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
183183

184184
let post = Post(postId: UUID().uuidString, title: "title")
185185
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
186-
let savedPost = try await saveAndWaitForSync(post)
187-
let savedComment = try await saveAndWaitForSync(comment)
186+
let savedPost = try await createAndWaitForSync(post)
187+
let savedComment = try await createAndWaitForSync(comment)
188188
try await deleteAndWaitForSync(savedPost)
189189
try await assertModelDoesNotExist(savedComment)
190190
try await assertModelDoesNotExist(savedPost)
@@ -204,7 +204,7 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
204204
let receivedPost = try? mutationEvent.decodeModel(as: Post.self),
205205
receivedPost.postId == post.postId {
206206

207-
try await saveAndWaitForSync(comment)
207+
try await createAndWaitForSync(comment)
208208
guard let comments = receivedPost.comments else {
209209
XCTFail("Lazy List does not exist")
210210
return
@@ -236,7 +236,7 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
236236
await setup(withModels: PostComment7Models())
237237
try await startAndWaitForReady()
238238
let post = Post(postId: UUID().uuidString, title: "title")
239-
let savedPost = try await saveAndWaitForSync(post)
239+
let savedPost = try await createAndWaitForSync(post)
240240
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
241241
let mutationEventReceived = asyncExpectation(description: "Received mutation event")
242242
let mutationEvents = Amplify.DataStore.observe(Comment.self)
@@ -273,7 +273,7 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
273273
Task {
274274
for try await querySnapshot in querySnapshots {
275275
if let receivedPost = querySnapshot.items.first {
276-
try await saveAndWaitForSync(comment)
276+
try await createAndWaitForSync(comment)
277277
guard let comments = receivedPost.comments else {
278278
XCTFail("Lazy List does not exist")
279279
return
@@ -306,7 +306,7 @@ final class AWSDataStoreLazyLoadPostComment7Tests: AWSDataStoreLazyLoadBaseTest
306306
try await startAndWaitForReady()
307307

308308
let post = Post(postId: UUID().uuidString, title: "title")
309-
let savedPost = try await saveAndWaitForSync(post)
309+
let savedPost = try await createAndWaitForSync(post)
310310
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
311311
let snapshotReceived = asyncExpectation(description: "Received query snapshot")
312312
let querySnapshots = Amplify.DataStore.observeQuery(for: Comment.self, where: Comment.keys.commentId == comment.commentId)

0 commit comments

Comments
 (0)