-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathAWSDataStoreLocalStoreTests.swift
More file actions
716 lines (626 loc) · 25.4 KB
/
Copy pathAWSDataStoreLocalStoreTests.swift
File metadata and controls
716 lines (626 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import XCTest
import AmplifyTestCommon
import AWSPluginsCore
@testable import Amplify
@testable import AWSDataStorePlugin
// swfitlint:disable file_length
// swiftlint:disable type_body_length
class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
struct TestModelRegistration: AmplifyModelRegistration {
func registerModels(registry: ModelRegistry.Type) {
registry.register(modelType: Post.self)
registry.register(modelType: Comment.self)
}
let version: String = "1"
}
/// - Given: 4 posts that has been saved
/// - When:
/// - query with grouped predicate
/// - Then:
/// - 2 post instances will be returned
/// - second page returns the remaining 5 posts
/// - the 15 retrieved posts have unique identifiers
func testQueryWithGroupedQueryPredicateInput() async throws {
setUp(withModels: TestModelRegistration())
try await setUpLocalStoreForGroupedPredicateTest()
let post = Post.keys
let predicate = (post.id <= 1 && post.title == "title1")
|| (post.rating > 2 && post.status == PostStatus.private)
let queriedPosts = try await Amplify.DataStore.query(Post.self, where: predicate)
XCTAssertEqual(queriedPosts.count, 2)
}
/// - Given: 15 posts that has been saved
/// - When:
/// - query with pagination input given a page number and limit 10
/// - Then:
/// - first page returns the 10 (the defined limit) of 15 posts
/// - second page returns the remaining 5 posts
/// - the 15 retrieved posts have unique identifiers
func testQueryWithPaginationInput() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 15)
var posts = [Post]()
let queriedPosts = try await Amplify.DataStore.query(Post.self, paginate: .page(0, limit: 10))
XCTAssertEqual(queriedPosts.count, 10)
posts.append(contentsOf: queriedPosts)
let queriedPosts2 = try await Amplify.DataStore.query(Post.self, paginate: .page(1, limit: 10))
XCTAssertEqual(queriedPosts2.count, 5)
posts.append(contentsOf: queriedPosts2)
let idSet = Set(posts.map { $0.id })
XCTAssertEqual(idSet.count, 15)
}
/// - Given: 20 posts that has been saved
/// - When:
/// - attempt to query existing posts that are sorted by rating in ascending order
/// - Then:
/// - the existing data will be returned in expected order
func testQueryWithSortReturnsPostsInAscendingOrder() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 20)
let posts = try await Amplify.DataStore.query(Post.self, sort: .ascending(Post.keys.rating))
XCTAssertEqual(posts.count, 20)
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
}
/// - Given: 50 posts that has been saved
/// - When:
/// - attempt to query existing posts firstly sorted by rating in ascending order and secondly sorted by title in descending order
/// - Then:
/// - the existing data will be returned in expected order
func testQueryWithMultipleSortsReturnsPosts() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 50)
let posts = try await Amplify.DataStore.query(
Post.self,
sort: .by(
.ascending(Post.keys.rating),
.descending(Post.keys.title)
)
)
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
// Group the posts by the first sort field, rating. By using `Dictionary(grouping:by:)`,
// the values in each grouop will be the same order as the original Post array
// See https://developer.apple.com/documentation/swift/dictionary/3127163-init for more details
let postsDic = Dictionary(grouping: posts, by: { $0.rating! })
for (_, pairs) in postsDic {
for index in 0 ..< pairs.count - 1 {
if pairs[index].title < pairs[index + 1].title {
XCTFail("title should be in descending order")
}
}
}
}
/// - Given: 20 posts that has been saved
/// - When:
/// - attempt to query existing posts matching a condition and sorted by rating in ascending order
/// - Then:
/// - the existing data that matches the given condition will be returned in ascending order by rating
func testQueryWithPredicateAndSort() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 20)
let posts = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.rating >= 2,
sort: .ascending(Post.keys.rating)
)
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < 2 {
XCTFail("Predicate is not working as expected")
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
}
/// - Given: 20 posts that has been saved
/// - When:
/// - attempt to query the first 10 existing posts that are sorted by rating in ascending order
/// - Then:
/// - the existing data that matches the given condition will be returned in ascending order by rating
func testQueryWithSortAndPagintate() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 20)
let posts = try await Amplify.DataStore.query(
Post.self,
sort: .by(
.ascending(Post.keys.rating),
.descending(Post.keys.title)
),
paginate: .page(0, limit: 10)
)
XCTAssertEqual(posts.count, 10)
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
}
/// - Given: 50 posts that has been saved
/// - When:
/// - attempt to query the first 10 existing posts that mathches a condition and are sorted by rating in ascending order
/// - Then:
/// - 10 or less existing data that matches the given condition will be returned in ascending order by rating
func testQueryWithPredicateAndSortAndPagintate() async throws {
setUp(withModels: TestModelRegistration())
let localPosts = try await setUpLocalStore(numberOfPosts: 50)
let filteredPosts = localPosts.filter { $0.rating! >= 2.0 }
let count = filteredPosts.count
let posts = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.rating >= 2,
sort: .ascending(Post.keys.rating),
paginate: .page(0, limit: 10)
)
if count >= 10 {
XCTAssertEqual(posts.count, 10)
} else {
XCTAssertEqual(posts.count, count)
}
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < 2 {
XCTFail("Predicate is not working as expected")
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
}
/// - Given: 50 posts that has been saved
/// - When:
/// - attempt to query the every existing posts that mathches a condition and are sorted by rating in ascending order
/// - Then:
/// - the existing data that matches the given condition will be returned in ascending order by rating
func testQueryWithPredicateAndSortWithMultiplePages() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 50)
let queriedPosts = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.rating >= 2
)
var posts = [Post]()
var currentPage: UInt = 0
var shouldRepeat = true
repeat {
let returnPosts = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.rating >= 2,
sort: .ascending(Post.keys.rating),
paginate: .page(currentPage, limit: 10)
)
posts.append(contentsOf: returnPosts)
if returnPosts.count == 10 {
currentPage += 1
} else {
shouldRepeat = false
}
} while shouldRepeat
XCTAssertEqual(posts.count, queriedPosts.count)
var previousRating: Double = 0
for post in posts {
guard let rating = post.rating else {
XCTFail("Rating should not be nil")
return
}
if rating < 2 {
XCTFail("Predicate is not working as expected")
}
if rating < previousRating {
XCTFail("ratings should be in ascending order")
} else {
previousRating = rating
}
}
}
/// DataStore without sync to cloud enabled.
///
/// - Given: DataStore is set up with models, and local store is populated with models
/// - When:
/// - ObserveQuery is called, add more models
/// - Then:
/// - The first snapshot will have initial models and may have additional models
/// - There may be subsequent snapshots based on how the items are batched
/// - The last snapshot will have a total of initial plus additional models
func testObserveQuery() async throws {
setUp(withModels: TestModelRegistration())
try await Amplify.DataStore.clear()
var snapshotCount = 0
let initialQueryComplete = expectation(description: "initial snapshot received")
let allSnapshotsReceived = expectation(description: "query snapshots received")
let subscription = Amplify.DataStore.observeQuery(for: Post.self)
let sink = Amplify.Publisher.create(subscription).sink { completed in
switch completed {
case .finished:
break
case .failure(let error):
XCTFail("\(error)")
}
} receiveValue: { querySnapshot in
snapshotCount += 1
if snapshotCount == 1 {
initialQueryComplete.fulfill()
}
if querySnapshot.items.count == 15 {
allSnapshotsReceived.fulfill()
}
}
await fulfillment(of: [initialQueryComplete], timeout: 10)
_ = try await setUpLocalStore(numberOfPosts: 15)
await fulfillment(of: [allSnapshotsReceived], timeout: 10)
XCTAssertTrue(snapshotCount >= 2)
sink.cancel()
}
func testDeleteModelTypeWithPredicate() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 5)
var posts = try await Amplify.DataStore.query(Post.self, where: Post.keys.status.eq(PostStatus.draft))
XCTAssertFalse(posts.isEmpty)
_ = try await Amplify.DataStore.delete(Post.self, where: Post.keys.status.eq(PostStatus.draft))
posts = try await Amplify.DataStore.query(Post.self, where: Post.keys.status.eq(PostStatus.draft))
XCTAssertEqual(posts.count, 0)
}
func testDeleteAll() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 5)
_ = try await Amplify.DataStore.delete(Post.self, where: QueryPredicateConstant.all)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, 0)
}
/// Given: 5 `Posts` with titles containing 0...4
/// When: Querying `Posts` where title`notContains("1")`
/// Then: 4 posts should be returned, none of which contain `"1"` in the title
func testQueryNotContains() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 5)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, 5)
let postsContaining1InTitle = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.contains("_1_")
)
XCTAssertEqual(postsContaining1InTitle.count, 1)
let postsNotContaining1InTitle = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.notContains("_1_")
)
XCTAssertEqual(
posts.count - postsContaining1InTitle.count,
postsNotContaining1InTitle.count
)
XCTAssertTrue(
postsNotContaining1InTitle.filter(
{ $0.title.contains("_1_") }
).isEmpty
)
}
/// Given: 50 `Posts` with titles containing 0...49
/// When: Querying posts with multiple `notContains(...)` chained with `&&`
/// e.g. `notContains(a) && notContains(b)`
/// Then: Posts returned should not contain either `a` or `b`
func testQueryMultipleNotContains() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 50)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, 50)
let titleValueOne = "25", titleValueTwo = "42"
let postsContaining25or42InTitle = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.contains(titleValueOne)
|| Post.keys.title.contains(titleValueTwo)
)
XCTAssertEqual(postsContaining25or42InTitle.count, 2)
let postsNotContaining25or42InTitle = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.notContains(titleValueOne)
&& Post.keys.title.notContains(titleValueTwo)
)
XCTAssertEqual(
posts.count - postsContaining25or42InTitle.count,
postsNotContaining25or42InTitle.count
)
XCTAssertTrue(
postsNotContaining25or42InTitle.filter(
{ $0.title.contains(titleValueOne) }
).isEmpty
)
XCTAssertTrue(
postsNotContaining25or42InTitle.filter(
{ $0.title.contains(titleValueTwo) }
).isEmpty
)
}
/// Given: 50 saved `Post`s
/// When: Querying for posts with `contains(a)` and `notContains()`
/// where `a` == `<char in 2 posts>` and `b` == `<status of 1 / 2 posts>`
/// Then: The result should contain a single `Post` that contains `a` but doesn't contain `b`
func testQueryNotContainsAndContains() async throws {
let numberOfPosts = 50
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: numberOfPosts)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, numberOfPosts)
let randomTitleNumber = String(Int.random(in: 0 ..< numberOfPosts))
let postWithDuplicateTitleAndDifferentStatus = Post(
title: "title_\(randomTitleNumber)_",
content: "content",
createdAt: .now(),
status: .published
)
_ = try await Amplify.DataStore.save(postWithDuplicateTitleAndDifferentStatus)
let postsContainingRandomTitleNumber = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.contains("_\(randomTitleNumber)_")
)
XCTAssertEqual(postsContainingRandomTitleNumber.count, 2)
XCTAssertEqual(
postsContainingRandomTitleNumber
.lazy
.count(where: { $0.status == .draft }),
1
)
XCTAssertEqual(
postsContainingRandomTitleNumber
.lazy
.count(where: { $0.status == .published }),
1
)
let postsContainingRandomTitleNumberAndNotContainingDraftStatus = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.contains("_\(randomTitleNumber)_")
&& Post.keys.status.notContains(PostStatus.published.rawValue)
)
XCTAssertEqual(
postsContainingRandomTitleNumberAndNotContainingDraftStatus.count,
1
)
XCTAssertEqual(
postsContainingRandomTitleNumberAndNotContainingDraftStatus[0].title,
"title_\(randomTitleNumber)_"
)
XCTAssertNotEqual(
postsContainingRandomTitleNumberAndNotContainingDraftStatus[0].status,
.published
)
}
/// Given: 5 saved `Post`s
/// When: Deleting with `notContains(a)` where `a` is contained in only one post
/// Then: All but one `Post` should be deleted. The `Post` containing `a` should remain.
func testDeleteNotContains() async throws {
setUp(withModels: TestModelRegistration())
_ = try await setUpLocalStore(numberOfPosts: 5)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, 5)
try await Amplify.DataStore.delete(
Post.self,
where: Post.keys.title.notContains("_1_")
)
let postsIncluding1InTitle = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(postsIncluding1InTitle.count, 1)
XCTAssertEqual(postsIncluding1InTitle[0].title, "title_1_")
}
/// Given: 3 saved `Post`s where 2 `Post` titles contain `x` and 1 of those `Post`s content field contain `y`
/// When: Deleting with `notContains(x) || notContains(y)`. Then querying for remaining `Post`s
/// Then: The query should return a single `Post` that does **not** contain `x` in the title but **does** contain `y` in the content.
func testDeleteJoinedOrNotContains() async throws {
setUp(withModels: TestModelRegistration())
func post(title: String, content: String) -> Post {
.init(title: title, content: content, createdAt: .now())
}
let post1 = post(title: "title_1_", content: "a")
let post2 = post(title: "title_1_", content: "b")
let post3 = post(title: "title_3_", content: "c")
_ = try await Amplify.DataStore.save(post1)
_ = try await Amplify.DataStore.save(post2)
_ = try await Amplify.DataStore.save(post3)
let posts = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(posts.count, 3)
try await Amplify.DataStore.delete(
Post.self,
where: Post.keys.title.notContains("_1_")
|| Post.keys.content.notContains("a")
)
let postsAfterDeletingNotContains1andNotContainsA = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(postsAfterDeletingNotContains1andNotContainsA.count, 1)
XCTAssertEqual(postsAfterDeletingNotContains1andNotContainsA[0].content, "a")
}
/// Given: Saved `Post`s containing SQL pattern matching symbols `%` and `_`
/// When: Querying with predicates containing those symbols.
/// Then: The query results should only contain values matching the predicate without
/// treating `%` and `_` as pattern matching symbols.
func testQueryPatternMatchingSymbols() async throws {
setUp(withModels: TestModelRegistration())
let posts = [
Post(
title: "_bc",
content: "",
createdAt: .now()
),
Post(
title: "abc",
content: "",
createdAt: .now()
),
Post(
title: "de%",
content: "",
createdAt: .now()
),
Post(
title: "def",
content: "",
createdAt: .now()
)
]
for post in posts {
try await Amplify.DataStore.save(post)
}
// This should only contain 1 Post with the title "_bc"
// It should not contain the Post with the title "abc"
let postBeginsWithUnderscore = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.beginsWith("_b")
)
XCTAssertEqual(postBeginsWithUnderscore.count, 1)
XCTAssertEqual(postBeginsWithUnderscore[0].title, "_bc")
// This should only contain the Post with the title "de%"
// It should not contain the Post with the title "def"
let postContainingPercent = try await Amplify.DataStore.query(
Post.self,
where: Post.keys.title.contains("%")
)
XCTAssertEqual(postContainingPercent.count, 1)
XCTAssertEqual(postContainingPercent[0].title, "de%")
}
/// Given: Saved `Post`s containing SQL pattern matching symbols `%` and `_`
/// When: Deleting with predicates containing those symbols and subsequently querying
/// for all `Post`s.
/// Then: The query results should only contain values matching the predicate without
/// treating `%` and `_` as pattern matching symbols.
func testDeletePatternMatchingSymbols() async throws {
setUp(withModels: TestModelRegistration())
let posts = [
Post(
title: "_bc",
content: "",
createdAt: .now()
),
Post(
title: "abc",
content: "",
createdAt: .now()
),
Post(
title: "de%",
content: "",
createdAt: .now()
),
Post(
title: "def",
content: "",
createdAt: .now()
)
]
for post in posts {
try await Amplify.DataStore.save(post)
}
// This should only delete 1 Post with the title "_bc"
// It should not delete the Post with the title "abc"
try await Amplify.DataStore.delete(
Post.self,
where: Post.keys.title.beginsWith("_b")
)
let p1 = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(p1.count, 3)
XCTAssertTrue(p1.filter { $0.title == "_bc" }.isEmpty)
try await Amplify.DataStore.delete(
Post.self,
where: Post.keys.title.contains("%")
)
// This should only delete the Post with the title "de%"
// It should not delete the Post with the title "def"
let p2 = try await Amplify.DataStore.query(Post.self)
XCTAssertEqual(p2.count, 2)
XCTAssertTrue(p2.filter { $0.title == "de%" }.isEmpty)
}
func setUpLocalStore(numberOfPosts: Int) async throws -> [Post] {
let posts = (0 ..< numberOfPosts).map {
Post(
title: "title_\($0)_",
content: "content",
createdAt: .now(),
rating: Double(Int.random(in: 0 ... 5)),
status: .draft
)
}
for (index, post) in posts.enumerated() {
print("\(index) \(post.id)")
try await Amplify.DataStore.save(post)
}
return posts
}
func setUpLocalStoreForGroupedPredicateTest() async throws {
var savedPosts = [Post]()
savedPosts.append(Post(
id: "1",
title: "title1",
content: "content1",
createdAt: .now(),
rating: 1,
status: .draft
))
savedPosts.append(Post(
id: "2",
title: "title2",
content: "content2",
createdAt: .now(),
rating: 2,
status: .private
))
savedPosts.append(Post(
id: "3",
title: "title3",
content: "content3",
createdAt: .now(),
rating: 3,
status: .draft
))
savedPosts.append(Post(
id: "4",
title: "title4",
content: "content4",
createdAt: .now(),
rating: 4,
status: .private
))
for post in savedPosts {
_ = try await Amplify.DataStore.save(post)
}
}
}