Skip to content

Commit f648f41

Browse files
author
Di Wu
authored
test(datastore): fix contains and notContains with random number test cases (#2829)
1 parent 3869ec5 commit f648f41

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/AWSDataStoreLocalStoreTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
345345

346346
let postsContaining1InTitle = try await Amplify.DataStore.query(
347347
Post.self,
348-
where: Post.keys.title.contains("1")
348+
where: Post.keys.title.contains("_1_")
349349
)
350350
XCTAssertEqual(postsContaining1InTitle.count, 1)
351351

352352
let postsNotContaining1InTitle = try await Amplify.DataStore.query(
353353
Post.self,
354-
where: Post.keys.title.notContains("1")
354+
where: Post.keys.title.notContains("_1_")
355355
)
356356
XCTAssertEqual(
357357
posts.count - postsContaining1InTitle.count,
@@ -360,7 +360,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
360360

361361
XCTAssertTrue(
362362
postsNotContaining1InTitle.filter(
363-
{ $0.title.contains("1") }
363+
{ $0.title.contains("_1_") }
364364
).isEmpty
365365
)
366366
}
@@ -423,7 +423,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
423423
let randomTitleNumber = String(Int.random(in: 0..<numberOfPosts))
424424

425425
let postWithDuplicateTitleAndDifferentStatus = Post(
426-
title: "title_\(randomTitleNumber)",
426+
title: "title_\(randomTitleNumber)_",
427427
content: "content",
428428
createdAt: .now(),
429429
status: .published
@@ -433,7 +433,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
433433

434434
let postsContainingRandomTitleNumber = try await Amplify.DataStore.query(
435435
Post.self,
436-
where: Post.keys.title.contains(randomTitleNumber)
436+
where: Post.keys.title.contains("_\(randomTitleNumber)_")
437437
)
438438

439439
XCTAssertEqual(postsContainingRandomTitleNumber.count, 2)
@@ -455,7 +455,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
455455

456456
let postsContainingRandomTitleNumberAndNotContainingDraftStatus = try await Amplify.DataStore.query(
457457
Post.self,
458-
where: Post.keys.title.contains(randomTitleNumber)
458+
where: Post.keys.title.contains("_\(randomTitleNumber)_")
459459
&& Post.keys.status.notContains(PostStatus.published.rawValue)
460460
)
461461

@@ -466,7 +466,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
466466

467467
XCTAssertEqual(
468468
postsContainingRandomTitleNumberAndNotContainingDraftStatus[0].title,
469-
"title_\(randomTitleNumber)"
469+
"title_\(randomTitleNumber)_"
470470
)
471471

472472
XCTAssertNotEqual(
@@ -486,12 +486,12 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
486486

487487
try await Amplify.DataStore.delete(
488488
Post.self,
489-
where: Post.keys.title.notContains("1")
489+
where: Post.keys.title.notContains("_1_")
490490
)
491491

492492
let postsIncluding1InTitle = try await Amplify.DataStore.query(Post.self)
493493
XCTAssertEqual(postsIncluding1InTitle.count, 1)
494-
XCTAssertEqual(postsIncluding1InTitle[0].title, "title_1")
494+
XCTAssertEqual(postsIncluding1InTitle[0].title, "title_1_")
495495
}
496496

497497

@@ -505,9 +505,9 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
505505
.init(title: title, content: content, createdAt: .now())
506506
}
507507

508-
let post1 = post(title: "title_1", content: "a")
509-
let post2 = post(title: "title_1", content: "b")
510-
let post3 = post(title: "title_3", content: "c")
508+
let post1 = post(title: "title_1_", content: "a")
509+
let post2 = post(title: "title_1_", content: "b")
510+
let post3 = post(title: "title_3_", content: "c")
511511

512512
_ = try await Amplify.DataStore.save(post1)
513513
_ = try await Amplify.DataStore.save(post2)
@@ -518,7 +518,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
518518

519519
try await Amplify.DataStore.delete(
520520
Post.self,
521-
where: Post.keys.title.notContains("1")
521+
where: Post.keys.title.notContains("_1_")
522522
|| Post.keys.content.notContains("a")
523523
)
524524

@@ -645,7 +645,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
645645
func setUpLocalStore(numberOfPosts: Int) async throws -> [Post] {
646646
let posts = (0..<numberOfPosts).map {
647647
Post(
648-
title: "title_\($0)",
648+
title: "title_\($0)_",
649649
content: "content",
650650
createdAt: .now(),
651651
rating: Double(Int.random(in: 0 ... 5)),

AmplifyPlugins/DataStore/Tests/DataStoreHostApp/DataStoreHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)