@@ -23,17 +23,22 @@ class InitialSyncOperationTests: XCTestCase {
23
23
}
24
24
25
25
// MARK: - GetLastSyncTime
26
-
26
+
27
27
func testFullSyncWhenLastSyncPredicateNilAndCurrentSyncPredicateNonNil( ) {
28
28
let lastSyncTime : Int64 = 123456
29
29
let lastSyncPredicate : String ? = nil
30
30
let currentSyncPredicate = DataStoreConfiguration . custom (
31
31
syncExpressions: [
32
- . syncExpression( MockSynced . schema,
33
- where: { MockSynced . keys. id. eq ( " 123 " ) } ) ] )
32
+ . syncExpression(
33
+ MockSynced . schema,
34
+ where: { MockSynced . keys. id. eq ( " 123 " ) }
35
+ )
36
+ ] ,
37
+ disableSubscriptions: { false }
38
+ )
34
39
let expectedSyncType = SyncType . fullSync
35
40
let expectedLastSync : Int64 ? = nil
36
-
41
+
37
42
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
38
43
let operation = InitialSyncOperation (
39
44
modelSchema: MockSynced . schema,
@@ -60,25 +65,24 @@ class InitialSyncOperationTests: XCTestCase {
60
65
lastSync: lastSyncTime,
61
66
syncPredicate: lastSyncPredicate)
62
67
XCTAssertEqual ( operation. getLastSyncTime ( lastSyncMetadataLastSyncNil) , expectedLastSync)
63
-
68
+
64
69
waitForExpectations ( timeout: 1 )
65
70
sink. cancel ( )
66
71
}
67
-
72
+
68
73
func testFullSyncWhenLastSyncPredicateNonNilAndCurrentSyncPredicateNil( ) {
69
74
let lastSyncTime : Int64 = 123456
70
75
let lastSyncPredicate : String ? = " non nil "
71
- let currentSyncPredicate = DataStoreConfiguration . default
72
76
let expectedSyncType = SyncType . fullSync
73
77
let expectedLastSync : Int64 ? = nil
74
-
78
+
75
79
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
76
80
let operation = InitialSyncOperation (
77
81
modelSchema: MockSynced . schema,
78
82
api: nil ,
79
83
reconciliationQueue: nil ,
80
84
storageAdapter: nil ,
81
- dataStoreConfiguration: currentSyncPredicate ,
85
+ dataStoreConfiguration: . custom ( disableSubscriptions : { false } ) ,
82
86
authModeStrategy: AWSDefaultAuthModeStrategy ( ) )
83
87
let sink = operation
84
88
. publisher
@@ -98,21 +102,26 @@ class InitialSyncOperationTests: XCTestCase {
98
102
lastSync: lastSyncTime,
99
103
syncPredicate: lastSyncPredicate)
100
104
XCTAssertEqual ( operation. getLastSyncTime ( lastSyncMetadataLastSyncNil) , expectedLastSync)
101
-
105
+
102
106
waitForExpectations ( timeout: 1 )
103
107
sink. cancel ( )
104
108
}
105
-
109
+
106
110
func testFullSyncWhenLastSyncPredicateDifferentFromCurrentSyncPredicate( ) {
107
111
let lastSyncTime : Int64 = 123456
108
112
let lastSyncPredicate : String ? = " non nil different from current predicate "
109
113
let currentSyncPredicate = DataStoreConfiguration . custom (
110
114
syncExpressions: [
111
- . syncExpression( MockSynced . schema,
112
- where: { MockSynced . keys. id. eq ( " 123 " ) } ) ] )
115
+ . syncExpression(
116
+ MockSynced . schema,
117
+ where: { MockSynced . keys. id. eq ( " 123 " ) }
118
+ )
119
+ ] ,
120
+ disableSubscriptions: { false }
121
+ )
113
122
let expectedSyncType = SyncType . fullSync
114
123
let expectedLastSync : Int64 ? = nil
115
-
124
+
116
125
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
117
126
let operation = InitialSyncOperation (
118
127
modelSchema: MockSynced . schema,
@@ -139,22 +148,27 @@ class InitialSyncOperationTests: XCTestCase {
139
148
lastSync: lastSyncTime,
140
149
syncPredicate: lastSyncPredicate)
141
150
XCTAssertEqual ( operation. getLastSyncTime ( lastSyncMetadataLastSyncNil) , expectedLastSync)
142
-
151
+
143
152
waitForExpectations ( timeout: 1 )
144
153
sink. cancel ( )
145
154
}
146
-
155
+
147
156
func testDeltaSyncWhenLastSyncPredicateSameAsCurrentSyncPredicate( ) {
148
157
let startDateSeconds = ( Int64 ( Date ( ) . timeIntervalSince1970) - 100 )
149
158
let lastSyncTime : Int64 = startDateSeconds * 1_000
150
159
let lastSyncPredicate : String ? = " { \" field \" : \" id \" , \" operator \" :{ \" type \" : \" equals \" , \" value \" : \" 123 \" }} "
151
160
let currentSyncPredicate = DataStoreConfiguration . custom (
152
161
syncExpressions: [
153
- . syncExpression( MockSynced . schema,
154
- where: { MockSynced . keys. id. eq ( " 123 " ) } ) ] )
162
+ . syncExpression(
163
+ MockSynced . schema,
164
+ where: { MockSynced . keys. id. eq ( " 123 " ) }
165
+ )
166
+ ] ,
167
+ disableSubscriptions: { false }
168
+ )
155
169
let expectedSyncType = SyncType . deltaSync
156
170
let expectedLastSync : Int64 ? = lastSyncTime
157
-
171
+
158
172
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
159
173
let operation = InitialSyncOperation (
160
174
modelSchema: MockSynced . schema,
@@ -181,13 +195,13 @@ class InitialSyncOperationTests: XCTestCase {
181
195
lastSync: lastSyncTime,
182
196
syncPredicate: lastSyncPredicate)
183
197
XCTAssertEqual ( operation. getLastSyncTime ( lastSyncMetadataLastSyncNil) , expectedLastSync)
184
-
198
+
185
199
waitForExpectations ( timeout: 1 )
186
200
sink. cancel ( )
187
201
}
188
-
202
+
189
203
// MARK: - `main()` tests
190
-
204
+
191
205
/// - Given: An InitialSyncOperation
192
206
/// - When:
193
207
/// - I invoke main()
0 commit comments