@@ -110,7 +110,7 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
110
110
sink. cancel ( )
111
111
}
112
112
113
- /// Apply a query predicate "title begins with 'xyz' "
113
+ /// Apply a query predicate "title begins with same random UUID "
114
114
///
115
115
/// - Given: DataStore is set up with an empty local store
116
116
/// - When:
@@ -119,18 +119,34 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
119
119
/// - The models only contain models based on the predicate
120
120
///
121
121
func testInitialSyncWithPredicate( ) throws {
122
- setUp ( withModels: TestModelRegistration ( ) , logLevel: . info)
122
+ let startTime = Temporal . DateTime. now ( )
123
+ setUp (
124
+ withModels: TestModelRegistration ( ) ,
125
+ logLevel: . info,
126
+ dataStoreConfiguration: . custom(
127
+ syncMaxRecords: 100 ,
128
+ syncExpressions: [
129
+ DataStoreSyncExpression (
130
+ modelSchema: Post . schema,
131
+ modelPredicate: { Post . keys. createdAt. ge ( startTime) }
132
+ )
133
+ ]
134
+ )
135
+ )
123
136
try startAmplify ( )
124
- savePostAndWaitForSync ( Post ( title: " xyz 1 " , content: " content " , createdAt: . now( ) ) )
125
- savePostAndWaitForSync ( Post ( title: " xyz 2 " , content: " content " , createdAt: . now( ) ) )
126
- savePostAndWaitForSync ( Post ( title: " xyz 3 " , content: " content " , createdAt: . now( ) ) )
137
+
138
+ let randomTitle = UUID ( ) . uuidString
139
+ savePostAndWaitForSync ( Post ( title: " \( randomTitle) 1 " , content: " content " , createdAt: . now( ) ) )
140
+ savePostAndWaitForSync ( Post ( title: " \( randomTitle) 2 " , content: " content " , createdAt: . now( ) ) )
141
+ savePostAndWaitForSync ( Post ( title: " \( randomTitle) 3 " , content: " content " , createdAt: . now( ) ) )
127
142
clearDataStore ( )
128
143
var snapshots = [ DataStoreQuerySnapshot < Post > ] ( )
129
144
let snapshotWithIsSynced = expectation ( description: " query snapshot with isSynced true " )
130
145
let receivedPostFromObserveQuery = expectation ( description: " received Post " )
131
146
snapshotWithIsSynced. assertForOverFulfill = false
147
+ receivedPostFromObserveQuery. assertForOverFulfill = false
132
148
var snapshotWithIsSyncedFulfilled = false
133
- let predicate = Post . keys. title. beginsWith ( " xyz " )
149
+ let predicate = Post . keys. title. beginsWith ( randomTitle )
134
150
let sink = Amplify . DataStore. observeQuery ( for: Post . self, where: predicate) . sink { completed in
135
151
switch completed {
136
152
case . finished:
@@ -144,15 +160,14 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
144
160
snapshotWithIsSyncedFulfilled = true
145
161
snapshotWithIsSynced. fulfill ( )
146
162
} else if snapshotWithIsSyncedFulfilled {
147
- if querySnapshot. items. count >= 4 && querySnapshot. items. contains ( where: { post in
148
- post. title. contains ( " xyz " )
149
- } ) {
163
+ if querySnapshot. items. count >= 4
164
+ && querySnapshot. items. allSatisfy ( { $0. title. contains ( randomTitle) } ) {
150
165
receivedPostFromObserveQuery. fulfill ( )
151
166
}
152
167
}
153
168
}
154
169
155
- savePostAndWaitForSync ( Post ( title: " xyz 4" , content: " content " , createdAt: . now( ) ) )
170
+ savePostAndWaitForSync ( Post ( title: " \( randomTitle ) 4 " , content: " content " , createdAt: . now( ) ) )
156
171
wait ( for: [ snapshotWithIsSynced, receivedPostFromObserveQuery] , timeout: 200 )
157
172
XCTAssertTrue ( snapshots. count >= 2 )
158
173
XCTAssertFalse ( snapshots [ 0 ] . isSynced)
0 commit comments